|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "spec_helper" |
| 4 | + |
| 5 | +describe "Homepage with content blocks", type: :system do |
| 6 | + let(:official_url) { "http://test.example.org" } |
| 7 | + let(:organization) { create(:organization, official_url:) } |
| 8 | + let!(:participatory_process) { create(:participatory_process, :promoted, organization:) } |
| 9 | + let!(:assembly) { create(:assembly, :promoted, organization:) } |
| 10 | + let!(:component) { create(:component, manifest_name: :meetings, organization:) } |
| 11 | + let!(:meeting) { create(:meeting, :published, component:) } |
| 12 | + |
| 13 | + before do |
| 14 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :hero, weight: 1) |
| 15 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :sub_hero, weight: 2) |
| 16 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :how_to_participate, weight: 3) |
| 17 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :stats, weight: 4) |
| 18 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :footer_sub_hero, weight: 5) |
| 19 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_processes, weight: 6) |
| 20 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_assemblies, weight: 7) |
| 21 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :upcoming_meetings, weight: 8) |
| 22 | + create(:content_block, organization:, scope_name: :homepage, manifest_name: :html, weight: 9, settings: { html_content: { en: "<div class=\"custom-html\">Custom HTML Content</div>" } }) |
| 23 | + |
| 24 | + switch_to_host(organization.host) |
| 25 | + end |
| 26 | + |
| 27 | + it "renders all content blocks on the homepage" do |
| 28 | + visit decidim.root_path |
| 29 | + |
| 30 | + expect(page).to have_css("section.hero__container") |
| 31 | + expect(page).to have_css("#sub_hero") |
| 32 | + expect(page).to have_css("#how_to_participate") |
| 33 | + expect(page).to have_css("#statistics") |
| 34 | + expect(page).to have_css("#footer_sub_hero") |
| 35 | + expect(page).to have_css("#highlighted-processes") |
| 36 | + expect(page).to have_css("#highlighted-assemblies") |
| 37 | + expect(page).to have_css("[id^=meetings]") |
| 38 | + expect(page).to have_css(".custom-html") |
| 39 | + end |
| 40 | + |
| 41 | + it "renders content blocks in the correct order by weight" do |
| 42 | + visit decidim.root_path |
| 43 | + |
| 44 | + hero_section = page.find("section.hero__container") |
| 45 | + sub_hero_section = page.find("#sub_hero") |
| 46 | + how_to_participate_section = page.find("#how_to_participate") |
| 47 | + stats_section = page.find("#statistics") |
| 48 | + footer_sub_hero_section = page.find("#footer_sub_hero") |
| 49 | + |
| 50 | + hero_position = hero_section.evaluate_script("this.getBoundingClientRect().top") |
| 51 | + sub_hero_position = sub_hero_section.evaluate_script("this.getBoundingClientRect().top") |
| 52 | + how_to_participate_position = how_to_participate_section.evaluate_script("this.getBoundingClientRect().top") |
| 53 | + stats_position = stats_section.evaluate_script("this.getBoundingClientRect().top") |
| 54 | + footer_sub_hero_position = footer_sub_hero_section.evaluate_script("this.getBoundingClientRect().top") |
| 55 | + |
| 56 | + expect(hero_position).to be < sub_hero_position |
| 57 | + expect(sub_hero_position).to be < how_to_participate_position |
| 58 | + expect(how_to_participate_position).to be < stats_position |
| 59 | + expect(stats_position).to be < footer_sub_hero_position |
| 60 | + end |
| 61 | + |
| 62 | + it "renders each content block with its corresponding cell content" do |
| 63 | + visit decidim.root_path |
| 64 | + |
| 65 | + expect(page).to have_css("section.hero__container") |
| 66 | + within "section.hero__container" do |
| 67 | + expect(page).to have_content("Welcome") |
| 68 | + end |
| 69 | + |
| 70 | + expect(page).to have_css("#how_to_participate") |
| 71 | + expect(page).to have_content("How do I take part in a process?") |
| 72 | + |
| 73 | + expect(page).to have_css("#statistics") |
| 74 | + expect(page).to have_content("Statistics") |
| 75 | + |
| 76 | + expect(page).to have_css("#footer_sub_hero") |
| 77 | + |
| 78 | + expect(page).to have_css("#highlighted-processes") |
| 79 | + expect(page).to have_css("#highlighted-assemblies") |
| 80 | + expect(page).to have_css("[id^=meetings]") |
| 81 | + |
| 82 | + expect(page).to have_css(".custom-html") |
| 83 | + expect(page).to have_content("Custom HTML Content") |
| 84 | + end |
| 85 | +end |
0 commit comments