From 7d2b940ad9def33d4e12e479d02adc034f471f23 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 21 Jan 2021 20:29:18 +0100 Subject: [PATCH] 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