From c052e907ebfbddde57d2180dda0d054190c5347a Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 08:41:46 +0100 Subject: [PATCH 01/10] Prepare related list component to add on front pages To make it easier to add the component to the front pages forms and avoid introducing redundant classes we add the necessary padding (@include grid-column-gutter) to make it behave like the rest of the form fields. Note that for the sdg management section we set this value to 0. --- app/assets/stylesheets/sdg/related_list_selector.scss | 2 ++ app/assets/stylesheets/sdg_management/relations/edit.scss | 6 ++++++ .../sdg_management/relations/edit_component.html.erb | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/sdg_management/relations/edit.scss diff --git a/app/assets/stylesheets/sdg/related_list_selector.scss b/app/assets/stylesheets/sdg/related_list_selector.scss index a60cd57cf..75fb5c433 100644 --- a/app/assets/stylesheets/sdg/related_list_selector.scss +++ b/app/assets/stylesheets/sdg/related_list_selector.scss @@ -1,4 +1,6 @@ .sdg-related-list-selector { + @include grid-column-gutter; + clear: both; .amsify-suggestags-area .amsify-select-tag { color: $white; diff --git a/app/assets/stylesheets/sdg_management/relations/edit.scss b/app/assets/stylesheets/sdg_management/relations/edit.scss new file mode 100644 index 000000000..a719b4336 --- /dev/null +++ b/app/assets/stylesheets/sdg_management/relations/edit.scss @@ -0,0 +1,6 @@ +.sdg-relations-edit { + + .sdg-related-list-selector { + padding: 0; + } +} diff --git a/app/components/sdg_management/relations/edit_component.html.erb b/app/components/sdg_management/relations/edit_component.html.erb index 3cb8350f4..de0b351d1 100644 --- a/app/components/sdg_management/relations/edit_component.html.erb +++ b/app/components/sdg_management/relations/edit_component.html.erb @@ -1,6 +1,6 @@ <%= header %> -<%= form_for record, url: update_path do |f| %> +<%= form_for record, url: update_path, html: { class: "sdg-relations-edit" } do |f| %> <%= render SDG::RelatedListSelectorComponent.new(f) %> <%= f.submit %> From 8a91493fe439d380aea31e7d88045c83bfc6eb98 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 09:50:54 +0100 Subject: [PATCH 02/10] Extract repeating code to a method --- spec/support/common_actions.rb | 10 +++++++ spec/system/sdg_management/relations_spec.rb | 29 ++++++-------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index ab84b1500..9c9f267cc 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -43,4 +43,14 @@ module CommonActions allow_any_instance_of(Officing::BaseController). to receive(:current_booth).and_return(booth) end + + def click_sdg_goal(code) + find("li[data-code='#{code}']").click + end + + def remove_sdg_goal_or_target_tag(code) + within "span[data-val='#{code}']" do + click_button "Remove" + end + end end diff --git a/spec/system/sdg_management/relations_spec.rb b/spec/system/sdg_management/relations_spec.rb index 8f477db2b..83791a9a6 100644 --- a/spec/system/sdg_management/relations_spec.rb +++ b/spec/system/sdg_management/relations_spec.rb @@ -218,13 +218,8 @@ describe "SDG Relations", :js do visit sdg_management_edit_legislation_process_path(process) - within "span[data-val='2']" do - click_button "Remove" - end - - within "span[data-val='3.3']" do - click_button "Remove" - end + remove_sdg_goal_or_target_tag(2) + remove_sdg_goal_or_target_tag(3.3) click_button "Update Process" @@ -293,7 +288,7 @@ describe "SDG Relations", :js do process = create(:legislation_process, title: "SDG process") visit sdg_management_edit_legislation_process_path(process) - find("li[data-code='1']").click + click_sdg_goal(1) click_button "Update Process" click_link "Marked as reviewed" @@ -307,7 +302,7 @@ describe "SDG Relations", :js do process.sdg_goals = [SDG::Goal[1], SDG::Goal[2]] visit sdg_management_edit_legislation_process_path(process) - find("li[data-code='1']").click + click_sdg_goal(1) click_button "Update Process" click_link "Marked as reviewed" @@ -322,7 +317,7 @@ describe "SDG Relations", :js do process = create(:legislation_process, title: "SDG process") visit sdg_management_edit_legislation_process_path(process) - find("li[data-code='1']").click + click_sdg_goal(1) expect(find("li[data-code='1']")["aria-checked"]).to eq "true" end @@ -333,15 +328,11 @@ describe "SDG Relations", :js do process.sdg_targets = [SDG::Target[1.1]] visit sdg_management_edit_legislation_process_path(process) - within "span[data-val='1']" do - click_button "Remove" - end + remove_sdg_goal_or_target_tag(1) expect(find("li[data-code='1']")["aria-checked"]).to eq "true" - within "span[data-val='1.1']" do - click_button "Remove" - end + remove_sdg_goal_or_target_tag(1.1) expect(find("li[data-code='1']")["aria-checked"]).to eq "false" end @@ -352,7 +343,7 @@ describe "SDG Relations", :js do process = create(:legislation_process, title: "SDG process") visit sdg_management_edit_legislation_process_path(process) - find("li[data-code='1']").click + click_sdg_goal(1) within(".help-section") { expect(page).to have_content "No Poverty" } end @@ -365,9 +356,7 @@ describe "SDG Relations", :js do within(".help-section") { expect(page).to have_content "No Poverty" } - within "span[data-val='1']" do - click_button "Remove" - end + remove_sdg_goal_or_target_tag(1) expect(page).not_to have_content "No Poverty" end From 189c299a6e7328c2f7e0b9c13bb697c5a985b8e5 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 09:09:30 +0100 Subject: [PATCH 03/10] Do not render component when the feature is disabled --- .../sdg/related_list_selector_component.rb | 4 ++++ .../related_list_selector_component_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/components/sdg/related_list_selector_component.rb b/app/components/sdg/related_list_selector_component.rb index 42584fdad..b183765de 100644 --- a/app/components/sdg/related_list_selector_component.rb +++ b/app/components/sdg/related_list_selector_component.rb @@ -28,6 +28,10 @@ class SDG::RelatedListSelectorComponent < ApplicationComponent } end + def render? + SDG::ProcessEnabled.new(f.object).enabled? + end + private def goals diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index ca0db193e..7326400e0 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -5,6 +5,27 @@ describe SDG::RelatedListSelectorComponent, type: :component do let(:form) { ConsulFormBuilder.new(:debate, debate, ActionView::Base.new, {}) } let(:component) { SDG::RelatedListSelectorComponent.new(form) } + before do + Setting["feature.sdg"] = true + Setting["sdg.process.debates"] = true + end + + it "does not render when the feature is disabled" do + Setting["feature.sdg"] = false + + render_inline component + + expect(page).not_to have_css ".sdg-related-list-selector" + end + + it "does not render when the SDG process feature is disabled" do + Setting["sdg.process.debates"] = false + + render_inline component + + expect(page).not_to have_css ".sdg-related-list-selector" + end + it "renders sdg_related_list field" do render_inline component From e6bfeef58deacb661a07bea19accf6b3aea94e97 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 16:40:23 +0100 Subject: [PATCH 04/10] Add SDG::RelatedListSelectorComponent to Debates --- app/controllers/debates_controller.rb | 2 +- app/views/debates/_form.html.erb | 3 +++ spec/system/debates_spec.rb | 37 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index a4898e5c4..89ef3d725 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -55,7 +55,7 @@ class DebatesController < ApplicationController private def debate_params - attributes = [:tag_list, :terms_of_service] + attributes = [:tag_list, :terms_of_service, :sdg_related_list] params.require(:debate).permit(attributes, translation_params(Debate)) end diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 155bb7da5..ac9a0f84a 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -32,6 +32,9 @@ data: { js_url: suggest_tags_path }, class: "tag-autocomplete" %> + + <%= render SDG::RelatedListSelectorComponent.new(f) %> +
<% if @debate.new_record? %> <%= f.check_box :terms_of_service, diff --git a/spec/system/debates_spec.rb b/spec/system/debates_spec.rb index 2f97dffa3..9844c926e 100644 --- a/spec/system/debates_spec.rb +++ b/spec/system/debates_spec.rb @@ -1115,4 +1115,41 @@ describe "Debates" do expect(page).not_to have_content("Featured") end end + + describe "SDG related list" do + let(:user) { create(:user) } + + before do + Setting["feature.sdg"] = true + Setting["sdg.process.debates"] = true + end + + scenario "create debate with sdg related list", :js do + login_as(user) + visit new_debate_path + fill_in "Debate title", with: "A title for a debate related with SDG related content" + fill_in_ckeditor "Initial debate text", with: "This is very important because..." + click_sdg_goal(1) + check "debate_terms_of_service" + + click_button "Start a debate" + + within(".sdg-goal-tag-list") { expect(page).to have_link "1. No Poverty" } + end + + scenario "edit debate with sdg related list", :js do + debate = create(:debate, author: user) + debate.sdg_goals = [SDG::Goal[1], SDG::Goal[2]] + login_as(user) + visit edit_debate_path(debate) + + remove_sdg_goal_or_target_tag(1) + click_button "Save changes" + + within(".sdg-goal-tag-list") do + expect(page).not_to have_link "1. No Poverty" + expect(page).to have_link "2. Zero Hunger" + end + end + end end From 95c1f36bddf4b093c9edbcb7a7859a13d39df0ba Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 17:17:16 +0100 Subject: [PATCH 05/10] Add SDG::RelatedListSelectorComponent to Proposals Allow to relate SDG and Targets to Proposals --- app/controllers/proposals_controller.rb | 4 +-- app/views/proposals/_form.html.erb | 2 ++ spec/system/proposals_spec.rb | 38 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 6f2d7e10b..544a939cc 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -98,8 +98,8 @@ class ProposalsController < ApplicationController private def proposal_params - attributes = [:video_url, :responsible_name, :tag_list, - :terms_of_service, :geozone_id, :skip_map, + attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service, + :geozone_id, :skip_map, :sdg_related_list, image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index eba35f60d..60cc80f84 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -93,6 +93,8 @@
<% end %> + <%= render SDG::RelatedListSelectorComponent.new(f) %> +
<% if @proposal.new_record? %> <%= f.check_box :terms_of_service, diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index b42cd0a41..4376b6d92 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -1907,4 +1907,42 @@ describe "Successful proposals" do expect(page).to have_content "Proposal created successfully." end end + + describe "SDG related list" do + let(:user) { create(:user) } + + before do + Setting["feature.sdg"] = true + Setting["sdg.process.proposals"] = true + end + + scenario "create proposal with sdg related list", :js do + login_as(user) + visit new_proposal_path + fill_in "Proposal title", with: "A title for a proposal related with SDG related content" + fill_in "Proposal summary", with: "In summary, what we want is..." + fill_in "proposal_responsible_name", with: "Isabel Garcia" + click_sdg_goal(1) + check "proposal_terms_of_service" + + click_button "Create proposal" + + within(".sdg-goal-tag-list") { expect(page).to have_link "1. No Poverty" } + end + + scenario "edit proposal with sdg related list", :js do + proposal = create(:proposal, author: user) + proposal.sdg_goals = [SDG::Goal[1], SDG::Goal[2]] + login_as(user) + visit edit_proposal_path(proposal) + + remove_sdg_goal_or_target_tag(1) + click_button "Save changes" + + within(".sdg-goal-tag-list") do + expect(page).not_to have_link "1. No Poverty" + expect(page).to have_link "2. Zero Hunger" + end + end + end end From 6d3782b4a095f60174f02441e0dafdbc2cbea8e8 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 17:17:48 +0100 Subject: [PATCH 06/10] Add SDG::RelatedListSelectorComponent to Budget Investments Allow to relate SDG and Targets to Budget Investments --- .../budgets/investments_controller.rb | 4 +- app/views/budgets/investments/_form.html.erb | 2 + spec/system/budgets/investments_spec.rb | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index f3e41f3ae..a876af8f6 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -132,8 +132,8 @@ module Budgets end def investment_params - attributes = [:heading_id, :tag_list, - :organization_name, :location, :terms_of_service, :skip_map, + attributes = [:heading_id, :tag_list, :organization_name, :location, + :terms_of_service, :skip_map, :sdg_related_list, image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], map_location_attributes: [:latitude, :longitude, :zoom]] diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 3eff59f72..2156b9d60 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -86,6 +86,8 @@ data: { js_url: suggest_tags_path } %>
+ <%= render SDG::RelatedListSelectorComponent.new(f) %> + <% unless current_user.manager? %>
diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 8382b7f05..10a6f7a4b 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -1933,4 +1933,41 @@ describe "Budget Investments" do end end end + + describe "SDG related list" do + before do + Setting["feature.sdg"] = true + Setting["sdg.process.budgets"] = true + budget.update!(phase: "accepting") + end + + scenario "create budget investment with sdg related list", :js do + login_as(author) + visit new_budget_investment_path(budget) + select heading.name, from: "Heading" + fill_in "Title", with: "A title for a budget investment related with SDG related content" + fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" + click_sdg_goal(1) + check "budget_investment_terms_of_service" + + click_button "Create Investment" + + within(".sdg-goal-tag-list") { expect(page).to have_link "1. No Poverty" } + end + + scenario "edit budget investment with sdg related list", :js do + investment = create(:budget_investment, heading: heading, author: author) + investment.sdg_goals = [SDG::Goal[1], SDG::Goal[2]] + login_as(author) + visit edit_budget_investment_path(budget, investment) + + remove_sdg_goal_or_target_tag(1) + click_button "Update Investment" + + within(".sdg-goal-tag-list") do + expect(page).not_to have_link "1. No Poverty" + expect(page).to have_link "2. Zero Hunger" + end + end + end end From 6e0158db172189a8987116bf24209b6121d83348 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 11:09:48 +0100 Subject: [PATCH 07/10] Display Goals and Targets relateds on Admin Poll index --- app/views/admin/poll/polls/_poll.html.erb | 14 +++++--------- app/views/admin/poll/polls/index.html.erb | 2 ++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/views/admin/poll/polls/_poll.html.erb b/app/views/admin/poll/polls/_poll.html.erb index e367d7708..eb77fdd4f 100644 --- a/app/views/admin/poll/polls/_poll.html.erb +++ b/app/views/admin/poll/polls/_poll.html.erb @@ -1,13 +1,9 @@ - - <%= poll.name %> - - - <%= l poll.starts_at.to_date %> - - - <%= l poll.ends_at.to_date %> - + <%= poll.name %> + <%= l poll.starts_at.to_date %> + <%= l poll.ends_at.to_date %> + <%= poll.sdg_goal_list %> + <%= poll.sdg_target_list %> <%= render Admin::TableActionsComponent.new(poll, destroy_confirmation: t("admin.polls.destroy.alert") diff --git a/app/views/admin/poll/polls/index.html.erb b/app/views/admin/poll/polls/index.html.erb index b305a7b73..2d55a37f9 100644 --- a/app/views/admin/poll/polls/index.html.erb +++ b/app/views/admin/poll/polls/index.html.erb @@ -14,6 +14,8 @@ <%= t("admin.polls.index.name") %> <%= t("admin.polls.index.start_date") %> <%= t("admin.polls.index.closing_date") %> + <%= SDG::Goal.model_name.human(count: :other).upcase_first %> + <%= SDG::Target.model_name.human(count: :other).upcase_first %> <%= t("admin.actions.actions") %> From 920631c5b3e77a8630b59180a1ae3b9710a7f3cc Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 18:17:47 +0100 Subject: [PATCH 08/10] Add SDG::RelatedListSelectorComponent to Polls Allow to relate SDG and Targets to Polls --- .../admin/poll/polls_controller.rb | 2 +- app/views/admin/poll/polls/_form.html.erb | 4 ++ spec/system/admin/poll/polls_spec.rb | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 75fae91ff..8bf2b75f7 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -76,7 +76,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, + attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, :sdg_related_list, geozone_ids: [], image_attributes: image_attributes] params.require(:poll).permit(*attributes, *report_attributes, translation_params(Poll)) diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 4011ab4ec..cb542612d 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -55,6 +55,10 @@
+
+ <%= render SDG::RelatedListSelectorComponent.new(f) %> +
+
diff --git a/spec/system/admin/poll/polls_spec.rb b/spec/system/admin/poll/polls_spec.rb index c60ade14b..5d5baf257 100644 --- a/spec/system/admin/poll/polls_spec.rb +++ b/spec/system/admin/poll/polls_spec.rb @@ -521,4 +521,42 @@ describe "Admin polls", :admin do end end end + + context "SDG related list" do + before do + Setting["feature.sdg"] = true + Setting["sdg.process.polls"] = true + end + + scenario "create poll with sdg related list", :js do + visit new_admin_poll_path + fill_in "Name", with: "Upcoming poll with SDG related content" + fill_in "Start Date", with: 1.week.from_now + fill_in "Closing Date", with: 2.weeks.from_now + fill_in "Summary", with: "Upcoming poll's summary. This poll..." + fill_in "Description", with: "Upcomming poll's description. This poll..." + + click_sdg_goal(17) + click_button "Create poll" + visit admin_polls_path + + within("tr", text: "Upcoming poll with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + + scenario "edit poll with sdg related list", :js do + poll = create(:poll, name: "Upcoming poll with SDG related content") + poll.sdg_goals = [SDG::Goal[1], SDG::Goal[17]] + visit edit_admin_poll_path(poll) + + remove_sdg_goal_or_target_tag(1) + click_button "Update poll" + visit admin_polls_path + + within("tr", text: "Upcoming poll with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + end end From 1cbf9a3404dc6885fd411b49982eb76f79ab639b Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 11:16:23 +0100 Subject: [PATCH 09/10] Display Goals and Targets relateds on Admin Legislation Process index --- app/views/admin/legislation/processes/index.html.erb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb index 159f553c7..c32ce9d6d 100644 --- a/app/views/admin/legislation/processes/index.html.erb +++ b/app/views/admin/legislation/processes/index.html.erb @@ -20,6 +20,8 @@ <%= t("admin.legislation.processes.process.start_date") %> <%= t("admin.legislation.processes.process.end_date") %> <%= t("admin.legislation.processes.process.comments") %> + <%= SDG::Goal.model_name.human(count: :other).upcase_first %> + <%= SDG::Target.model_name.human(count: :other).upcase_first %> <%= t("admin.actions.actions") %> @@ -32,6 +34,8 @@ <%= I18n.l process.start_date %> <%= I18n.l process.end_date %> <%= process.total_comments %> + <%= process.sdg_goal_list %> + <%= process.sdg_target_list %> <%= render Admin::TableActionsComponent.new(process) %> <% end %> From 7d2b940ad9def33d4e12e479d02adc034f471f23 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 20:29:18 +0100 Subject: [PATCH 10/10] Add SDG::RelatedListSelectorComponent to Legislation Process Allow to relate SDG and Targets to Legislation Process --- .../admin/legislation/processes_controller.rb | 1 + .../legislation/processes/_form.html.erb | 4 ++ .../admin/legislation/processes_spec.rb | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 6f9f5c1c2..46144207d 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -69,6 +69,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :custom_list, :background_color, :font_color, + :sdg_related_list, translation_params(::Legislation::Process), documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], image_attributes: image_attributes diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 267414ee9..b5ad0b23a 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -190,6 +190,10 @@ <% end %>
+
+ <%= render SDG::RelatedListSelectorComponent.new(f) %> +
+
<%= f.submit(class: "button success expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %> diff --git a/spec/system/admin/legislation/processes_spec.rb b/spec/system/admin/legislation/processes_spec.rb index 5e69b60b0..2c88b0140 100644 --- a/spec/system/admin/legislation/processes_spec.rb +++ b/spec/system/admin/legislation/processes_spec.rb @@ -330,4 +330,42 @@ describe "Admin collaborative legislation", :admin do expect(page).not_to have_link "Remove language" end end + + context "SDG related list" do + before do + Setting["feature.sdg"] = true + Setting["sdg.process.legislation"] = true + end + + scenario "create Collaborative Legislation with sdg related list", :js do + visit new_admin_legislation_process_path + fill_in "Process Title", with: "Legislation process with SDG related content" + within_fieldset "Process" do + fill_in "Start", with: 2.days.ago + fill_in "End", with: 1.day.from_now + end + + click_sdg_goal(17) + click_button "Create process" + visit admin_legislation_processes_path + + within("tr", text: "Legislation process with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + + scenario "edit Collaborative Legislation with sdg related list", :js do + process = create(:legislation_process, title: "Legislation process with SDG related content") + process.sdg_goals = [SDG::Goal[1], SDG::Goal[17]] + visit edit_admin_legislation_process_path(process) + + remove_sdg_goal_or_target_tag(1) + click_button "Save changes" + visit admin_legislation_processes_path + + within("tr", text: "Legislation process with SDG related content") do + expect(page).to have_css "td", exact_text: "17" + end + end + end end