Skip to content

Commit

Permalink
Improve settings options for Related Spaces content block. (decidim#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeig authored Oct 21, 2024
1 parent 606a187 commit 8fc6703
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% form.fields_for :settings, form.object.settings do |settings_fields| %>
<%= settings_fields.select :max_results, [6, 9, 12], prompt: "", label: %>
<%= settings_fields.number_field :max_results, label: %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def edit_content_block_path(resource, content_block)
visit edit_content_block_path(resource, related_assemblies_content_block)

expect(related_assemblies_content_block.settings["max_results"]).to eq(6)
select 12, from: :content_block_settings_max_results
fill_in :content_block_settings_max_results, with: "12"
click_on "Update"

expect(page).to have_content("Related assemblies")
Expand Down
23 changes: 22 additions & 1 deletion decidim-assemblies/spec/system/homepage_content_blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
let!(:promoted_assembly) { create(:assembly, :promoted, organization:) }
let!(:unpromoted_assembly) { create(:assembly, organization:) }
let!(:promoted_external_assembly) { create(:assembly, :promoted) }
let!(:highlighted_assemblies_content_block) { create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_assemblies) }

include_context "when admin administrating an assembly"

before do
create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_assemblies)
switch_to_host(organization.host)
login_as user, scope: :user
end

it "includes active assemblies to the homepage" do
Expand All @@ -22,4 +25,22 @@
expect(page).not_to have_i18n_content(promoted_external_assembly.title)
end
end

it "updates the settings of the content block" do
visit decidim_admin.edit_organization_homepage_content_block_path(highlighted_assemblies_content_block)

expect(find("input[type='number'][name='content_block[settings][max_results]").value).to eq("6")

fill_in "content_block[settings][max_results]", with: "1"
click_on "Update"

expect(page).to have_content("Highlighted assemblies")
expect(highlighted_assemblies_content_block.reload.settings["max_results"]).to eq(1)

visit decidim.root_path

within "#highlighted-assemblies" do
expect(page).to have_css("a.card__grid", count: 1)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% form.fields_for :settings, form.object.settings do |settings_fields| %>
<%= settings_fields.select :max_results, [6, 9, 12], prompt: "", label: %>
<%= settings_fields.number_field :max_results, label: %>
<% end %>
25 changes: 24 additions & 1 deletion decidim-conferences/spec/system/homepage_content_blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
let!(:promoted_conference) { create(:conference, :promoted, organization:) }
let!(:unpromoted_conference) { create(:conference, organization:) }
let!(:promoted_external_conference) { create(:conference, :promoted) }
let!(:highlighted_conferences_content_block) { create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_conferences) }

include_context "when admin administrating a conference"

before do
create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_conferences)
switch_to_host(organization.host)
login_as user, scope: :user
end

it "includes active conferences to the homepage" do
Expand All @@ -21,6 +24,26 @@
expect(page).to have_i18n_content(promoted_conference.title)
expect(page).to have_i18n_content(unpromoted_conference.title)
expect(page).not_to have_i18n_content(promoted_external_conference.title)

expect(page).to have_css("a.card__grid", count: 3)
end
end

it "updates the number of highlighted conferences with a number input field" do
visit decidim_admin.edit_organization_homepage_content_block_path(highlighted_conferences_content_block)

expect(find("input[type='number'][name='content_block[settings][max_results]']").value).to eq("6")

fill_in "content_block[settings][max_results]", with: "1"
click_on "Update"

expect(page).to have_content("Highlighted conferences")
expect(highlighted_conferences_content_block.reload.settings["max_results"]).to eq(1)

visit decidim.root_path

within "#highlighted-conferences" do
expect(page).to have_css("a.card__grid", count: 1)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% form.fields_for :settings, form.object.settings do |settings_fields| %>
<%= settings_fields.select :max_results, [4, 8, 12], prompt: "", label: max_results_label %>
<%= settings_fields.number_field :max_results, label: max_results_label %>
<%= settings_fields.select :order, order_select, prompt: "", label: order_label %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% form.fields_for :settings, form.object.settings do |settings_fields| %>
<%= settings_fields.select :max_results, [6, 9, 12], prompt: "", label: %>
<%= settings_fields.number_field :max_results, label: %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
end
let!(:unpromoted_process) { create(:participatory_process, organization:) }
let!(:promoted_external_process) { create(:participatory_process, :promoted) }
let!(:highlighted_participatory_processes_content_block) { create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_processes) }
let!(:user) { create(:user, :admin, :confirmed, organization:) }

before do
create(:content_block, organization:, scope_name: :homepage, manifest_name: :highlighted_processes)
switch_to_host(organization.host)
login_as user, scope: :user
end

it "includes active processes to the homepage" do
Expand All @@ -30,6 +32,8 @@
expect(page).to have_i18n_content(unpromoted_process.title)
expect(page).not_to have_i18n_content(promoted_external_process.title)
expect(page).not_to have_i18n_content(promoted_past_process.title)

expect(page).to have_css("a.card__grid", count: 2)
end
end

Expand All @@ -50,4 +54,22 @@
end
end
end

it "updates the number of highlighted participatory processes with a number input field" do
visit decidim_admin.edit_organization_homepage_content_block_path(highlighted_participatory_processes_content_block)

expect(find("input[type='number'][name='content_block[settings][max_results]']").value).to eq("6")

fill_in "content_block[settings][max_results]", with: "1"
click_on "Update"

expect(page).to have_content("Highlighted processes")
expect(highlighted_participatory_processes_content_block.reload.settings["max_results"]).to eq(1)

visit decidim.root_path

within "#highlighted-processes" do
expect(page).to have_css("a.card__grid", count: 1)
end
end
end

0 comments on commit 8fc6703

Please sign in to comment.