Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 2, 2023
1 parent e9764e7 commit cdde53f
Show file tree
Hide file tree
Showing 4 changed files with 497 additions and 5 deletions.
5 changes: 5 additions & 0 deletions decidim-custom_proposal_states.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ Gem::Specification.new do |s|

s.add_dependency "decidim-core", "~> 0.26.0"
s.add_dependency "decidim-proposals", "~> 0.26.0"
s.add_development_dependency "decidim-accountability", "~> 0.26.0"
s.add_development_dependency "decidim-budgets", "~> 0.26.0"
s.add_development_dependency "decidim-dev", "~> 0.26.0"
s.add_development_dependency "decidim-elections", "~> 0.26.0"
s.add_development_dependency "decidim-sortitions", "~> 0.26.0"
end
125 changes: 123 additions & 2 deletions spec/accountability/admin_manages_accountability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

describe "Admin manages accountability", type: :system do
let(:manifest_name) { "accountability" }
let!(:result) { create :result, scope: scope, component: current_component }
let!(:child_result) { create :result, scope: scope, component: current_component, parent: result }
let!(:status) { create :status, key: "ongoing", name: { en: "Ongoing" }, component: current_component }

include_context "when managing an accountability component as an admin"
include_context "when managing a component as an admin"

before do
switch_to_host(organization.host)
Expand All @@ -15,6 +18,124 @@
end

describe "results" do
it_behaves_like "manage results"
describe "admin form" do
before { click_on "New Result", match: :first }

it_behaves_like "having a rich text editor", "new_result", "full"

it "displays the proposals picker" do
expect(page).to have_content("Choose proposals")
end

context "when proposal linking is disabled" do
before do
allow(Decidim::Accountability).to receive(:enable_proposal_linking).and_return(false)

# Reload the page with the updated settings
visit current_path
end

it "does not display the proposal picker" do
expect(page).not_to have_content "Choose proposals"
end
end
end

context "when having existing proposals" do
let!(:proposal_component) { create(:proposal_component, participatory_space: participatory_space) }
let!(:proposals) { create_list :proposal, 5, component: proposal_component, skip_injection: true }

it "updates a result" do
within find("tr", text: translated(result.title)) do
click_link "Edit"
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"
)

proposals_pick(select_data_picker(:result_proposals, multiple: true), proposals.last(2))

find("*[type=submit]").click
end

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

within "table" do
expect(page).to have_content("My new title")
end
end

it "creates a new result", :slow do
click_link "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"
)

proposals_pick(select_data_picker(:result_proposals, multiple: true), proposals.first(2))
scope_pick(select_data_picker(:result_decidim_scope_id), scope)
select translated(category.name), from: :result_decidim_category_id

find("*[type=submit]").click
end

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

within "table" do
expect(page).to have_content("My result")
end
end
end

it "allows the user to preview the result" do
within find("tr", text: translated(result.title)) do
klass = "action-icon--preview"
href = resource_locator(result).path
target = "blank"

expect(page).to have_selector(
:xpath,
"//a[contains(@class,'#{klass}')][@href='#{href}'][@target='#{target}']"
)
end
end

describe "deleting a result" do
let!(:result2) { create(:result, component: current_component) }

before do
visit current_path
end

it "deletes a result" do
within find("tr", text: translated(result2.title)) do
accept_confirm { click_link "Delete" }
end

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

within "table" do
expect(page).to have_no_content(translated(result2.title))
end
end
end
end
end
Loading

0 comments on commit cdde53f

Please sign in to comment.