Skip to content

Commit

Permalink
Backport 'Refactor malformed titles in admin logs (part 2)' to v0.27 (#…
Browse files Browse the repository at this point in the history
…13085)

* Refactor malformed titles in admin logs (part 2)

* Refactor admin logs

* Component presenters

* Various logs

* More logs

* Add logs for moderation

* Fix spec

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Add missing spec

---------

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Fix syntax errors in PR

* Fix specs

* Add specs

* Fix failing spec

---------

Co-authored-by: Andrés Pereira de Lucena <[email protected]>
  • Loading branch information
alecslupu and andreslucena authored Jul 11, 2024
1 parent 2b2aea3 commit 9d79f09
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

shared_examples "manage attachment collections examples" do
let!(:attachment_collection) { create(:attachment_collection, collection_for: collection_for) }
let(:attributes) { attributes_for(:attachment_collection) }

before do
visit current_path
Expand Down Expand Up @@ -30,17 +31,13 @@
fill_in_i18n(
:attachment_collection_name,
"#attachment_collection-name-tabs",
en: "Application forms",
es: "Formularios de solicitud",
ca: "Formularis de sol·licitud"
**attributes[:name].except("machine_translations")
)

fill_in_i18n(
:attachment_collection_description,
"#attachment_collection-description-tabs",
en: "Contains the application forms",
es: "Contiene los formularios de solicitud",
ca: "Conté els formularis de sol·licitud"
**attributes[:description].except("machine_translations")
)

find("*[type=submit]").click
Expand All @@ -49,8 +46,11 @@
expect(page).to have_admin_callout("successfully")

within "#attachment_collections table" do
expect(page).to have_link("Application forms")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("created the #{translated(attributes[:name])} attachment collection")
end

it "can update an attachment collection" do
Expand All @@ -64,9 +64,7 @@
fill_in_i18n(
:attachment_collection_name,
"#attachment_collection-name-tabs",
en: "Latest application forms",
es: "Últimos formularios de solicitud",
ca: "Últims formularis de sol·licitud"
**attributes[:name].except("machine_translations")
)

find("*[type=submit]").click
Expand All @@ -75,8 +73,11 @@
expect(page).to have_admin_callout("successfully")

within "#attachment_collections table" do
expect(page).to have_link("Latest application forms")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("updated the #{translated(attributes[:name])} attachment collection")
end

context "when deleting a attachment collection" do
Expand Down
19 changes: 11 additions & 8 deletions decidim-admin/lib/decidim/admin/test/manage_categories_examples.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

shared_examples "manage categories examples" do
let(:attributes) { attributes_for(:category) }
it "lists all the categories for the process" do
within "#categories table" do
expect(page).to have_content(translated(category.name, locale: :en))
Expand All @@ -25,9 +26,7 @@
fill_in_i18n(
:category_name,
"#category-name-tabs",
en: "My category",
es: "Mi categoría",
ca: "La meva categoria"
**attributes[:name].except("machine_translations")
)

find("*[type=submit]").click
Expand All @@ -36,8 +35,11 @@
expect(page).to have_admin_callout("successfully")

within "#categories table" do
expect(page).to have_content("My category")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("added the #{translated(attributes[:name])} category to the")
end

it "updates a category" do
Expand All @@ -51,9 +53,7 @@
fill_in_i18n(
:category_name,
"#category-name-tabs",
en: "My new name",
es: "Mi nuevo nombre",
ca: "El meu nou nom"
**attributes[:name].except("machine_translations")
)

find("*[type=submit]").click
Expand All @@ -62,8 +62,11 @@
expect(page).to have_admin_callout("successfully")

within "#categories 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])} category in the")
end

context "when deleting a category" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@
expect(page).to have_admin_callout("Resource successfully unreported")
end

it "user can hide a resource" do
within "tr[data-id=\"#{moderation.id}\"]" do
click_link "Hide"
end

expect(page).to have_admin_callout("Resource successfully hidden")
expect(page).to have_no_content(moderation.reportable.reported_content_url)
end

it "user can sort by report count" do
moderations.each_with_index { |moderation, index| moderation.update(report_count: index + 1) }
moderations_ordered_by_report_count_asc = moderations.sort_by(&:report_count)
Expand Down
22 changes: 22 additions & 0 deletions decidim-admin/spec/system/admin_manage_moderated_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,27 @@

it_behaves_like "a paginated collection", url: true
end

context "when the user is blocked" do
let!(:first_user) { create(:user, :confirmed, organization: organization) }

before do
visit decidim_admin.moderated_users_path
end

it "displays the proper log" do
within find("tr", text: first_user.name) do
click_link "Block"
end
fill_in :block_user_justification, with: "This user is a spammer" * 2 # to have at least 15 chars

click_on I18n.t("decidim.admin.block_user.new.action")

expect(first_user.reload).to be_blocked

visit decidim_admin.root_path
expect(page).to have_content("blocked user")
end
end
end
end
12 changes: 12 additions & 0 deletions decidim-admin/spec/system/admin_manages_global_moderations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@

it_behaves_like "manage moderations" do
let(:moderations_link_text) { "Global moderations" }

it "user can hide a resource" do
within "tr[data-id=\"#{moderation.id}\"]" do
click_link "Hide"
end

expect(page).to have_admin_callout("Resource successfully hidden")
expect(page).to have_no_content(moderation.reportable.reported_content_url)

visit decidim_admin.root_path
expect(page).to have_content("hid a resource of type")
end
end

it_behaves_like "sorted moderations" do
Expand Down
3 changes: 3 additions & 0 deletions decidim-admin/spec/system/admin_manages_help_sections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

help_content = Decidim::ContextualHelpSection.find_content(organization, :participatory_processes)
expect(help_content).to include("en" => "<p>Well hello!</p>")

visit decidim_admin.root_path
expect(page).to have_content("updated the Participatory processes help section")
end

it "destroys the section when it is empty" do
Expand Down
19 changes: 11 additions & 8 deletions decidim-admin/spec/system/admin_manages_newsletters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

describe "Admin manages newsletters", type: :system do
let(:organization) { create(:organization) }
let!(:attributes) { attributes_for(:newsletter, organization: organization) }
let(:user) { create(:user, :admin, :confirmed, name: "Sarah Kerrigan", organization: organization) }
let!(:deliverable_users) { create_list(:user, 5, :confirmed, newsletter_notifications_at: Time.current, organization: organization) }

Expand Down Expand Up @@ -43,9 +44,7 @@
fill_in_i18n(
:newsletter_subject,
"#newsletter-subject-tabs",
en: "A fancy newsletter for %{name}",
es: "Un correo electrónico muy chulo para %{name}",
ca: "Un correu electrònic flipant per a %{name}"
**attributes[:subject].except("machine_translations")
)

fill_in_i18n_editor(
Expand Down Expand Up @@ -84,7 +83,10 @@
end

expect(page).to have_content("Preview")
expect(page).to have_content("A fancy newsletter for #{user.name}")
expect(page).to have_content(translated(attributes[:subject]))

visit decidim_admin.root_path
expect(page).to have_content("created the #{translated(attributes[:subject])} newsletter")
end
end

Expand Down Expand Up @@ -128,9 +130,7 @@
fill_in_i18n(
:newsletter_subject,
"#newsletter-subject-tabs",
en: "A fancy newsletter",
es: "Un correo electrónico muy chulo",
ca: "Un correu electrònic flipant"
**attributes[:subject].except("machine_translations")
)

fill_in_i18n_editor(
Expand All @@ -145,7 +145,10 @@
end

expect(page).to have_content("Preview")
expect(page).to have_content("A fancy newsletter")
expect(page).to have_content(translated(attributes[:subject]))

visit decidim_admin.root_path
expect(page).to have_content("updated the #{translated(attributes[:subject])} newsletter")
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
describe "Admin manages area types", type: :system do
let(:admin) { create :user, :admin, :confirmed }
let(:organization) { admin.organization }
let(:attributes) { attributes_for(:area_type) }

before do
switch_to_host(organization.host)
Expand All @@ -23,17 +24,13 @@
fill_in_i18n(
:area_type_name,
"#area_type-name-tabs",
en: "Sectorial en",
es: "Sectorial es",
ca: "Sectorial ca"
**attributes[:name].except("machine_translations")
)

fill_in_i18n(
:area_type_plural,
"#area_type-plural-tabs",
en: "Sectorials en",
es: "Sectoriales es",
ca: "Sectorials ca"
**attributes[:plural].except("machine_translations")
)

find("*[type=submit]").click
Expand All @@ -42,8 +39,11 @@
expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("Sectorial en")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("created the #{translated(attributes[:name])} area type")
end

context "with existing area_types" do
Expand All @@ -68,22 +68,25 @@
fill_in_i18n(
:area_type_name,
"#area_type-name-tabs",
en: "Not Sectorial en"
**attributes[:name].except("machine_translations")
)

fill_in_i18n(
:area_type_plural,
"#area_type-plural-tabs",
en: "This is the new pluarl"
**attributes[:plural].except("machine_translations")
)
find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("Not Sectorial en")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("updated the #{translated(attributes[:name])} area type")
end

it "can delete them" do
Expand Down
19 changes: 11 additions & 8 deletions decidim-admin/spec/system/admin_manages_organization_areas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

let(:admin) { create :user, :admin, :confirmed }
let(:organization) { admin.organization }
let(:attributes) { attributes_for(:area) }

before do
switch_to_host(organization.host)
Expand All @@ -26,9 +27,7 @@
click_link "Add"

within ".new_area" do
fill_in_i18n :area_name, "#area-name-tabs", en: "My area",
es: "Mi area",
ca: "La meva area"
fill_in_i18n :area_name, "#area-name-tabs", **attributes[:name].except("machine_translations")
select area_type.name["en"], from: :area_area_type_id

find("*[type=submit]").click
Expand All @@ -37,8 +36,11 @@
expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("My area")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("created the #{translated(attributes[:name])} area")
end

context "with existing areas" do
Expand All @@ -61,17 +63,18 @@
end

within ".edit_area" do
fill_in_i18n :area_name, "#area-name-tabs", en: "Another area",
es: "Otra area",
ca: "Una altra area"
fill_in_i18n :area_name, "#area-name-tabs", **attributes[:name].except("machine_translations")
find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "table" do
expect(page).to have_content("Another area")
expect(page).to have_content(translated(attributes[:name]))
end

visit decidim_admin.root_path
expect(page).to have_content("updated the #{translated(attributes[:name])} area")
end

it "can delete them" do
Expand Down
Loading

0 comments on commit 9d79f09

Please sign in to comment.