Skip to content

Commit fdbf1ec

Browse files
committed
Add more specs for content blocks
1 parent cc54905 commit fdbf1ec

3 files changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe Decidim::Admin::HomepageContentBlockCell, type: :cell do
6+
controller Decidim::Admin::OrganizationHomepageController
7+
8+
let(:organization) { create(:organization) }
9+
let(:content_block) { create(:content_block, organization:, manifest_name: :hero, scope_name: :homepage) }
10+
11+
subject { cell("decidim/admin/homepage_content_block", content_block).call }
12+
13+
it "renders the content block name" do
14+
expect(subject).to have_content("Hero image")
15+
end
16+
17+
it "renders a link to edit the content block" do
18+
expect(subject).to have_link(href: /edit/)
19+
end
20+
21+
it "renders a link to destroy the content block" do
22+
expect(subject).to have_link(href: /content_blocks/)
23+
end
24+
25+
it "renders the drag handle" do
26+
expect(subject).to have_css("[draggable=\"true\"]")
27+
end
28+
29+
context "when content block is not persisted" do
30+
let(:content_block) { build(:content_block, organization:, manifest_name: :hero, scope_name: :homepage) }
31+
32+
it "does not render edit or destroy links" do
33+
expect(subject).not_to have_link(href: /edit/)
34+
expect(subject).not_to have_link(href: /delete/)
35+
end
36+
end
37+
38+
context "when content block has no settings" do
39+
let(:content_block) do
40+
create(:content_block, organization:, manifest_name: :sub_hero, scope_name: :homepage)
41+
end
42+
43+
it "does not render edit link" do
44+
expect(subject).not_to have_link(href: /edit/)
45+
end
46+
end
47+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
describe "Admin publishes/unpublishes content blocks", type: :system do
6+
let(:organization) { create(:organization) }
7+
let(:user) { create(:user, :admin, :confirmed, organization:) }
8+
9+
before do
10+
switch_to_host(organization.host)
11+
login_as user, scope: :user
12+
end
13+
14+
context "when verifying published blocks appear on homepage" do
15+
let!(:hero_block) { create(:content_block, organization:, manifest_name: :hero, scope_name: :homepage, weight: 1, published_at: Time.current) }
16+
17+
it "shows published content block on the homepage" do
18+
visit decidim.root_path
19+
20+
expect(page).to have_css("[id^=hero]")
21+
end
22+
end
23+
24+
context "when verifying unpublished blocks do not appear on homepage" do
25+
let!(:hero_block) { create(:content_block, organization:, manifest_name: :hero, scope_name: :homepage, weight: nil, published_at: nil) }
26+
27+
it "does not show unpublished content block on the homepage" do
28+
visit decidim.root_path
29+
30+
expect(page).not_to have_css("[id^=hero]")
31+
end
32+
end
33+
end
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)