Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 5, 2023
1 parent 1f9ec58 commit f7f9893
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim", path: "../decidim" # github: "decidim/decidim", ref: "release/0.26-stable"
gem "decidim", github: "decidim/decidim", ref: "release/0.26-stable"
gem "decidim-custom_proposal_states", path: "."
gem "decidim-elections", path: "../decidim" # , github: "decidim/decidim", ref: "release/0.26-stable"
gem "decidim-elections", github: "decidim/decidim", ref: "release/0.26-stable"

gem "bootsnap"
gem "uglifier", "~> 4.1"

group :development, :test do
gem "faker"

gem "decidim-dev", path: "../decidim" # , github: "decidim/decidim", ref: "release/0.26-stable"
gem "decidim-dev", github: "decidim/decidim", ref: "release/0.26-stable"

gem "rubocop-performance"
gem "simplecov", require: false
Expand Down
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PATH
remote: ../decidim
GIT
remote: https://github.com/decidim/decidim.git
revision: 9f17d2920c505a9ab48026fa8712e0d801c3e711
ref: release/0.26-stable
specs:
decidim (0.26.8)
decidim-accountability (= 0.26.8)
Expand Down Expand Up @@ -471,7 +473,7 @@ GEM
ruby-vips (>= 2.0.17, < 3)
invisible_captcha (0.13.0)
rails (>= 3.2.0)
json (2.7.0)
json (2.7.1)
jwt (2.2.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
Expand Down
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 f7f9893

Please sign in to comment.