Skip to content

Commit

Permalink
update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed May 20, 2024
1 parent cd3eeca commit 81f438d
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 328 deletions.
4 changes: 3 additions & 1 deletion decidim-admin/app/packs/src/decidim/admin/css_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
})
})
Expand Down
14 changes: 9 additions & 5 deletions decidim-proposals/spec/shared/manage_proposals_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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("<p>Decidim is great but it can be better</p>")
expect(page).to have_content(translated(attributes[:title]))
expect(translated(proposal.body)).to eq("<p>#{strip_tags(translated(attributes[:body]))}</p>")
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

Expand Down
16 changes: 16 additions & 0 deletions decidim-proposals/spec/system/admin/admin_edits_proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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
Expand All @@ -43,6 +44,21 @@
end
end

it "can can check logs" do
visit_component_admin

find("a.action-icon--edit-proposal").click
expect(page).to have_content "Update proposal"

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"
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
before do
create(:proposal_vote, proposal:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -139,39 +132,30 @@
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
end

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
Expand All @@ -180,36 +164,29 @@
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
end

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, the "ca" being the last one that one 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
142 changes: 0 additions & 142 deletions decidim-proposals/spec/system/admin/admin_views_admin_logs_spec.rb

This file was deleted.

0 comments on commit 81f438d

Please sign in to comment.