Skip to content

Commit

Permalink
refacto: cleaner test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadrien Froger committed Feb 19, 2025
1 parent aa2486b commit bdae61e
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions decidim-proposals/spec/system/admin/admin_answers_proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

describe "Admin answers proposals" do
let(:manifest_name) { "proposals" }
let(:proposal_answering_enabled?) { true }
let(:proposal_answers_with_costs?) { false }
let!(:component) { create(:proposal_component, participatory_space:) }
let!(:proposals) { create_list(:proposal, 3, component:, cost_report: {}) }
Expand All @@ -21,21 +20,21 @@
settings: { proposal_answering_enabled: true },
step_settings: {
component.participatory_space.active_step.id => {
proposal_answering_enabled: proposal_answering_enabled?,
proposal_answering_enabled: true,
answers_with_costs: proposal_answers_with_costs?
}
}
)
visit current_path
end

it "can accept the proposal" do
it "when accepting, can submit answer with a text answer" do
find("a.action-icon--show-proposal", match: :first).click
find("label[for='proposal_answer_internal_state_accepted']").click
fill_in_i18n_editor(
:proposal_answer_answer,
"#proposal_answer-answer-tabs",
en: "An accepted answer"
en: "An accepted answer without costs"
)
find("*[type=submit][name=commit]", match: :first).click
expect(page).to have_css(".flash", text: "Proposal successfully answered.")
Expand All @@ -44,44 +43,35 @@
context "with costs enabled" do
let(:proposal_answers_with_costs?) { true }

it "when accepting, a cost value and cost report are required" do
before do
find("a.action-icon--show-proposal", match: :first).click
find("input#proposal_answer_internal_state_accepted").click
fill_in_i18n_editor(
:proposal_answer_answer,
"#proposal_answer-answer-tabs",
en: "An accepted answer"
en: "A text answer that is long enough to be valid"
)
end

it "when accepting, a cost value and cost report are required" do
find("input#proposal_answer_internal_state_accepted").click
find("*[type=submit][name=commit]", match: :first).click
expect(find("label[for=proposal_answer_cost_report]")).to have_content("Required field")
expect(find("label[for=proposal_answer_cost]")).to have_content("Required field")
expect(page).to have_css(".flash", text: "There was a problem answering this proposal.")
end

it "rejects without any cost value or cost report" do
find("a.action-icon--show-proposal", match: :first).click
it "when rejecting, do not require a cost value or cost report" do
find("input#proposal_answer_internal_state_rejected").click
fill_in_i18n_editor(
:proposal_answer_answer,
"#proposal_answer-answer-tabs",
en: "A Rejected answer"
)
find("*[type=submit][name=commit]", match: :first).click
expect(page).to have_css(".flash", text: "Proposal successfully answered.")
end

it "accepts with a cost value and cost report" do
find("a.action-icon--show-proposal", match: :first).click
it "when accepting, can submit answer with a cost value and cost report" do
find("input#proposal_answer_internal_state_accepted").click
fill_in_i18n_editor(
:proposal_answer_answer,
"#proposal_answer-answer-tabs",
en: "An accepted answer with cost report"
)
fill_in_i18n_editor(
:proposal_answer_cost_report,
"#proposal_answer-cost_report-tabs",
en: "Cost report on the "
en: "Cost report on the proposal"
)
fill_in :proposal_answer_cost, with: "50"

Expand Down

0 comments on commit bdae61e

Please sign in to comment.