diff --git a/decidim-accountability/spec/shared/manage_results_examples.rb b/decidim-accountability/spec/shared/manage_results_examples.rb index dec97c1a56a7..230ac46299cc 100644 --- a/decidim-accountability/spec/shared/manage_results_examples.rb +++ b/decidim-accountability/spec/shared/manage_results_examples.rb @@ -31,6 +31,7 @@ context "when having existing proposals" do let!(:proposal_component) { create(:proposal_component, participatory_space:) } let!(:proposals) { create_list(:proposal, 5, component: proposal_component) } + let(:attributes) { attributes_for(:result, component: current_component) } it "updates a result" do within "tr", text: translated(result.title) do @@ -38,13 +39,7 @@ end within ".edit_result" do - fill_in_i18n( - :result_title, - "#result-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:result_title, "#result-title-tabs", **attributes[:title].except("machine_translations")) tom_select("#proposals_list", option_id: proposals.first(2).map(&:id)) @@ -54,28 +49,20 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated result") + expect(page).to have_content(translated(attributes[:title])) end it "creates a new result", :slow do click_on "New result", match: :first within ".new_result" do - fill_in_i18n( - :result_title, - "#result-title-tabs", - en: "My result", - es: "Mi result", - ca: "El meu result" - ) - fill_in_i18n_editor( - :result_description, - "#result-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:result_title, "#result-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:result_description, "#result-description-tabs", **attributes[:description].except("machine_translations")) tom_select("#proposals_list", option_id: proposals.first(2).map(&:id)) @@ -88,8 +75,12 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My result") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created result") + expect(page).to have_content(attributes[:title]["en"]) end end diff --git a/decidim-accountability/spec/shared/manage_statuses_examples.rb b/decidim-accountability/spec/shared/manage_statuses_examples.rb index 69af2bf4c8be..9eda4605063f 100644 --- a/decidim-accountability/spec/shared/manage_statuses_examples.rb +++ b/decidim-accountability/spec/shared/manage_statuses_examples.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true RSpec.shared_examples "manage statuses" do + let(:attributes) { attributes_for(:status) } + it "updates a status" do within "tr", text: status.key do click_on "Edit" @@ -10,9 +12,7 @@ fill_in_i18n( :status_name, "#status-name-tabs", - en: "My new name", - es: "Mi nuevo nombre", - ca: "El meu nou nom" + **attributes[:name].except("machine_translations") ) find("*[type=submit]").click @@ -21,8 +21,11 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My new name") + expect(page).to have_content(translated(attributes[:name])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:name])} status") end it "creates a new status" do @@ -31,21 +34,8 @@ within ".new_status" do fill_in :status_key, with: "status_key_1" - fill_in_i18n( - :status_name, - "#status-name-tabs", - en: "A longer name", - es: "Nombre más larga", - ca: "Nom més llarga" - ) - - fill_in_i18n( - :status_description, - "#status-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:status_name, "#status-name-tabs", **attributes[:name].except("machine_translations")) + fill_in_i18n(:status_description, "#status-description-tabs", **attributes[:description].except("machine_translations")) fill_in :status_progress, with: 75 @@ -56,8 +46,11 @@ within "table" do expect(page).to have_content("status_key_1") - expect(page).to have_content("A longer name") + expect(page).to have_content(translated(attributes[:name])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:name])} status") end describe "deleting a result" do diff --git a/decidim-accountability/spec/shared/manage_timeline_examples.rb b/decidim-accountability/spec/shared/manage_timeline_examples.rb new file mode 100644 index 000000000000..6544bf64800d --- /dev/null +++ b/decidim-accountability/spec/shared/manage_timeline_examples.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +RSpec.shared_examples "manage timeline" do + let(:attributes) { attributes_for(:timeline_entry, result:) } + + it "updates a timeline entry", versioning: true do + visit current_path + click_on "Edit", match: :first + + within ".edit_timeline_entry" do + fill_in :timeline_entry_entry_date_date, with: Date.current.strftime("%d/%m/%Y") + fill_in_i18n(:timeline_entry_title, "#timeline_entry-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:timeline_entry_description, "#timeline_entry-description-tabs", **attributes[:description].except("machine_translations")) + + find("*[type=submit]").click + end + + expect(page).to have_admin_callout("successfully") + + within "table" do + expect(page).to have_content(translated(attributes[:title])) + end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} timeline entry") + end + + it "creates a timeline entry", versioning: true do + click_on "New timeline entry", match: :first + + within ".new_timeline_entry" do + fill_in :timeline_entry_entry_date_date, with: Date.current.strftime("%d/%m/%Y") + fill_in_i18n(:timeline_entry_title, "#timeline_entry-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:timeline_entry_description, "#timeline_entry-description-tabs", **attributes[:description].except("machine_translations")) + + find("*[type=submit]").click + end + + expect(page).to have_admin_callout("successfully") + + within "table" do + expect(page).to have_content(translated(attributes[:title])) + end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} timeline entry") + end +end diff --git a/decidim-accountability/spec/system/admin/admin_manages_accountability_spec.rb b/decidim-accountability/spec/system/admin/admin_manages_accountability_spec.rb index 347e554c4ed4..1d3a820e598d 100644 --- a/decidim-accountability/spec/system/admin/admin_manages_accountability_spec.rb +++ b/decidim-accountability/spec/system/admin/admin_manages_accountability_spec.rb @@ -35,4 +35,17 @@ it_behaves_like "manage statuses" end + + describe "timeline" do + before do + visit_component_admin + within "tr", text: translated(result.title) do + click_on "Project evolution" + end + end + + let!(:timeline_entry) { create(:timeline_entry, result:) } + + it_behaves_like "manage timeline" + end end diff --git a/decidim-admin/app/packs/src/decidim/admin/css_preview.js b/decidim-admin/app/packs/src/decidim/admin/css_preview.js index 350c8369aea8..fbf6cebfef2a 100644 --- a/decidim-admin/app/packs/src/decidim/admin/css_preview.js +++ b/decidim-admin/app/packs/src/decidim/admin/css_preview.js @@ -30,7 +30,9 @@ window.addEventListener("DOMContentLoaded", () => { updateRules.forEach((rule) => { const [target, property, value] = rule.split(":"); - document.querySelector(target).style[property.trim()] = value.trim(); + if (target !== "") { + document.querySelector(target).style[property.trim()] = value.trim(); + } }); }) }) diff --git a/decidim-assemblies/spec/shared/manage_assemblies_examples.rb b/decidim-assemblies/spec/shared/manage_assemblies_examples.rb index 441dc635655d..d0ce27112b77 100644 --- a/decidim-assemblies/spec/shared/manage_assemblies_examples.rb +++ b/decidim-assemblies/spec/shared/manage_assemblies_examples.rb @@ -6,24 +6,33 @@ let(:image3_path) { Decidim::Dev.asset(image3_filename) } let(:assembly_parent_id_options) { page.find_by_id("assembly_parent_id").find_all("option").map(&:value) } + let(:attributes) { attributes_for(:assembly, :with_content_blocks, organization:, blocks_manifests: [:announcement]) } before do click_on "Configure" end it "updates an assembly" do - fill_in_i18n( - :assembly_title, - "#assembly-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:assembly_title, "#assembly-title-tabs", **attributes[:title].except("machine_translations")) dynamically_attach_file(:assembly_banner_image, image3_path, remove_before: true) within ".edit_assembly" do expect(assembly_parent_id_options).not_to include(assembly.id) + fill_in_i18n(:assembly_subtitle, "#assembly-subtitle-tabs", **attributes[:subtitle].except("machine_translations")) + fill_in_i18n_editor(:assembly_short_description, "#assembly-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:assembly_description, "#assembly-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:assembly_purpose_of_action, "#assembly-purpose_of_action-tabs", **attributes[:purpose_of_action].except("machine_translations")) + fill_in_i18n_editor(:assembly_composition, "#assembly-composition-tabs", **attributes[:composition].except("machine_translations")) + fill_in_i18n_editor(:assembly_internal_organisation, "#assembly-internal_organisation-tabs", **attributes[:internal_organisation].except("machine_translations")) + fill_in_i18n_editor(:assembly_announcement, "#assembly-announcement-tabs", **attributes[:announcement].except("machine_translations")) + fill_in_i18n_editor(:assembly_closing_date_reason, "#assembly-closing_date_reason-tabs", **attributes[:closing_date_reason].except("machine_translations")) + + fill_in_i18n(:assembly_participatory_scope, "#assembly-participatory_scope-tabs", **attributes[:participatory_scope].except("machine_translations")) + fill_in_i18n(:assembly_participatory_structure, "#assembly-participatory_structure-tabs", **attributes[:participatory_structure].except("machine_translations")) + fill_in_i18n(:assembly_meta_scope, "#assembly-meta_scope-tabs", **attributes[:meta_scope].except("machine_translations")) + fill_in_i18n(:assembly_local_area, "#assembly-local_area-tabs", **attributes[:local_area].except("machine_translations")) + fill_in_i18n(:assembly_target, "#assembly-target-tabs", **attributes[:target].except("machine_translations")) fill_in :assembly_creation_date_date, with: nil, fill_options: { clear: :backspace } fill_in :assembly_included_at_date, with: nil, fill_options: { clear: :backspace } @@ -39,13 +48,16 @@ expect(page).to have_admin_callout("successfully") within "[data-content]" do - expect(page).to have_css("input[value='My new title']") + expect(page).to have_css("input[value='#{translated(attributes[:title])}']") expect(page).to have_css("img[src*='#{image3_filename}']") expect(page).to have_field(:assembly_creation_date_date, with: Date.yesterday.strftime("%d/%m/%Y").to_s) expect(page).to have_field(:assembly_included_at_date, with: Date.current.strftime("%d/%m/%Y").to_s) expect(page).to have_field(:assembly_duration_date, with: Date.tomorrow.strftime("%d/%m/%Y").to_s) expect(page).to have_field(:assembly_closing_date_date, with: Date.tomorrow.strftime("%d/%m/%Y").to_s) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} assembly") end end diff --git a/decidim-assemblies/spec/shared/manage_assembly_admins_examples.rb b/decidim-assemblies/spec/shared/manage_assembly_admins_examples.rb index d40fec0c7c91..b13dfa1dabe5 100644 --- a/decidim-assemblies/spec/shared/manage_assembly_admins_examples.rb +++ b/decidim-assemblies/spec/shared/manage_assembly_admins_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage assembly admins examples" do let(:other_user) { create(:user, organization:, email: "my_email@example.org") } + let(:attributes) { attributes_for(:user, organization:) } let!(:assembly_admin) do create(:assembly_admin, @@ -25,12 +26,12 @@ end end - it "creates a new assembly admin" do + it "creates a new assembly admin", versioning: true do click_on "New assembly admin" within ".new_assembly_user_role" do fill_in :assembly_user_role_email, with: other_user.email - fill_in :assembly_user_role_name, with: "John Doe" + fill_in :assembly_user_role_name, with: attributes[:name] select "Administrator", from: :assembly_user_role_role find("*[type=submit]").click @@ -41,6 +42,9 @@ within "#assembly_admins table" do expect(page).to have_content(other_user.email) end + + visit decidim_admin.root_path + expect(page).to have_content("invited #{other_user.name} to the #{translated(assembly.title)} assembly") end describe "when managing different users" do @@ -49,7 +53,7 @@ visit current_path end - it "updates an assembly admin" do + it "updates an assembly admin", versioning: true do within "#assembly_admins" do within "#assembly_admins tr", text: other_user.email do click_on "Edit" @@ -67,6 +71,8 @@ within "#assembly_admins table" do expect(page).to have_content("Collaborator") end + visit decidim_admin.root_path + expect(page).to have_content("changed the role of #{other_user.name} in the #{translated(assembly.title)} assembly") end it "deletes an assembly_user_role" do diff --git a/decidim-assemblies/spec/shared/manage_assembly_members_examples.rb b/decidim-assemblies/spec/shared/manage_assembly_members_examples.rb index e94821a4c35c..2688fa4e79a6 100644 --- a/decidim-assemblies/spec/shared/manage_assembly_members_examples.rb +++ b/decidim-assemblies/spec/shared/manage_assembly_members_examples.rb @@ -12,17 +12,17 @@ context "without existing user" do let!(:assembly_member) { create(:assembly_member, assembly:) } + let(:attributes) { attributes_for(:assembly_member, assembly:) } - it "creates a new assembly member" do + it "creates a new assembly member", versioning: true do click_on "New assembly member" fill_in_datepicker :assembly_member_designation_date_date, with: Time.current.strftime("%d/%m/%Y") within ".new_assembly_member" do - fill_in( - :assembly_member_full_name, - with: "Daisy O'connor" - ) + fill_in(:assembly_member_full_name, with: attributes[:full_name]) + fill_in(:assembly_member_gender, with: attributes[:gender]) + fill_in(:assembly_member_birthplace, with: attributes[:birthplace]) end dynamically_attach_file(:assembly_member_non_user_avatar, Decidim::Dev.asset("avatar.jpg")) do @@ -39,8 +39,11 @@ expect(page).to have_current_path decidim_admin_assemblies.assembly_members_path(assembly) within "#assembly_members table" do - expect(page).to have_content("Daisy O'connor") + expect(page).to have_content(attributes[:full_name]) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{attributes[:full_name]} member") end end @@ -98,6 +101,7 @@ describe "when managing other assembly members" do let!(:assembly_member) { create(:assembly_member, assembly:) } + let(:attributes) { attributes_for(:assembly_member, assembly:) } before do visit current_path @@ -109,16 +113,15 @@ end end - it "updates an assembly member" do + it "updates an assembly member", versioning: true do within "#assembly_members tr", text: assembly_member.full_name do click_on "Edit" end within ".edit_assembly_member" do - fill_in( - :assembly_member_full_name, - with: "Alicia O'connor" - ) + fill_in(:assembly_member_full_name, with: attributes[:full_name]) + fill_in(:assembly_member_gender, with: attributes[:gender]) + fill_in(:assembly_member_birthplace, with: attributes[:birthplace]) find("*[type=submit]").click end @@ -127,8 +130,11 @@ expect(page).to have_current_path decidim_admin_assemblies.assembly_members_path(assembly) within "#assembly_members table" do - expect(page).to have_content("Alicia O'connor") + expect(page).to have_content(attributes[:full_name]) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{assembly_member.full_name} member") end it "deletes the assembly member" do diff --git a/decidim-assemblies/spec/system/admin/admin_manages_assemblies_spec.rb b/decidim-assemblies/spec/system/admin/admin_manages_assemblies_spec.rb index 5323a2afed1f..dc36b6e86698 100644 --- a/decidim-assemblies/spec/system/admin/admin_manages_assemblies_spec.rb +++ b/decidim-assemblies/spec/system/admin/admin_manages_assemblies_spec.rb @@ -45,6 +45,7 @@ let(:image2_filename) { "city2.jpeg" } let(:image2_path) { Decidim::Dev.asset(image2_filename) } + let(:attributes) { attributes_for(:assembly, :with_content_blocks, organization:, blocks_manifests: [:announcement]) } before do click_on "New assembly" @@ -56,36 +57,23 @@ it_behaves_like "having a rich text editor for field", "#closing_date_reason_div", "content" - it "creates a new assembly" do + it "creates a new assembly", versioning: true do within ".new_assembly" do - fill_in_i18n( - :assembly_title, - "#assembly-title-tabs", - en: "My assembly", - es: "Mi proceso participativo", - ca: "El meu procés participatiu" - ) - fill_in_i18n( - :assembly_subtitle, - "#assembly-subtitle-tabs", - en: "Subtitle", - es: "Subtítulo", - ca: "Subtítol" - ) - fill_in_i18n_editor( - :assembly_short_description, - "#assembly-short_description-tabs", - en: "Short description", - es: "Descripción corta", - ca: "Descripció curta" - ) - fill_in_i18n_editor( - :assembly_description, - "#assembly-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:assembly_title, "#assembly-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:assembly_subtitle, "#assembly-subtitle-tabs", **attributes[:subtitle].except("machine_translations")) + fill_in_i18n_editor(:assembly_short_description, "#assembly-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:assembly_description, "#assembly-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:assembly_purpose_of_action, "#assembly-purpose_of_action-tabs", **attributes[:purpose_of_action].except("machine_translations")) + fill_in_i18n_editor(:assembly_composition, "#assembly-composition-tabs", **attributes[:composition].except("machine_translations")) + fill_in_i18n_editor(:assembly_internal_organisation, "#assembly-internal_organisation-tabs", **attributes[:internal_organisation].except("machine_translations")) + fill_in_i18n_editor(:assembly_announcement, "#assembly-announcement-tabs", **attributes[:announcement].except("machine_translations")) + fill_in_i18n_editor(:assembly_closing_date_reason, "#assembly-closing_date_reason-tabs", **attributes[:closing_date_reason].except("machine_translations")) + + fill_in_i18n(:assembly_participatory_scope, "#assembly-participatory_scope-tabs", **attributes[:participatory_scope].except("machine_translations")) + fill_in_i18n(:assembly_participatory_structure, "#assembly-participatory_structure-tabs", **attributes[:participatory_structure].except("machine_translations")) + fill_in_i18n(:assembly_meta_scope, "#assembly-meta_scope-tabs", **attributes[:meta_scope].except("machine_translations")) + fill_in_i18n(:assembly_local_area, "#assembly-local_area-tabs", **attributes[:local_area].except("machine_translations")) + fill_in_i18n(:assembly_target, "#assembly-target-tabs", **attributes[:target].except("machine_translations")) fill_in :assembly_slug, with: "slug" fill_in :assembly_hashtag, with: "#hashtag" @@ -103,8 +91,11 @@ within "[data-content]" do expect(page).to have_current_path decidim_admin_assemblies.assemblies_path(q: { parent_id_eq: parent_assembly&.id }) - expect(page).to have_content("My assembly") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} assembly") end end diff --git a/decidim-assemblies/spec/system/admin/admin_manages_assemblies_types_spec.rb b/decidim-assemblies/spec/system/admin/admin_manages_assemblies_types_spec.rb index e41d100a9e70..199753c73e10 100644 --- a/decidim-assemblies/spec/system/admin/admin_manages_assemblies_types_spec.rb +++ b/decidim-assemblies/spec/system/admin/admin_manages_assemblies_types_spec.rb @@ -2,9 +2,10 @@ require "spec_helper" -describe "Admin manages assemblies" do +describe "Admin manages assemblies types" do let(:admin) { create(:user, :admin, :confirmed) } let(:organization) { admin.organization } + let(:attributes) { attributes_for(:assemblies_type) } describe "Managing assemblies types" do before do @@ -13,18 +14,13 @@ visit decidim_admin_assemblies.assemblies_types_path end - it "can create new assemblies types" do + it "can create new assemblies types", versioning: true do within "[data-content]" do click_on "New assembly type" within ".new_assembly_type" do - fill_in_i18n( - :assemblies_type_title, - "#assemblies_type-title-tabs", - en: "My assembly type", - es: "Mi assembly type", - ca: "La meva assembly type" - ) + fill_in_i18n(:assemblies_type_title, "#assemblies_type-title-tabs", **attributes[:title].except("machine_translations")) + find("*[type=submit]").click end end @@ -32,8 +28,11 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My assembly type") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} assembly type") end context "with existing assemblies types" do @@ -49,23 +48,24 @@ end end - it "can edit them" do + it "can edit them", versioning: true do within "tr", text: translated(assembly_type.title) do click_on "Edit" end within ".edit_assembly_type" do - fill_in_i18n :assemblies_type_title, "#assemblies_type-title-tabs", en: "Another assembly type", - es: "Otra assembly type", - ca: "Una altra assembly type" + fill_in_i18n :assemblies_type_title, "#assemblies_type-title-tabs", **attributes[:title].except("machine_translations") find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("Another assembly type") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} assembly type") end it "can delete them" do diff --git a/decidim-blogs/spec/shared/manage_posts_examples.rb b/decidim-blogs/spec/shared/manage_posts_examples.rb index 5c4e363393c5..bd4d8518f1de 100644 --- a/decidim-blogs/spec/shared/manage_posts_examples.rb +++ b/decidim-blogs/spec/shared/manage_posts_examples.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -shared_examples "manage posts" do +# we really need the audit_check variable, as it seems that a process admin should not be able to see the admin logs +# Therefore, as long we do have the logs checks in this shared example, we need to have the config flag. +shared_examples "manage posts" do |audit_check: true| it_behaves_like "having a rich text editor for field", ".tabs-content[data-tabs-content='post-body-tabs']", "full" do before do within "tr", text: translated(post1.title) do @@ -8,8 +10,9 @@ end end end + let(:attributes) { attributes_for(:post) } - it "updates a post" do + it "updates a post", versioning: true do within "tr", text: translated(post1.title) do click_on "Edit" end @@ -17,20 +20,8 @@ within ".edit_post" do expect(page).to have_select("post_decidim_author_id", selected: translated(author.name)) - fill_in_i18n( - :post_title, - "#post-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) - fill_in_i18n_editor( - :post_body, - "#post-body-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:post_title, "#post-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:post_body, "#post-body-tabs", **attributes[:body].except("machine_translations")) find("*[type=submit]").click end @@ -38,30 +29,22 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) expect(page).to have_content("Post title 2") expect(page).to have_content(translated(author.name)) end + + if audit_check == true + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} blog post") + end end - it "creates a new post" do + it "creates a new post", versioning: true do click_on "New post" - fill_in_i18n( - :post_title, - "#post-title-tabs", - en: "My post", - es: "Mi post", - ca: "El meu post" - ) - - fill_in_i18n_editor( - :post_body, - "#post-body-tabs", - en: "A description", - es: "Descripción", - ca: "Descripció" - ) + fill_in_i18n(:post_title, "#post-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:post_body, "#post-body-tabs", **attributes[:body].except("machine_translations")) within ".new_post" do find("*[type=submit]").click @@ -70,10 +53,15 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My post") + expect(page).to have_content(translated(attributes[:title])) expect(page).to have_content("Post title 1") expect(page).to have_content("Post title 2") end + + if audit_check == true + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} blog post") + end end describe "deleting a post" do diff --git a/decidim-blogs/spec/system/process_admin_manages_post_spec.rb b/decidim-blogs/spec/system/process_admin_manages_post_spec.rb index d87fe5d8051b..02bd0652dcb0 100644 --- a/decidim-blogs/spec/system/process_admin_manages_post_spec.rb +++ b/decidim-blogs/spec/system/process_admin_manages_post_spec.rb @@ -10,5 +10,5 @@ include_context "when managing a component as a process admin" - it_behaves_like "manage posts" + it_behaves_like "manage posts", audit_check: false end diff --git a/decidim-budgets/spec/shared/manage_projects_examples.rb b/decidim-budgets/spec/shared/manage_projects_examples.rb index 869de60dd243..9f77f84f8095 100644 --- a/decidim-budgets/spec/shared/manage_projects_examples.rb +++ b/decidim-budgets/spec/shared/manage_projects_examples.rb @@ -139,26 +139,16 @@ end end - it "creates a new project", :slow do + let(:attributes) { attributes_for(:project) } + + it "creates a new project", versioning: true do within ".bulk-actions-budgets" do click_on "New project" end within ".new_project" do - fill_in_i18n( - :project_title, - "#project-title-tabs", - en: "My project", - es: "Mi proyecto", - ca: "El meu projecte" - ) - fill_in_i18n_editor( - :project_description, - "#project-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:project_title, "#project-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:project_description, "#project-description-tabs", **attributes[:description].except("machine_translations")) fill_in :project_budget_amount, with: 22_000_000 select translated(scope.name), from: :project_decidim_scope_id @@ -170,8 +160,10 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My project") + expect(page).to have_content(translated(attributes[:title])) end + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} project") end context "when deleting a project" do @@ -197,20 +189,16 @@ context "when having existing proposals" do let!(:proposal_component) { create(:proposal_component, participatory_space:) } let!(:proposals) { create_list(:proposal, 5, component: proposal_component) } + let(:attributes) { attributes_for(:project) } - it "updates a project" do + it "updates a project", versioning: true do within "tr", text: translated(project.title) do click_on "Edit" end within ".edit_project" do - fill_in_i18n( - :project_title, - "#project-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:project_title, "#project-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:project_description, "#project-description-tabs", **attributes[:description].except("machine_translations")) tom_select("#proposals_list", option_id: proposals.last(2).map(&:id)) @@ -220,8 +208,11 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} project") end it "removes proposals from project", :slow do diff --git a/decidim-budgets/spec/system/admin_manages_budgets_spec.rb b/decidim-budgets/spec/system/admin_manages_budgets_spec.rb index 346b5ae32a7b..676bd2ccea57 100644 --- a/decidim-budgets/spec/system/admin_manages_budgets_spec.rb +++ b/decidim-budgets/spec/system/admin_manages_budgets_spec.rb @@ -3,12 +3,12 @@ require "spec_helper" describe "Admin manages budgets" do - let(:budget) { create(:budget, component: current_component) } + let!(:budget) { create(:budget, component: current_component) } let(:manifest_name) { "budgets" } + let(:attributes) { attributes_for(:budget) } include_context "when managing a component as an admin" before do - budget switch_to_host(organization.host) login_as user, scope: :user visit_component_admin @@ -20,24 +20,13 @@ it_behaves_like "having a rich text editor", "new_budget", "content" end - it "creates a new budget" do + it "creates a new budget", versioning: true do click_on "New budget" within ".new_budget" do - fill_in_i18n( - :budget_title, - "#budget-title-tabs", - en: "My Budget", - es: "Mi Presupuesto", - ca: "El meu Pressupost" - ) - fill_in_i18n_editor( - :budget_description, - "#budget-description-tabs", - en: "Long description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:budget_title, "#budget-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:budget_description, "#budget-description-tabs", **attributes[:description].except("machine_translations")) + fill_in :budget_weight, with: 1 fill_in :budget_total_budget, with: 100_000_00 select translated(scope.name), from: :budget_decidim_scope_id @@ -48,24 +37,22 @@ expect(page).to have_admin_callout("Budget successfully created.") within "table" do - expect(page).to have_content("My Budget") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} budget") end - describe "updating a budget" do + describe "updating a budget", versioning: true do it "updates a budget" do within "tr", text: translated(budget.title) do page.find(".action-icon--edit").click end within ".edit_budget" do - fill_in_i18n( - :budget_title, - "#budget-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:budget_title, "#budget-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:budget_description, "#budget-description-tabs", **attributes[:description].except("machine_translations")) end click_on "Update budget" @@ -73,8 +60,11 @@ expect(page).to have_admin_callout("Budget successfully updated.") within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} budget") end end diff --git a/decidim-budgets/spec/system/admin_manages_projects_spec.rb b/decidim-budgets/spec/system/admin_manages_projects_spec.rb index 96feff19e61f..5d8f895010fa 100644 --- a/decidim-budgets/spec/system/admin_manages_projects_spec.rb +++ b/decidim-budgets/spec/system/admin_manages_projects_spec.rb @@ -4,14 +4,13 @@ describe "Admin manages projects" do let(:manifest_name) { "budgets" } - let(:budget) { create(:budget, component: current_component) } + let!(:budget) { create(:budget, component: current_component) } let!(:project) { create(:project, budget:) } let!(:destination_budget) { create(:budget, component: current_component) } include_context "when managing a component as an admin" before do - budget switch_to_host(organization.host) login_as user, scope: :user visit_component_admin diff --git a/decidim-conferences/spec/shared/manage_conference_admins_examples.rb b/decidim-conferences/spec/shared/manage_conference_admins_examples.rb index 29d3a9e4f9de..0dd2d340d3e0 100644 --- a/decidim-conferences/spec/shared/manage_conference_admins_examples.rb +++ b/decidim-conferences/spec/shared/manage_conference_admins_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage conference admins examples" do let(:other_user) { create(:user, organization:, email: "my_email@example.org") } + let(:attributes) { attributes_for(:user, organization:) } let!(:conference_admin) do create(:conference_admin, @@ -25,12 +26,12 @@ end end - it "creates a new conference admin" do + it "creates a new conference admin", versioning: true do click_on "New conference admin" within ".new_conference_user_role" do fill_in :conference_user_role_email, with: other_user.email - fill_in :conference_user_role_name, with: "John Doe" + fill_in :conference_user_role_name, with: attributes[:name] select "Administrator", from: :conference_user_role_role find("*[type=submit]").click @@ -41,6 +42,8 @@ within "#conference_admins table" do expect(page).to have_content(other_user.email) end + visit decidim_admin.root_path + expect(page).to have_content("invited #{other_user.name} to the #{translated(conference.title)} conference") end describe "when managing different users" do @@ -49,7 +52,7 @@ visit current_path end - it "updates a conference admin" do + it "updates a conference admin", versioning: true do within "#conference_admins" do within "#conference_admins tr", text: other_user.email do click_on "Edit" @@ -67,6 +70,8 @@ within "#conference_admins table" do expect(page).to have_content("Collaborator") end + visit decidim_admin.root_path + expect(page).to have_content("changed the role of #{other_user.name} in the #{translated(conference.title)} conference") end it "deletes a conference_user_role" do diff --git a/decidim-conferences/spec/shared/manage_conference_speakers_examples.rb b/decidim-conferences/spec/shared/manage_conference_speakers_examples.rb index 40d194a29ed3..b9cee9a1aab7 100644 --- a/decidim-conferences/spec/shared/manage_conference_speakers_examples.rb +++ b/decidim-conferences/spec/shared/manage_conference_speakers_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage conference speakers examples" do let!(:conference_speaker) { create(:conference_speaker, conference:) } + let(:attributes) { attributes_for(:conference_speaker, conference:) } before do switch_to_host(organization.host) @@ -19,14 +20,14 @@ end context "without existing user" do - it "creates a new conference speaker" do + it "creates a new conference speaker", versioning: true do click_on "New speaker" within ".new_conference_speaker" do - fill_in( - :conference_speaker_full_name, - with: "Daisy O'connor" - ) + fill_in(:conference_speaker_full_name, with: attributes[:full_name]) + fill_in_i18n(:conference_speaker_position, "#conference_speaker-position-tabs", **attributes[:position].except("machine_translations")) + fill_in_i18n(:conference_speaker_affiliation, "#conference_speaker-affiliation-tabs", **attributes[:affiliation].except("machine_translations")) + fill_in_i18n_editor(:conference_speaker_short_bio, "#conference_speaker-short_bio-tabs", **attributes[:short_bio].except("machine_translations")) find("*[type=submit]").click end @@ -35,8 +36,10 @@ expect(page).to have_current_path decidim_admin_conferences.conference_speakers_path(conference) within "#conference_speakers table" do - expect(page).to have_content("Daisy O'connor") + expect(page).to have_content(attributes[:full_name]) end + visit decidim_admin.root_path + expect(page).to have_content("created the #{attributes[:full_name]} speaker in the") end end @@ -67,16 +70,16 @@ visit current_path end - it "updates a conference speaker" do + it "updates a conference speaker", versioning: true do within "#conference_speakers tr", text: conference_speaker.full_name do click_on "Edit" end within ".edit_conference_speaker" do - fill_in( - :conference_speaker_full_name, - with: "Alicia O'connor" - ) + fill_in(:conference_speaker_full_name, with: attributes[:full_name]) + fill_in_i18n(:conference_speaker_position, "#conference_speaker-position-tabs", **attributes[:position].except("machine_translations")) + fill_in_i18n(:conference_speaker_affiliation, "#conference_speaker-affiliation-tabs", **attributes[:affiliation].except("machine_translations")) + fill_in_i18n_editor(:conference_speaker_short_bio, "#conference_speaker-short_bio-tabs", **attributes[:short_bio].except("machine_translations")) find("*[type=submit]").click end @@ -85,8 +88,10 @@ expect(page).to have_current_path decidim_admin_conferences.conference_speakers_path(conference) within "#conference_speakers table" do - expect(page).to have_content("Alicia O'connor") + expect(page).to have_content(attributes[:full_name]) end + visit decidim_admin.root_path + expect(page).to have_content("updated the #{conference_speaker.full_name} speaker in the") end it "deletes the conference speaker" do diff --git a/decidim-conferences/spec/shared/manage_conferences_examples.rb b/decidim-conferences/spec/shared/manage_conferences_examples.rb index a9c53bde4103..27d30fea66a1 100644 --- a/decidim-conferences/spec/shared/manage_conferences_examples.rb +++ b/decidim-conferences/spec/shared/manage_conferences_examples.rb @@ -7,6 +7,7 @@ let(:image2_filename) { "city2.jpeg" } let(:image2_path) { Decidim::Dev.asset(image2_filename) } + let(:attributes) { attributes_for(:conference) } before do click_on "New conference" @@ -17,36 +18,13 @@ end it_behaves_like "having a rich text editor for field", "#conference_registrations_terms", "content" - it "creates a new conference" do + it "creates a new conference", versioning: true do within ".new_conference" do - fill_in_i18n( - :conference_title, - "#conference-title-tabs", - en: "My conference", - es: "Mi proceso participativo", - ca: "El meu procés participatiu" - ) - fill_in_i18n( - :conference_slogan, - "#conference-slogan-tabs", - en: "Slogan", - es: "Eslogan", - ca: "Eslógan" - ) - fill_in_i18n_editor( - :conference_short_description, - "#conference-short_description-tabs", - en: "Short description", - es: "Descripción corta", - ca: "Descripció curta" - ) - fill_in_i18n_editor( - :conference_description, - "#conference-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:conference_title, "#conference-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:conference_slogan, "#conference-slogan-tabs", **attributes[:slogan].except("machine_translations")) + fill_in_i18n_editor(:conference_short_description, "#conference-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:conference_description, "#conference-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:conference_objectives, "#conference-objectives-tabs", **attributes[:objectives].except("machine_translations")) fill_in :conference_weight, with: 1 fill_in :conference_slug, with: "slug" @@ -67,14 +45,18 @@ within "[data-content]" do expect(page).to have_current_path decidim_admin_conferences.conferences_path - expect(page).to have_content("My conference") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} conference") end end describe "updating a conference" do let(:image3_filename) { "city3.jpeg" } let(:image3_path) { Decidim::Dev.asset(image3_filename) } + let(:attributes) { attributes_for(:conference) } before do within "tr", text: translated(conference.title) do @@ -82,26 +64,27 @@ end end - it "updates a conference" do - fill_in_i18n( - :conference_title, - "#conference-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + it "updates a conference", versioning: true do dynamically_attach_file(:conference_banner_image, image3_path, remove_before: true) within ".edit_conference" do + fill_in_i18n(:conference_title, "#conference-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:conference_slogan, "#conference-slogan-tabs", **attributes[:slogan].except("machine_translations")) + fill_in_i18n_editor(:conference_short_description, "#conference-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:conference_description, "#conference-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:conference_objectives, "#conference-objectives-tabs", **attributes[:objectives].except("machine_translations")) find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") within "[data-content]" do - expect(page).to have_css("input[value='My new title']") + expect(page).to have_css("input[value='#{translated(attributes[:title])}']") expect(page).to have_css("img[src*='#{image3_filename}']") end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} conference") end end diff --git a/decidim-conferences/spec/shared/manage_media_links_examples.rb b/decidim-conferences/spec/shared/manage_media_links_examples.rb index 8612b12dbf2d..85f849b369af 100644 --- a/decidim-conferences/spec/shared/manage_media_links_examples.rb +++ b/decidim-conferences/spec/shared/manage_media_links_examples.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true shared_examples "manage media links examples" do + let!(:attributes) { attributes_for(:media_link, conference:) } + before do switch_to_host(organization.host) login_as user, scope: :user @@ -15,16 +17,10 @@ click_on "New media link" end - it "creates a new media link" do + it "creates a new media link", versioning: true do within "[data-content]" do within ".new_media_link" do - fill_in_i18n( - :conference_media_link_title, - "#conference_media_link-title-tabs", - en: "Media Link en", - es: "Media Link es", - ca: "Media Link ca" - ) + fill_in_i18n(:conference_media_link_title, "#conference_media_link-title-tabs", **attributes[:title].except("machine_translations")) fill_in :conference_media_link_link, with: "https://decidim.org" fill_in :conference_media_link_weight, with: 2 @@ -38,8 +34,11 @@ within "[data-content]" do expect(page).to have_current_path decidim_admin_conferences.conference_media_links_path(conference) - expect(page).to have_content("Media Link en") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} media link") end end @@ -56,19 +55,13 @@ end end - it "updates a conference media links" do + it "updates a conference media links", versioning: true do within "#media_links tr", text: translated(media_link.title) do click_on "Edit" end within ".edit_media_link" do - fill_in_i18n( - :conference_media_link_title, - "#conference_media_link-title-tabs", - en: "Media Link update en", - es: "Media Link update es", - ca: "Media Link update ca" - ) + fill_in_i18n(:conference_media_link_title, "#conference_media_link-title-tabs", **attributes[:title].except("machine_translations")) fill_in :conference_media_link_link, with: "https://decidim.org" fill_in :conference_media_link_weight, with: 2 @@ -81,8 +74,10 @@ expect(page).to have_current_path decidim_admin_conferences.conference_media_links_path(conference) within "#media_links table" do - expect(page).to have_content("Media Link update en") + expect(page).to have_content(translated(attributes[:title])) end + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(media_link.title)} media link") end it "deletes the conference media link" do diff --git a/decidim-conferences/spec/shared/manage_partners_examples.rb b/decidim-conferences/spec/shared/manage_partners_examples.rb index f3c618a91722..192c08de9b23 100644 --- a/decidim-conferences/spec/shared/manage_partners_examples.rb +++ b/decidim-conferences/spec/shared/manage_partners_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage partners examples" do let!(:conference_partner) { create(:partner, conference:) } + let!(:attributes) { attributes_for(:partner, conference:) } before do switch_to_host(organization.host) @@ -19,20 +20,42 @@ end describe "when managing other conference partners" do + let(:image1_filename) { "city.jpeg" } + let(:image1_path) { Decidim::Dev.asset(image1_filename) } + before do visit current_path end - it "updates a conference partners" do + it "creates a conference partner", versioning: true do + click_on "New partner" + dynamically_attach_file(:conference_partner_logo, image1_path) + + within ".new_partner" do + fill_in(:conference_partner_name, with: attributes[:name]) + + select("Collaborator", from: :conference_partner_partner_type) + + find("*[type=submit]").click + end + expect(page).to have_admin_callout("successfully") + expect(page).to have_current_path decidim_admin_conferences.conference_partners_path(conference) + + within "#partners table" do + expect(page).to have_content(attributes[:name]) + expect(page).to have_content("Collaborator") + end + visit decidim_admin.root_path + expect(page).to have_content("created the partner #{attributes[:name]}") + end + + it "updates a conference partners", versioning: true do within "#partners tr", text: conference_partner.name do click_on "Edit" end within ".edit_partner" do - fill_in( - :conference_partner_name, - with: "Partner name" - ) + fill_in(:conference_partner_name, with: attributes[:name]) select( "Collaborator", @@ -46,9 +69,11 @@ expect(page).to have_current_path decidim_admin_conferences.conference_partners_path(conference) within "#partners table" do - expect(page).to have_content("Partner name") + expect(page).to have_content(attributes[:name]) expect(page).to have_content("Collaborator") end + visit decidim_admin.root_path + expect(page).to have_content("updated the partner #{conference_partner.name}") end context "when the partner type is already a Collaborator" do diff --git a/decidim-conferences/spec/shared/manage_registration_types_examples.rb b/decidim-conferences/spec/shared/manage_registration_types_examples.rb index 9f6963e6c61b..b032e1d393a4 100644 --- a/decidim-conferences/spec/shared/manage_registration_types_examples.rb +++ b/decidim-conferences/spec/shared/manage_registration_types_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage registration types examples" do let!(:registration_type) { create(:registration_type, conference:) } + let(:attributes) { attributes_for(:registration_type, conference:) } before do switch_to_host(organization.host) @@ -23,19 +24,37 @@ visit current_path end + it "creates a conference registration types", versioning: true do + click_on "New registration type" + + within ".new_registration_type" do + fill_in_i18n(:conference_registration_type_title, "#conference_registration_type-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:conference_registration_type_description, "#conference_registration_type-description-tabs", **attributes[:description].except("machine_translations")) + + fill_in(:conference_registration_type_weight, with: 4) + + find("*[type=submit]").click + end + + expect(page).to have_admin_callout("successfully") + expect(page).to have_current_path decidim_admin_conferences.conference_registration_types_path(conference) + + within "#registration_types table" do + expect(page).to have_content(translated(attributes[:title])) + end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} registration type") + end + it "updates a conference registration types" do within "#registration_types tr", text: translated(registration_type.title) do click_on "Edit" end within ".edit_registration_type" do - fill_in_i18n( - :conference_registration_type_title, - "#conference_registration_type-title-tabs", - en: "Registration type title", - es: "Registration type title es", - ca: "Registration type title ca" - ) + fill_in_i18n(:conference_registration_type_title, "#conference_registration_type-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:conference_registration_type_description, "#conference_registration_type-description-tabs", **attributes[:description].except("machine_translations")) find("*[type=submit]").click end @@ -44,8 +63,11 @@ expect(page).to have_current_path decidim_admin_conferences.conference_registration_types_path(conference) within "#registration_types table" do - expect(page).to have_content("Registration type title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(registration_type.title)} registration type") end it "deletes the conference registration type" do diff --git a/decidim-core/app/presenters/decidim/log/resource_presenter.rb b/decidim-core/app/presenters/decidim/log/resource_presenter.rb index 5b6fc8fb6f1f..3b0584ecee13 100644 --- a/decidim-core/app/presenters/decidim/log/resource_presenter.rb +++ b/decidim-core/app/presenters/decidim/log/resource_presenter.rb @@ -10,6 +10,8 @@ module Log # overwrite `BasePresenter#resource_presenter` to return your custom resource presenter. # The only requirement for custom renderers is that they should respond to `present`. class ResourcePresenter + include Decidim::SanitizeHelper + # Public: Initializes the presenter. # # resource - An instance of a model that can be located by @@ -65,7 +67,11 @@ def resource_path # # Returns an HTML-safe String. def present_resource_name - h.translated_attribute extra["title"] + if resource.present? && resource.respond_to?(:presenter) && resource.presenter.respond_to?(:title) + resource.presenter.title(html_escape: true) + else + decidim_escape_translated(extra["title"]).html_safe + end end end end diff --git a/decidim-core/app/services/decidim/log/diff_changeset_calculator.rb b/decidim-core/app/services/decidim/log/diff_changeset_calculator.rb index c1fee50e771d..4846e0ab0579 100644 --- a/decidim-core/app/services/decidim/log/diff_changeset_calculator.rb +++ b/decidim-core/app/services/decidim/log/diff_changeset_calculator.rb @@ -86,7 +86,7 @@ def generate_i18n_changeset(attribute, values, type) locales.flat_map do |locale| previous_value = values.first.try(:[], locale) new_value = values.last.try(:[], locale) - if previous_value == new_value + if previous_value == new_value || (previous_value.nil? && new_value.blank?) nil else label = generate_label(attribute, locale) diff --git a/decidim-debates/app/models/decidim/debates/debate.rb b/decidim-debates/app/models/decidim/debates/debate.rb index 99478aba824c..9684d4a199f2 100644 --- a/decidim-debates/app/models/decidim/debates/debate.rb +++ b/decidim-debates/app/models/decidim/debates/debate.rb @@ -56,6 +56,12 @@ class Debate < Debates::ApplicationRecord } scope_search_multi :with_any_state, [:open, :closed] + # Returns the presenter for this debate, to be used in the views. + # Required by ResourceRenderer. + def presenter + Decidim::Debates::DebatePresenter.new(self) + end + def self.log_presenter_class_for(_log) Decidim::Debates::AdminLog::DebatePresenter end diff --git a/decidim-debates/app/presenters/decidim/debates/admin_log/debate_presenter.rb b/decidim-debates/app/presenters/decidim/debates/admin_log/debate_presenter.rb index 7e7e1fc9a2d5..2eb3068f2f76 100644 --- a/decidim-debates/app/presenters/decidim/debates/admin_log/debate_presenter.rb +++ b/decidim-debates/app/presenters/decidim/debates/admin_log/debate_presenter.rb @@ -15,10 +15,6 @@ module AdminLog class DebatePresenter < Decidim::Log::BasePresenter private - def resource_presenter - @resource_presenter ||= Decidim::Debates::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"]) - end - def diff_fields_mapping { description: "Decidim::Debates::AdminLog::ValueTypes::DebateTitleDescriptionPresenter", diff --git a/decidim-debates/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb b/decidim-debates/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb index 9098a70d461c..c61c1b8e909e 100644 --- a/decidim-debates/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb +++ b/decidim-debates/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb @@ -10,7 +10,7 @@ class DebateTitleDescriptionPresenter < Decidim::Log::ValueTypes::DefaultPresent def present return unless value - renderer = Decidim::ContentRenderers::HashtagRenderer.new(h.translated_attribute(value)) + renderer = Decidim::ContentRenderers::HashtagRenderer.new(h.decidim_escape_translated(value)) renderer.render(links: false).html_safe end end diff --git a/decidim-debates/app/presenters/decidim/debates/log/resource_presenter.rb b/decidim-debates/app/presenters/decidim/debates/log/resource_presenter.rb deleted file mode 100644 index 1804ee80e35c..000000000000 --- a/decidim-debates/app/presenters/decidim/debates/log/resource_presenter.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Debates - module Log - class ResourcePresenter < Decidim::Log::ResourcePresenter - private - - # Private: Presents resource name. - # - # Returns an HTML-safe String. - def present_resource_name - Decidim::Debates::DebatePresenter.new(resource).title - end - end - end - end -end diff --git a/decidim-debates/spec/shared/manage_debates_examples.rb b/decidim-debates/spec/shared/manage_debates_examples.rb index c52d7988a034..818ccd50b985 100644 --- a/decidim-debates/spec/shared/manage_debates_examples.rb +++ b/decidim-debates/spec/shared/manage_debates_examples.rb @@ -2,6 +2,7 @@ RSpec.shared_examples "manage debates" do let!(:debate) { create(:debate, category:, component: current_component) } + let(:attributes) { attributes_for(:debate, :closed, component: current_component) } before { visit_component_admin } @@ -39,19 +40,15 @@ end describe "updating a debate" do - it "updates a debate" do + it "updates a debate", versioning: true do within "tr", text: translated(debate.title) do page.find(".action-icon--edit").click end within ".edit_debate" do - fill_in_i18n( - :debate_title, - "#debate-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:debate_title, "#debate-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:debate_description, "#debate-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:debate_instructions, "#debate-instructions-tabs", **attributes[:instructions].except("machine_translations")) find("*[type=submit]").click end @@ -59,8 +56,11 @@ expect(page).to have_admin_callout "Debate successfully updated" within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} debate on the") end context "when the debate has an author" do @@ -88,31 +88,13 @@ end end - it "creates a new finite debate" do + it "creates a new finite debate", versioning: true do click_on "New debate" within ".new_debate" do - fill_in_i18n( - :debate_title, - "#debate-title-tabs", - en: "My debate", - es: "Mi debate", - ca: "El meu debat" - ) - fill_in_i18n_editor( - :debate_description, - "#debate-description-tabs", - en: "Long description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) - fill_in_i18n_editor( - :debate_instructions, - "#debate-instructions-tabs", - en: "Long instructions", - es: "Instrucciones más largas", - ca: "Instruccions més llargues" - ) + fill_in_i18n(:debate_title, "#debate-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:debate_description, "#debate-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:debate_instructions, "#debate-instructions-tabs", **attributes[:instructions].except("machine_translations")) choose "Finite" end @@ -131,35 +113,20 @@ expect(page).to have_admin_callout "Debate successfully created" within "table" do - expect(page).to have_content("My debate") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} debate on the") end it "creates a new open debate" do click_on "New debate" within ".new_debate" do - fill_in_i18n( - :debate_title, - "#debate-title-tabs", - en: "My debate", - es: "Mi debate", - ca: "El meu debat" - ) - fill_in_i18n_editor( - :debate_description, - "#debate-description-tabs", - en: "Long description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) - fill_in_i18n_editor( - :debate_instructions, - "#debate-instructions-tabs", - en: "Long instructions", - es: "Instrucciones más largas", - ca: "Instruccions més llargues" - ) + fill_in_i18n(:debate_title, "#debate-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:debate_description, "#debate-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:debate_instructions, "#debate-instructions-tabs", **attributes[:instructions].except("machine_translations")) choose "Open" end @@ -176,8 +143,11 @@ expect(page).to have_admin_callout "Debate successfully created" within "table" do - expect(page).to have_content("My debate") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} debate on the") end describe "deleting a debate" do @@ -212,20 +182,14 @@ end end - describe "closing a debate" do + describe "closing a debate", versioning: true do it "closes a debate" do within "tr", text: translated(debate.title) do page.find(".action-icon--close").click end within ".edit_close_debate" do - fill_in_i18n_editor( - :debate_conclusions, - "#debate-conclusions-tabs", - en: "The debate was great", - es: "El debate fué genial", - ca: "El debat ha anat molt bé" - ) + fill_in_i18n_editor(:debate_conclusions, "#debate-conclusions-tabs", **attributes[:conclusions].except("machine_translations")) find("*[type=submit]").click end @@ -239,7 +203,10 @@ end end - expect(page).to have_content("The debate was great") + expect(page).to have_content(strip_tags(translated(attributes[:conclusions])).strip) + + visit decidim_admin.root_path + expect(page).to have_content("performed some action on #{translated(debate.title)} in") end context "when the debate has an author" do diff --git a/decidim-meetings/app/presenters/decidim/meetings/admin_log/meeting_presenter.rb b/decidim-meetings/app/presenters/decidim/meetings/admin_log/meeting_presenter.rb index f8ee82dc73b9..1feb2202166f 100644 --- a/decidim-meetings/app/presenters/decidim/meetings/admin_log/meeting_presenter.rb +++ b/decidim-meetings/app/presenters/decidim/meetings/admin_log/meeting_presenter.rb @@ -15,10 +15,6 @@ module AdminLog class MeetingPresenter < Decidim::Log::BasePresenter private - def resource_presenter - @resource_presenter ||= Decidim::Meetings::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"]) - end - def diff_fields_mapping { address: :string, diff --git a/decidim-meetings/app/presenters/decidim/meetings/admin_log/value_types/meeting_title_description_presenter.rb b/decidim-meetings/app/presenters/decidim/meetings/admin_log/value_types/meeting_title_description_presenter.rb index 77e8ab746670..02694535b0d5 100644 --- a/decidim-meetings/app/presenters/decidim/meetings/admin_log/value_types/meeting_title_description_presenter.rb +++ b/decidim-meetings/app/presenters/decidim/meetings/admin_log/value_types/meeting_title_description_presenter.rb @@ -10,7 +10,7 @@ class MeetingTitleDescriptionPresenter < Decidim::Log::ValueTypes::DefaultPresen def present return unless value - renderer = Decidim::ContentRenderers::HashtagRenderer.new(h.translated_attribute(value)) + renderer = Decidim::ContentRenderers::HashtagRenderer.new(h.decidim_escape_translated(value)) renderer.render(links: false).html_safe end end diff --git a/decidim-meetings/app/presenters/decidim/meetings/log/resource_presenter.rb b/decidim-meetings/app/presenters/decidim/meetings/log/resource_presenter.rb deleted file mode 100644 index 4ee659a92328..000000000000 --- a/decidim-meetings/app/presenters/decidim/meetings/log/resource_presenter.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Meetings - module Log - class ResourcePresenter < Decidim::Log::ResourcePresenter - private - - # Private: Presents resource name. - # - # Returns an HTML-safe String. - def present_resource_name - Decidim::Meetings::MeetingPresenter.new(resource).title - end - end - end - end -end diff --git a/decidim-meetings/spec/system/admin/admin_manages_meetings_spec.rb b/decidim-meetings/spec/system/admin/admin_manages_meetings_spec.rb index 0ecaf464bcb4..65479cd3a283 100644 --- a/decidim-meetings/spec/system/admin/admin_manages_meetings_spec.rb +++ b/decidim-meetings/spec/system/admin/admin_manages_meetings_spec.rb @@ -15,6 +15,7 @@ let(:meeting_start_time) { base_date.utc.strftime("%H:%M") } let(:meeting_end_date) { ((base_date + 2.days) + 1.month).strftime("%d/%m/%Y") } let(:meeting_end_time) { (base_date + 4.hours).strftime("%H:%M") } + let(:attributes) { attributes_for(:meeting, component: current_component) } include_context "when managing a component as an admin" @@ -156,13 +157,12 @@ end within ".edit_meeting" do - fill_in_i18n( - :meeting_title, - "#meeting-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:meeting_title, "#meeting-title-tabs", **attributes[:title].except("machine_translations")) + + fill_in_i18n(:meeting_location, "#meeting-location-tabs", **attributes[:location].except("machine_translations")) + fill_in_i18n(:meeting_location_hints, "#meeting-location_hints-tabs", **attributes[:location_hints].except("machine_translations")) + fill_in_i18n_editor(:meeting_description, "#meeting-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_geocoding :meeting_address, with: address find("*[type=submit]").click @@ -171,8 +171,11 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My new title") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} meeting on the") end it "sets registration enabled to true when registration type is on this platform" do @@ -269,37 +272,13 @@ it "creates a new meeting", :serves_geocoding_autocomplete do click_on "New meeting" - fill_in_i18n( - :meeting_title, - "#meeting-title-tabs", - en: "My meeting", - es: "Mi meeting", - ca: "El meu meeting" - ) + fill_in_i18n(:meeting_title, "#meeting-title-tabs", **attributes[:title].except("machine_translations")) select "In person", from: :meeting_type_of_meeting - fill_in_i18n( - :meeting_location, - "#meeting-location-tabs", - en: "Location", - es: "Location", - ca: "Location" - ) - fill_in_i18n( - :meeting_location_hints, - "#meeting-location_hints-tabs", - en: "Location hints", - es: "Location hints", - ca: "Location hints" - ) - fill_in_i18n_editor( - :meeting_description, - "#meeting-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:meeting_location, "#meeting-location-tabs", **attributes[:location].except("machine_translations")) + fill_in_i18n(:meeting_location_hints, "#meeting-location_hints-tabs", **attributes[:location_hints].except("machine_translations")) + fill_in_i18n_editor(:meeting_description, "#meeting-description-tabs", **attributes[:description].except("machine_translations")) fill_in_geocoding :meeting_address, with: address fill_in_services @@ -321,8 +300,11 @@ expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My meeting") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} meeting on the") end context "when using the front-end geocoder", :serves_geocoding_autocomplete do diff --git a/decidim-pages/spec/system/admin_spec.rb b/decidim-pages/spec/system/admin_spec.rb index 004f1614680a..18279e561e0c 100644 --- a/decidim-pages/spec/system/admin_spec.rb +++ b/decidim-pages/spec/system/admin_spec.rb @@ -21,17 +21,13 @@ visit_component_admin end - it_behaves_like "having a rich text editor for field", ".tabs-content[data-tabs-content='page-body-tabs']", "full" + let!(:attributes) { attributes_for(:static_page) } - it "updates the page" do - new_body = { - en: "

New body

", - ca: "

Nou cos

", - es: "

Nuevo cuerpo

" - } + it_behaves_like "having a rich text editor for field", ".tabs-content[data-tabs-content='page-body-tabs']", "full" + it "updates the page", versioning: true do within "form.edit_page" do - fill_in_i18n_editor(:page_body, "#page-body-tabs", new_body) + fill_in_i18n_editor(:page_body, "#page-body-tabs", **attributes[:content].except("machine_translations")) find("*[type=submit]").click end @@ -39,7 +35,10 @@ visit_component - expect(page).to have_content("New body") + expect(page).to have_content(translated(component.name)) + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(component.name)} page") end end diff --git a/decidim-participatory_processes/lib/decidim/participatory_processes/test/factories.rb b/decidim-participatory_processes/lib/decidim/participatory_processes/test/factories.rb index 4fdd6459d397..4e04a9c4edb1 100644 --- a/decidim-participatory_processes/lib/decidim/participatory_processes/test/factories.rb +++ b/decidim-participatory_processes/lib/decidim/participatory_processes/test/factories.rb @@ -141,6 +141,7 @@ end title { generate_localized_title(:participatory_process_step_title, skip_injection:) } description { generate_localized_description(:participatory_process_step_description, skip_injection:) } + cta_text { generate_localized_description(:participatory_process_step_cta_text, skip_injection:) } start_date { 1.month.ago } end_date { 2.months.from_now } position { nil } diff --git a/decidim-participatory_processes/spec/shared/manage_process_admins_examples.rb b/decidim-participatory_processes/spec/shared/manage_process_admins_examples.rb index 552797fd16f3..deecc7c94367 100644 --- a/decidim-participatory_processes/spec/shared/manage_process_admins_examples.rb +++ b/decidim-participatory_processes/spec/shared/manage_process_admins_examples.rb @@ -2,6 +2,7 @@ shared_examples "manage process admins examples" do let(:other_user) { create(:user, organization:, email: "my_email@example.org") } + let(:attributes) { attributes_for(:user, organization:) } let!(:process_admin) do create(:process_admin, @@ -25,12 +26,12 @@ end end - it "creates a new process admin" do + it "creates a new process admin", versioning: true do click_on "New process admin" within ".new_participatory_process_user_role" do fill_in :participatory_process_user_role_email, with: other_user.email - fill_in :participatory_process_user_role_name, with: "John Doe" + fill_in :participatory_process_user_role_name, with: attributes[:name] select "Administrator", from: :participatory_process_user_role_role find("*[type=submit]").click @@ -41,6 +42,9 @@ within "#process_admins table" do expect(page).to have_content(other_user.email) end + + visit decidim_admin.root_path + expect(page).to have_content("invited the participant #{other_user.name} to the #{translated(participatory_process.title)} participatory process") end describe "when managing different users" do @@ -50,7 +54,7 @@ visit current_path end - it "updates a process admin" do + it "updates a process admin", versioning: true do within "#process_admins" do within "#process_admins tr", text: other_user.email do click_on "Edit" @@ -68,6 +72,9 @@ within "#process_admins table" do expect(page).to have_content("Administrator") end + + visit decidim_admin.root_path + expect(page).to have_content("changed the role of the participant #{other_user.name} in the #{translated(participatory_process.title)} participatory process") end it "deletes a participatory_process_user_role" do diff --git a/decidim-participatory_processes/spec/shared/manage_process_steps_examples.rb b/decidim-participatory_processes/spec/shared/manage_process_steps_examples.rb index 9bbb31ec8f95..7d0f34945648 100644 --- a/decidim-participatory_processes/spec/shared/manage_process_steps_examples.rb +++ b/decidim-participatory_processes/spec/shared/manage_process_steps_examples.rb @@ -9,6 +9,7 @@ active: ) end + let(:attributes) { attributes_for(:participatory_process_step, participatory_process:) } before do switch_to_host(organization.host) @@ -23,23 +24,20 @@ before { click_on "New phase" } end - it "creates a new participatory_process" do + it "creates a new participatory_process", versioning: true do click_on "New phase" fill_in_i18n( :participatory_process_step_title, "#participatory_process_step-title-tabs", - en: "My participatory process step", - es: "Mi fase de proceso participativo", - ca: "La meva fase de procés participatiu" + **attributes[:title].except("machine_translations") ) fill_in_i18n_editor( :participatory_process_step_description, "#participatory_process_step-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" + **attributes[:description].except("machine_translations") ) + fill_in_i18n(:participatory_process_step_cta_text, "#participatory_process_step-cta_text-tabs", **attributes[:cta_text].except("machine_translations")) find_by_id("participatory_process_step_start_date_date").click @@ -55,13 +53,15 @@ expect(page).to have_admin_callout("successfully") within "#steps table" do - expect(page).to have_content("My participatory process step") + expect(page).to have_content(translated(attributes[:title])) expect(page).to have_content("#{Time.new.utc.day},") expect(page).to have_content("#{(Time.new.utc + 2.days).day},") end + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} phase in") end - it "updates a participatory_process_step" do + it "updates a participatory_process_step", versioning: true do within "#steps" do within "tr", text: translated(process_step.title) do click_on "Edit" @@ -69,13 +69,9 @@ end within ".edit_participatory_process_step" do - fill_in_i18n( - :participatory_process_step_title, - "#participatory_process_step-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:participatory_process_step_title, "#participatory_process_step-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_step_description, "#participatory_process_step-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n(:participatory_process_step_cta_text, "#participatory_process_step-cta_text-tabs", **attributes[:cta_text].except("machine_translations")) find("*[type=submit]").click end @@ -83,9 +79,12 @@ expect(page).to have_admin_callout("successfully") within "#steps table" do - expect(page).to have_content("My new title") - click_on("My new title") + expect(page).to have_content(translated(attributes[:title])) + click_on(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} phase in") end context "when deleting a participatory process step" do diff --git a/decidim-participatory_processes/spec/shared/manage_processes_examples.rb b/decidim-participatory_processes/spec/shared/manage_processes_examples.rb index 92575cdad7b5..2cce418a348d 100644 --- a/decidim-participatory_processes/spec/shared/manage_processes_examples.rb +++ b/decidim-participatory_processes/spec/shared/manage_processes_examples.rb @@ -85,6 +85,7 @@ def filter_by_group(group_title) context "when updating a participatory process" do let(:image3_filename) { "city3.jpeg" } let(:image3_path) { Decidim::Dev.asset(image3_filename) } + let(:attributes) { attributes_for(:participatory_process, organization:) } before do within "tr", text: translated(participatory_process.title) do @@ -97,13 +98,18 @@ def filter_by_group(group_title) end it "updates a participatory_process" do - fill_in_i18n( - :participatory_process_title, - "#participatory_process-title-tabs", - en: "My new title", - es: "Mi nuevo título", - ca: "El meu nou títol" - ) + fill_in_i18n(:participatory_process_title, "#participatory_process-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:participatory_process_subtitle, "#participatory_process-subtitle-tabs", **attributes[:subtitle].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_short_description, "#participatory_process-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_description, "#participatory_process-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_announcement, "#participatory_process-announcement-tabs", **attributes[:announcement].except("machine_translations")) + fill_in_i18n(:participatory_process_developer_group, "#participatory_process-developer_group-tabs", **attributes[:developer_group].except("machine_translations")) + fill_in_i18n(:participatory_process_local_area, "#participatory_process-local_area-tabs", **attributes[:local_area].except("machine_translations")) + fill_in_i18n(:participatory_process_meta_scope, "#participatory_process-meta_scope-tabs", **attributes[:meta_scope].except("machine_translations")) + fill_in_i18n(:participatory_process_target, "#participatory_process-target-tabs", **attributes[:target].except("machine_translations")) + fill_in_i18n(:participatory_process_participatory_scope, "#participatory_process-participatory_scope-tabs", **attributes[:participatory_scope].except("machine_translations")) + fill_in_i18n(:participatory_process_participatory_structure, "#participatory_process-participatory_structure-tabs", **attributes[:participatory_structure].except("machine_translations")) + dynamically_attach_file(:participatory_process_banner_image, image3_path, remove_before: true) fill_in_datepicker :participatory_process_end_date_date, with: Time.new.utc.strftime("%d/%m/%Y") @@ -115,9 +121,12 @@ def filter_by_group(group_title) expect(page).to have_admin_callout("successfully") within "[data-content]" do - expect(page).to have_css("input[value='My new title']") + expect(page).to have_css("input[value='#{translated(attributes[:title])}']") expect(page).to have_css("img[src*='#{image3_filename}']") end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} participatory process") end end diff --git a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_groups_spec.rb b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_groups_spec.rb index e5063b167149..5052c25bca16 100644 --- a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_groups_spec.rb +++ b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_groups_spec.rb @@ -8,7 +8,7 @@ let!(:participatory_processes) do create_list(:participatory_process, 3, organization:) end - + let(:attributes) { attributes_for(:participatory_process_group, organization:) } let(:image1_filename) { "city.jpeg" } let(:image1_path) { Decidim::Dev.asset(image1_filename) } @@ -26,35 +26,18 @@ end end - it "creates a new participatory process group" do + it "creates a new participatory process group", versioning: true do within "div.process-title" do click_on "New process group" end within ".new_participatory_process_group" do - fill_in_i18n( - :participatory_process_group_title, - "#participatory_process_group-title-tabs", - en: "My group", - es: "Mi grupo", - ca: "El meu grup" - ) - fill_in_i18n_editor( - :participatory_process_group_description, - "#participatory_process_group-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:participatory_process_group_title, "#participatory_process_group-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:participatory_process_group_developer_group, "#participatory_process_group-developer_group-tabs", **attributes[:developer_group].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_group_description, "#participatory_process_group-description-tabs", **attributes[:description].except("machine_translations")) + fill_in :participatory_process_group_hashtag, with: "hashtag" fill_in :participatory_process_group_group_url, with: "http://example.org" - fill_in_i18n( - :participatory_process_group_developer_group, - "#participatory_process_group-developer_group-tabs", - en: "X corporation", - es: "La corporación X", - ca: "La corporació X" - ) select participatory_processes.first.title["en"], from: :participatory_process_group_participatory_process_ids end @@ -65,12 +48,17 @@ end expect(page).to have_admin_callout("successfully") - expect(page).to have_field(:participatory_process_group_title_en, with: "My group") + expect(page).to have_field(:participatory_process_group_title_en, with: translated(attributes[:title])) expect(page).to have_field(:participatory_process_group_hashtag, with: "hashtag") expect(page).to have_field(:participatory_process_group_group_url, with: "http://example.org") - expect(page).to have_field(:participatory_process_group_developer_group_en, with: "X corporation") + expect(page).to have_field(:participatory_process_group_developer_group_en, with: translated(attributes[:developer_group])) expect(page).to have_select("Related processes", selected: participatory_processes.first.title["en"]) expect(page).to have_css("img[src*='#{image1_filename}']") + + expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} participatory process group") end context "with existing groups" do @@ -90,29 +78,13 @@ end within ".edit_participatory_process_group" do - fill_in_i18n( - :participatory_process_group_title, - "#participatory_process_group-title-tabs", - en: "My old group", - es: "Mi grupo antiguo", - ca: "El meu grup antic" - ) - fill_in_i18n_editor( - :participatory_process_group_description, - "#participatory_process_group-description-tabs", - en: "New description", - es: "Nueva descripción", - ca: "Nova descripció" - ) + fill_in_i18n(:participatory_process_group_title, "#participatory_process_group-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_group_description, "#participatory_process_group-description-tabs", **attributes[:description].except("machine_translations")) + fill_in :participatory_process_group_hashtag, with: "new_hashtag" fill_in :participatory_process_group_group_url, with: "http://new-example.org" - fill_in_i18n( - :participatory_process_group_developer_group, - "#participatory_process_group-developer_group-tabs", - en: "Z corporation", - es: "La corporación Z", - ca: "La corporació Z" - ) + fill_in_i18n(:participatory_process_group_developer_group, "#participatory_process_group-developer_group-tabs", **attributes[:developer_group].except("machine_translations")) + select participatory_processes.last.title["en"], from: :participatory_process_group_participatory_process_ids end @@ -123,13 +95,16 @@ end expect(page).to have_admin_callout("successfully") - expect(page).to have_field(:participatory_process_group_title_en, with: "My old group") - expect(page).to have_content("New description") + expect(page).to have_field(:participatory_process_group_title_en, with: translated(attributes[:title])) + expect(page).to have_content(strip_tags(translated(attributes[:description])).strip) expect(page).to have_field(:participatory_process_group_hashtag, with: "new_hashtag") expect(page).to have_field(:participatory_process_group_group_url, with: "http://new-example.org") - expect(page).to have_field(:participatory_process_group_developer_group_en, with: "Z corporation") + expect(page).to have_field(:participatory_process_group_developer_group_en, with: translated(attributes[:developer_group])) expect(page).to have_select("Related processes", selected: participatory_processes.last.title["en"]) expect(page).to have_css("img[src*='#{image2_filename}']") + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} participatory process group") end it "validates the group attributes" do diff --git a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_types_spec.rb b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_types_spec.rb index 3b3408fb22a4..85d1a7d2c615 100644 --- a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_types_spec.rb +++ b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_process_types_spec.rb @@ -8,6 +8,7 @@ let!(:participatory_processes) do create_list(:participatory_process, 3, organization:) end + let(:attributes) { attributes_for(:participatory_process_type, organization:) } describe "Managing participatory process types" do before do @@ -16,25 +17,23 @@ visit decidim_admin_participatory_processes.participatory_process_types_path end - it "can create new participatory process types" do + it "can create new participatory process types", versioning: true do click_on "New process type" within ".new_participatory_process_type" do - fill_in_i18n( - :participatory_process_type_title, - "#participatory_process_type-title-tabs", - en: "My participatory process type", - es: "Mi tipo de proceso participativo", - ca: "El meu tipus de procés participatiu " - ) + fill_in_i18n(:participatory_process_type_title, "#participatory_process_type-title-tabs", **attributes[:title].except("machine_translations")) + find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("My participatory process type") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} participatory process type") end context "with existing participatory process types" do @@ -56,21 +55,19 @@ end within ".edit_participatory_process_type" do - fill_in_i18n( - :participatory_process_type_title, - "#participatory_process_type-title-tabs", - en: "Another participatory process type", - es: "Otro tipo de proceso participativo", - ca: "Un altre tipus de procés participatiu" - ) + fill_in_i18n(:participatory_process_type_title, "#participatory_process_type-title-tabs", **attributes[:title].except("machine_translations")) + find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") within "table" do - expect(page).to have_content("Another participatory process type") + expect(page).to have_content(translated(attributes[:title])) end + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} participatory process type") end it "can delete them" do diff --git a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_processes_spec.rb b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_processes_spec.rb index f68eb327e5c1..72f13d67ffe6 100644 --- a/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_processes_spec.rb +++ b/decidim-participatory_processes/spec/system/admin/admin_manages_participatory_processes_spec.rb @@ -55,6 +55,7 @@ let(:image2_filename) { "city2.jpeg" } let(:image2_path) { Decidim::Dev.asset(image2_filename) } + let(:attributes) { attributes_for(:participatory_process, organization:) } before do click_on "New process" @@ -66,34 +67,18 @@ it "creates a new participatory process" do within ".new_participatory_process" do - fill_in_i18n( - :participatory_process_title, - "#participatory_process-title-tabs", - en: "My participatory process", - es: "Mi proceso participativo", - ca: "El meu procés participatiu" - ) - fill_in_i18n( - :participatory_process_subtitle, - "#participatory_process-subtitle-tabs", - en: "Subtitle", - es: "Subtítulo", - ca: "Subtítol" - ) - fill_in_i18n_editor( - :participatory_process_short_description, - "#participatory_process-short_description-tabs", - en: "Short description", - es: "Descripción corta", - ca: "Descripció curta" - ) - fill_in_i18n_editor( - :participatory_process_description, - "#participatory_process-description-tabs", - en: "A longer description", - es: "Descripción más larga", - ca: "Descripció més llarga" - ) + fill_in_i18n(:participatory_process_title, "#participatory_process-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:participatory_process_subtitle, "#participatory_process-subtitle-tabs", **attributes[:subtitle].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_short_description, "#participatory_process-short_description-tabs", **attributes[:short_description].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_description, "#participatory_process-description-tabs", **attributes[:description].except("machine_translations")) + fill_in_i18n_editor(:participatory_process_announcement, "#participatory_process-announcement-tabs", **attributes[:announcement].except("machine_translations")) + + fill_in_i18n(:participatory_process_developer_group, "#participatory_process-developer_group-tabs", **attributes[:developer_group].except("machine_translations")) + fill_in_i18n(:participatory_process_local_area, "#participatory_process-local_area-tabs", **attributes[:local_area].except("machine_translations")) + fill_in_i18n(:participatory_process_meta_scope, "#participatory_process-meta_scope-tabs", **attributes[:meta_scope].except("machine_translations")) + fill_in_i18n(:participatory_process_target, "#participatory_process-target-tabs", **attributes[:target].except("machine_translations")) + fill_in_i18n(:participatory_process_participatory_scope, "#participatory_process-participatory_scope-tabs", **attributes[:participatory_scope].except("machine_translations")) + fill_in_i18n(:participatory_process_participatory_structure, "#participatory_process-participatory_structure-tabs", **attributes[:participatory_structure].except("machine_translations")) group_title = participatory_process_groups.first.title["en"] select group_title, from: :participatory_process_participatory_process_group_id @@ -117,6 +102,9 @@ expect(page).to have_content("Phases") expect(page).to have_content("Introduction") end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} participatory process") end end diff --git a/decidim-participatory_processes/spec/types/participatory_process_step_type_spec.rb b/decidim-participatory_processes/spec/types/participatory_process_step_type_spec.rb index 0bc1762bec8b..572730f14846 100644 --- a/decidim-participatory_processes/spec/types/participatory_process_step_type_spec.rb +++ b/decidim-participatory_processes/spec/types/participatory_process_step_type_spec.rb @@ -80,7 +80,7 @@ module ParticipatoryProcesses let(:query) { '{ callToActionText { locales translation(locale:"en") } }' } it "returns the step's call to action text" do - expect(response["callToActionText"]["locales"]).to include(*model.cta_text.keys) + expect(response["callToActionText"]["locales"]).to include(*model.cta_text.except("machine_translations").keys) expect(response["callToActionText"]["translation"]).to eq(model.cta_text["en"]) end end diff --git a/decidim-proposals/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb b/decidim-proposals/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb index d679d8038eda..a8e88721ee93 100644 --- a/decidim-proposals/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb +++ b/decidim-proposals/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb @@ -15,13 +15,9 @@ module AdminLog class ProposalPresenter < Decidim::Log::BasePresenter private - def resource_presenter - @resource_presenter ||= Decidim::Proposals::Log::ResourcePresenter.new(action_log.resource, h, action_log.extra["resource"]) - end - def diff_fields_mapping { - title: "Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter", + title: :i18n, body: "Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter", state: "Decidim::Proposals::AdminLog::ValueTypes::ProposalStatePresenter", answered_at: :date, diff --git a/decidim-proposals/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb b/decidim-proposals/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb index 4048dcc7f4b9..0ef814386db1 100644 --- a/decidim-proposals/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb +++ b/decidim-proposals/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb @@ -5,12 +5,10 @@ module Proposals module AdminLog module ValueTypes class ProposalTitleBodyPresenter < Decidim::Log::ValueTypes::DefaultPresenter - include Decidim::TranslatableAttributes - def present return unless value - translated_value = translated_attribute(value) + translated_value = h.decidim_escape_translated(value) return if translated_value.blank? renderer = Decidim::ContentRenderers::HashtagRenderer.new(translated_value) diff --git a/decidim-proposals/app/presenters/decidim/proposals/log/resource_presenter.rb b/decidim-proposals/app/presenters/decidim/proposals/log/resource_presenter.rb deleted file mode 100644 index fbacf6cacd08..000000000000 --- a/decidim-proposals/app/presenters/decidim/proposals/log/resource_presenter.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Decidim - module Proposals - module Log - class ResourcePresenter < Decidim::Log::ResourcePresenter - private - - # Private: Presents resource name. - # - # Returns an HTML-safe String. - def present_resource_name - if resource.present? - Decidim::Proposals::ProposalPresenter.new(resource).title - else - super - end - end - end - end - end -end diff --git a/decidim-proposals/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb b/decidim-proposals/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb index 01f4ad068187..bcad1f8180ff 100644 --- a/decidim-proposals/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb +++ b/decidim-proposals/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb @@ -11,7 +11,7 @@ class ValuationAssignmentPresenter < Decidim::Log::ResourcePresenter # Returns an HTML-safe String. def present_resource_name if resource.present? - Decidim::Proposals::ProposalPresenter.new(resource.proposal).title + resource.proposal.presenter.title(html_escape: true) else super end diff --git a/decidim-proposals/lib/decidim/proposals/test/factories.rb b/decidim-proposals/lib/decidim/proposals/test/factories.rb index d50b4b27acbb..aae67f87d74f 100644 --- a/decidim-proposals/lib/decidim/proposals/test/factories.rb +++ b/decidim-proposals/lib/decidim/proposals/test/factories.rb @@ -267,6 +267,7 @@ def generate_state_title(token, skip_injection: false) end token { :not_answered } title { generate_state_title(:not_answered, skip_injection:) } + announcement_title { generate_localized_title(:announcement_title, skip_injection:) } component { build(:proposal_component) } bg_color { Faker::Color.hex_color(:light) } text_color { Faker::Color.hex_color(:dark) } @@ -496,7 +497,13 @@ def generate_state_title(token, skip_injection: false) transient do skip_injection { false } end - body { Faker::Lorem.sentences(number: 3).join("\n") } + body do + if skip_injection + generate(:title) + else + " #{generate(:title)}" + end + end proposal { build(:proposal, skip_injection:) } author { build(:user, organization: proposal.organization, skip_injection:) } end diff --git a/decidim-proposals/spec/presenters/decidim/proposals/log/resource_presenter_spec.rb b/decidim-proposals/spec/presenters/decidim/log/resource_presenter_spec.rb similarity index 82% rename from decidim-proposals/spec/presenters/decidim/proposals/log/resource_presenter_spec.rb rename to decidim-proposals/spec/presenters/decidim/log/resource_presenter_spec.rb index cc05381a6036..c97bf493997a 100644 --- a/decidim-proposals/spec/presenters/decidim/proposals/log/resource_presenter_spec.rb +++ b/decidim-proposals/spec/presenters/decidim/log/resource_presenter_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe Decidim::Proposals::Log::ResourcePresenter, type: :helper do +describe Decidim::Log::ResourcePresenter, type: :helper do let(:presenter) { described_class.new(resource, helper, extra) } let(:resource) { create(:proposal, title: Faker::Book.unique.title) } let(:extra) do @@ -12,11 +12,6 @@ end let(:resource_path) { Decidim::ResourceLocatorPresenter.new(resource).path } - before do - helper.extend(Decidim::ApplicationHelper) - helper.extend(Decidim::TranslationsHelper) - end - context "when the resource exists" do it "links to its public page with the name of the proposal" do html = presenter.present diff --git a/decidim-proposals/spec/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter_spec.rb b/decidim-proposals/spec/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter_spec.rb index 8e51d2634f0f..6b105536f92a 100644 --- a/decidim-proposals/spec/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter_spec.rb +++ b/decidim-proposals/spec/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter_spec.rb @@ -2,8 +2,16 @@ require "spec_helper" -describe Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter do - subject { described_class.new(value, _helpers) } +describe Decidim::Proposals::AdminLog::ValueTypes::ProposalTitleBodyPresenter, type: :helper do + subject { described_class.new(value, helper) } + + before do + module FooBar + include Decidim::SanitizeHelper + end + + helper.extend FooBar + end let(:value) do { @@ -11,7 +19,6 @@ "es" => "My title in Spanish" } end - let(:_helpers) { nil } describe "#present" do it "handles i18n fields" do diff --git a/decidim-proposals/spec/shared/manage_proposals_examples.rb b/decidim-proposals/spec/shared/manage_proposals_examples.rb index dd874763b33b..8207a8b0e945 100644 --- a/decidim-proposals/spec/shared/manage_proposals_examples.rb +++ b/decidim-proposals/spec/shared/manage_proposals_examples.rb @@ -65,6 +65,8 @@ end context "when process is not related to any scope" do + let(:attributes) { attributes_for(:proposal, component: current_component) } + it "can be related to a scope" do click_on "New proposal" @@ -73,12 +75,12 @@ end end - it "creates a new proposal", :slow do + it "creates a new proposal", versioning: true do click_on "New proposal" within ".new_proposal" do - fill_in_i18n :proposal_title, "#proposal-title-tabs", en: "Make decidim great again" - fill_in_i18n_editor :proposal_body, "#proposal-body-tabs", en: "Decidim is great but it can be better" + fill_in_i18n :proposal_title, "#proposal-title-tabs", **attributes[:title].except("machine_translations") + fill_in_i18n_editor :proposal_body, "#proposal-body-tabs", **attributes[:body].except("machine_translations") select translated(category.name), from: :proposal_category_id select translated(scope.name), from: :proposal_scope_id find("*[type=submit]").click @@ -89,11 +91,13 @@ within "table" do proposal = Decidim::Proposals::Proposal.last - expect(page).to have_content("Make decidim great again") - expect(translated(proposal.body)).to eq("

Decidim is great but it can be better

") + expect(page).to have_content(translated(attributes[:title])) + expect(translated(proposal.body)).to eq("

#{strip_tags(translated(attributes[:body]))}

") expect(proposal.category).to eq(category) expect(proposal.scope).to eq(scope) end + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} proposal") end end diff --git a/decidim-proposals/spec/system/admin/admin_edits_proposal_spec.rb b/decidim-proposals/spec/system/admin/admin_edits_proposal_spec.rb index ea70eea72f0b..7c167a40de64 100644 --- a/decidim-proposals/spec/system/admin/admin_edits_proposal_spec.rb +++ b/decidim-proposals/spec/system/admin/admin_edits_proposal_spec.rb @@ -22,8 +22,7 @@ end describe "editing an official proposal" do - let(:new_title) { "This is my proposal new title" } - let(:new_body) { "This is my proposal new body" } + let(:attributes) { attributes_for(:proposal, component: current_component) } it "can be updated" do visit_component_admin @@ -31,16 +30,21 @@ find("a.action-icon--edit-proposal").click expect(page).to have_content "Update proposal" - fill_in_i18n :proposal_title, "#proposal-title-tabs", en: new_title - fill_in_i18n_editor :proposal_body, "#proposal-body-tabs", en: new_body + fill_in_i18n :proposal_title, "#proposal-title-tabs", **attributes[:title].except("machine_translations") + fill_in_i18n_editor :proposal_body, "#proposal-body-tabs", **attributes[:body].except("machine_translations") click_on "Update" preview_window = window_opened_by { find("a.action-icon--preview").click } within_window preview_window do - expect(page).to have_content(new_title) - expect(page).to have_content(new_body) + expect(page).to have_content(translated(attributes[:title])) + expect(page).to have_content(strip_tags(translated(attributes[:body])).strip) end + + expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} official proposal") end context "when the proposal has some votes" do diff --git a/decidim-proposals/spec/system/admin/admin_manages_proposal_states_spec.rb b/decidim-proposals/spec/system/admin/admin_manages_proposal_states_spec.rb index 93dfd204cd47..949f9f667c35 100644 --- a/decidim-proposals/spec/system/admin/admin_manages_proposal_states_spec.rb +++ b/decidim-proposals/spec/system/admin/admin_manages_proposal_states_spec.rb @@ -32,6 +32,8 @@ end describe "creating a proposal state" do + let(:attributes) { attributes_for(:proposal_state) } + before do click_on "Statuses" click_on "New status" @@ -40,21 +42,8 @@ it "creates a new proposal state" do expect(Decidim::Proposals::ProposalState.find_by(token: "custom")).to be_nil within ".new_proposal_state" do - fill_in_i18n( - :proposal_state_title, - "#proposal_state-title-tabs", - en: "Custom state", - es: "Estado personalizado", - ca: "Estat personalitzat" - ) - - fill_in_i18n( - :proposal_state_announcement_title, - "#proposal_state-announcement_title-tabs", - en: "A longer announcement", - es: "Anuncio más largo", - ca: "Anunci més llarg" - ) + fill_in_i18n(:proposal_state_title, "#proposal_state-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:proposal_state_announcement_title, "#proposal_state-announcement_title-tabs", **attributes[:announcement_title].except("machine_translations")) within ".proposal-status__color" do find_by_id("proposal_state_text_color_9a6700").click @@ -67,14 +56,17 @@ within "table" do expect(page).to have_css(".label", style: "background-color: #FFFCE5; color: #9A6700; border-color: #9A6700;") - expect(page).to have_content("Custom state") + expect(page).to have_content(translated(attributes[:title])) end - state = Decidim::Proposals::ProposalState.find_by(token: "custom_state") + state = Decidim::Proposals::ProposalState.find_by(token: "script_alert_proposal_state_title_script_not_answered") expect(state).to be_present - expect(translated(state.title)).to eq("Custom state") - expect(translated(state.announcement_title)).to eq("A longer announcement") + expect(translated(state.title)).to eq(translated(attributes[:title])) + expect(translated(state.announcement_title)).to eq(translated(attributes[:announcement_title])) expect(state.css_style).to eq("background-color: #FFFCE5; color: #9A6700; border-color: #9A6700;") + + visit decidim_admin.root_path + expect(page).to have_content("created #{translated(attributes[:title])} in") end it "updates the label and announcement previews" do @@ -124,6 +116,7 @@ } end let!(:state) { create(:proposal_state, component: current_component, **state_params) } + let(:attributes) { attributes_for(:proposal_state) } before do click_on "Statuses" @@ -139,21 +132,8 @@ end within ".edit_proposal_state" do - fill_in_i18n( - :proposal_state_title, - "#proposal_state-title-tabs", - en: "Custom state", - es: "Estado personalizado", - ca: "Estat personalitzat" - ) - - fill_in_i18n( - :proposal_state_announcement_title, - "#proposal_state-announcement_title-tabs", - en: "A longer announcement", - es: "Anuncio más largo", - ca: "Anunci més llarg" - ) + fill_in_i18n(:proposal_state_title, "#proposal_state-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:proposal_state_announcement_title, "#proposal_state-announcement_title-tabs", **attributes[:announcement_title].except("machine_translations")) within ".proposal-status__color" do find_by_id("proposal_state_text_color_9a6700").click @@ -161,17 +141,21 @@ find("*[type=submit]").click end + expect(page).to have_admin_callout("successfully") within "table" do expect(page).to have_css(".label", style: "background-color: #FFFCE5; color: #9A6700; border-color: #9A6700;") - expect(page).to have_content("Custom state") + expect(page).to have_content(translated(attributes[:title])) end state = Decidim::Proposals::ProposalState.find_by(token: "editable_state") - expect(translated(state.title)).to eq("Custom state") - expect(translated(state.announcement_title)).to eq("A longer announcement") + expect(translated(state.title)).to eq(translated(attributes[:title])) + expect(translated(state.announcement_title)).to eq(translated(attributes[:announcement_title])) expect(state.css_style).to eq("background-color: #FFFCE5; color: #9A6700; border-color: #9A6700;") + + visit decidim_admin.root_path + expect(page).to have_content("updated #{translated(attributes[:title])} in") end it "updates the label and announcement previews" do @@ -180,21 +164,8 @@ end within ".edit_proposal_state" do - fill_in_i18n( - :proposal_state_title, - "#proposal_state-title-tabs", - en: "Custom state", - es: "Estado personalizado", - ca: "Estat personalitzat" - ) - - fill_in_i18n( - :proposal_state_announcement_title, - "#proposal_state-announcement_title-tabs", - en: "A longer announcement", - es: "Anuncio más largo", - ca: "Anunci més llarg" - ) + fill_in_i18n(:proposal_state_title, "#proposal_state-title-tabs", **attributes[:title].except("machine_translations")) + fill_in_i18n(:proposal_state_announcement_title, "#proposal_state-announcement_title-tabs", **attributes[:announcement_title].except("machine_translations")) within ".proposal-status__color" do find_by_id("proposal_state_text_color_9a6700").click @@ -202,14 +173,20 @@ expect(page).to have_css("[data-label-preview]", style: "background-color: rgb(255, 252, 229); color: rgb(154, 103, 0);") within "[data-label-preview]" do - expect(page).to have_content("Estat personalitzat") + expect(page).to have_content(translated(attributes[:title])) end expect(page).to have_css("[data-announcement-preview]", style: "background-color: rgb(255, 252, 229); color: rgb(154, 103, 0); border-color: #9A6700/var(--tw-border-opacity);") within "[data-announcement-preview]" do - expect(page).to have_content("Anunci més llarg") + # text_copy.js implements a change event that updates the label. The fill_in_i18n is "changing" the fields, and the "ca" locale is the last one that one that is being changed + expect(page).to have_content(translated(attributes[:announcement_title], locale: "ca")) end + find("*[type=submit]").click end + expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("updated #{translated(attributes[:title])} in") end end diff --git a/decidim-proposals/spec/system/admin/admin_manages_proposal_valuators_spec.rb b/decidim-proposals/spec/system/admin/admin_manages_proposal_valuators_spec.rb index 3fd4906d869a..a1b53649b5a3 100644 --- a/decidim-proposals/spec/system/admin/admin_manages_proposal_valuators_spec.rb +++ b/decidim-proposals/spec/system/admin/admin_manages_proposal_valuators_spec.rb @@ -52,6 +52,11 @@ expect(page).to have_css("td.valuators-count", text: 1) end end + + it "displays log" do + visit decidim_admin.root_path + expect(page).to have_content("assigned the #{translated(proposal.title)} proposal to a valuator") + end end end diff --git a/decidim-proposals/spec/system/admin/index_proposal_notes_spec.rb b/decidim-proposals/spec/system/admin/index_proposal_notes_spec.rb index 06d2b1629498..8426b8017394 100644 --- a/decidim-proposals/spec/system/admin/index_proposal_notes_spec.rb +++ b/decidim-proposals/spec/system/admin/index_proposal_notes_spec.rb @@ -9,6 +9,7 @@ let(:manifest_name) { "proposals" } let(:proposal) { create(:proposal, component:) } let(:participatory_space) { component.participatory_space } + let(:attributes) { attributes_for(:proposal_note) } let(:body) { "New awesome body" } let(:proposal_notes_count) { 5 } @@ -33,15 +34,15 @@ it "shows proposal notes for the current proposal" do proposal_notes.each do |proposal_note| expect(page).to have_content(proposal_note.author.name) - expect(page).to have_content(proposal_note.body) + expect(page).to have_content(decidim_sanitize_translated(proposal_note.body)) end expect(page).to have_css("form") end context "when the form has a text inside body" do - it "creates a proposal note", :slow do + it "creates a proposal note", versioning: true do within ".new_proposal_note" do - fill_in :proposal_note_body, with: body + fill_in :proposal_note_body, with: attributes[:body] find("*[type=submit]").click end @@ -50,8 +51,11 @@ click_on "Private notes" within ".component__show_notes-grid .comment:last-child" do - expect(page).to have_content("New awesome body") + expect(page).to have_content(decidim_sanitize_translated(attributes[:body])) end + + visit decidim_admin.root_path + expect(page).to have_content("left a private note on the #{translated(proposal.title)} proposal") end end diff --git a/decidim-sortitions/spec/shared/manage_sortitions_examples.rb b/decidim-sortitions/spec/shared/manage_sortitions_examples.rb index 1d91844dbdf4..3f74a180a27d 100644 --- a/decidim-sortitions/spec/shared/manage_sortitions_examples.rb +++ b/decidim-sortitions/spec/shared/manage_sortitions_examples.rb @@ -56,37 +56,20 @@ let(:sortition_dice) { Faker::Number.between(from: 1, to: 6) } let(:sortition_target_items) { Faker::Number.between(from: 1, to: 10) } let!(:proposal) { create(:proposal, component: proposal_component) } + let(:attributes) { attributes_for(:sortition, component: current_component) } it_behaves_like "having a rich text editor for field", ".tabs-content[data-tabs-content='sortition-additional_info-tabs']", "full" it_behaves_like "having a rich text editor for field", ".tabs-content[data-tabs-content='sortition-witnesses-tabs']", "content" - it "shows the sortition details" do + it "shows the sortition details", versioning: true do within ".new_sortition" do fill_in :sortition_dice, with: sortition_dice fill_in :sortition_target_items, with: sortition_target_items select translated(proposal_component.name), from: :sortition_decidim_proposals_component_id - fill_in_i18n_editor( - :sortition_witnesses, - "#sortition-witnesses-tabs", - en: "Witnesses", - es: "Testigos", - ca: "Testimonis" - ) - fill_in_i18n_editor( - :sortition_additional_info, - "#sortition-additional_info-tabs", - en: "additional info", - es: "Información adicional", - ca: "Informació adicional" - ) - - fill_in_i18n( - :sortition_title, - "#sortition-title-tabs", - en: "Title", - es: "Título", - ca: "Títol" - ) + + fill_in_i18n_editor(:sortition_witnesses, "#sortition-witnesses-tabs", **attributes[:witnesses].except("machine_translations")) + fill_in_i18n_editor(:sortition_additional_info, "#sortition-additional_info-tabs", **attributes[:additional_info].except("machine_translations")) + fill_in_i18n(:sortition_title, "#sortition-title-tabs", **attributes[:title].except("machine_translations")) accept_confirm { find("*[type=submit]").click } end @@ -114,6 +97,9 @@ expect(page).to have_content(translated(p.title)) end end + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:title])} sortition") end end end diff --git a/decidim-sortitions/spec/shared/update_sortitions_examples.rb b/decidim-sortitions/spec/shared/update_sortitions_examples.rb index dfdd852d0f32..05f063e0024f 100644 --- a/decidim-sortitions/spec/shared/update_sortitions_examples.rb +++ b/decidim-sortitions/spec/shared/update_sortitions_examples.rb @@ -3,6 +3,7 @@ shared_examples "update sortitions" do describe "update sortition data" do let!(:sortition) { create(:sortition, component: current_component) } + let(:attributes) { attributes_for(:sortition, component: current_component) } before do visit_component_admin @@ -24,28 +25,18 @@ end context "when updates a sortition" do - it "Redirects to sortitions view" do + it "Redirects to sortitions view", versioning: true do within ".edit_sortition" do - fill_in_i18n_editor( - :sortition_additional_info, - "#sortition-additional_info-tabs", - en: "Additional info", - es: "Información adicional", - ca: "Informació adicional" - ) - - fill_in_i18n( - :sortition_title, - "#sortition-title-tabs", - en: "Title", - es: "Título", - ca: "Títol" - ) + fill_in_i18n_editor(:sortition_additional_info, "#sortition-additional_info-tabs", **attributes[:additional_info].except("machine_translations")) + fill_in_i18n(:sortition_title, "#sortition-title-tabs", **attributes[:title].except("machine_translations")) find("*[type=submit]").click end expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:title])} sortition") end end end diff --git a/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb b/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb index 2fd1c6faa22b..2c179f36c58c 100644 --- a/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb +++ b/decidim-templates/spec/system/admin/admin_manages_proposal_answer_templates_spec.rb @@ -12,6 +12,7 @@ let!(:templatable) { create(:proposal_component, name: { en: description }, participatory_space:) } let(:proposal_state_id) { Decidim::Proposals::ProposalState.find_by(component: templatable, token:).id } let!(:template) { create(:template, target: :proposal_answer, organization:, templatable:, field_values:) } + let(:attributes) { attributes_for(:template, target: :proposal_answer, organization:, templatable:, field_values:) } before do switch_to_host(organization.host) @@ -41,26 +42,14 @@ end end - it "creates a new template" do + it "creates a new template", versioning: true do within ".new_proposal_answer_template" do select "Participatory process: A participatory process > A component", from: :proposal_answer_template_component_constraint end within ".new_proposal_answer_template" do - fill_in_i18n( - :proposal_answer_template_name, - "#proposal_answer_template-name-tabs", - en: "My template", - es: "Mi plantilla", - ca: "La meva plantilla" - ) - fill_in_i18n_editor( - :proposal_answer_template_description, - "#proposal_answer_template-description-tabs", - en: "Description", - es: "Descripción", - ca: "Descripció" - ) + fill_in_i18n(:proposal_answer_template_name, "#proposal_answer_template-name-tabs", **attributes[:name].except("machine_translations")) + fill_in_i18n_editor(:proposal_answer_template_description, "#proposal_answer_template-description-tabs", **attributes[:description].except("machine_translations")) choose "Accepted" @@ -71,8 +60,12 @@ expect(page).to have_current_path decidim_admin_templates.proposal_answer_templates_path within ".table-list" do expect(page).to have_i18n_content("Participatory process: A participatory process > A component") - expect(page).to have_content("My template") + expect(page).to have_content(translated(attributes[:name])) end + expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("created the #{translated(attributes[:name])} questionnaire template") end end @@ -82,14 +75,9 @@ click_on translated(template.name) end - it "updates a template" do - fill_in_i18n( - :proposal_answer_template_name, - "#proposal_answer_template-name-tabs", - en: "My new name", - es: "Mi nuevo nombre", - ca: "El meu nou nom" - ) + it "updates a template", versioning: true do + fill_in_i18n(:proposal_answer_template_name, "#proposal_answer_template-name-tabs", **attributes[:name].except("machine_translations")) + fill_in_i18n_editor(:proposal_answer_template_description, "#proposal_answer_template-description-tabs", **attributes[:description].except("machine_translations")) within ".edit_proposal_answer_template" do page.find("*[type=submit]").click @@ -99,8 +87,12 @@ expect(page).to have_current_path decidim_admin_templates.proposal_answer_templates_path within ".table-list" do expect(page).to have_i18n_content("Participatory process: A participatory process > A component") - expect(page).to have_content("My new name") + expect(page).to have_content(translated(attributes[:name])) end + expect(page).to have_admin_callout("successfully") + + visit decidim_admin.root_path + expect(page).to have_content("updated the #{translated(attributes[:name])} questionnaire template") end end