Skip to content

Commit

Permalink
Add specs from dependent components
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Dec 2, 2023
1 parent a4703e9 commit e9764e7
Show file tree
Hide file tree
Showing 14 changed files with 1,066 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/accountability/admin_manages_accountability_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "spec_helper"
require "decidim/proposals/test/capybara_proposals_picker"

describe "Admin manages accountability", type: :system do
let(:manifest_name) { "accountability" }

include_context "when managing an accountability component as an admin"

before do
switch_to_host(organization.host)
login_as user, scope: :user
visit_component_admin
end

describe "results" do
it_behaves_like "manage results"
end
end
55 changes: 55 additions & 0 deletions spec/accountability/explore_results_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require "spec_helper"

describe "Explore results", versioning: true, type: :system do
include_context "with a component"

let(:manifest_name) { "accountability" }
let(:results_count) { 5 }
let!(:scope) { create :scope, organization: organization }
let!(:results) do
create_list(
:result,
results_count,
component: component
)
end

before do
component.update(settings: { scopes_enabled: true })
visit path
end

describe "show" do
let(:path) { decidim_participatory_process_accountability.result_path(id: result.id, participatory_process_slug: participatory_process.slug, component_id: component.id) }
let(:results_count) { 1 }
let(:result) { results.first }

context "with linked proposals" do
let(:proposal_component) do
create(:component, manifest_name: :proposals, participatory_space: result.component.participatory_space)
end
let(:proposals) { create_list(:proposal, 3, component: proposal_component) }
let(:proposal) { proposals.first }

before do
result.link_resources(proposals, "included_proposals")
visit current_path
end

it "shows related proposals" do
proposals.each do |proposal|
expect(page).to have_content(translated(proposal.title))
expect(page).to have_content(proposal.creator_author.name)
expect(page).to have_content(proposal.votes.size)
end
end

it "the result is mentioned in the proposal page" do
click_link translated(proposal.title)
expect(page).to have_i18n_content(result.title)
end
end
end
end
34 changes: 34 additions & 0 deletions spec/accountability/participatory_processes_view_hooks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "spec_helper"

describe "Results in process home", type: :system do
include_context "with a component"
let(:manifest_name) { "accountability" }
let(:results_count) { 5 }

context "when there are no results" do
it "does not show the highlighted results section" do
visit resource_locator(participatory_process).path
expect(page).not_to have_css(".highlighted_results")
end
end

context "when there are results" do
let!(:results) do
create_list(:result, results_count, component: component)
end

it "shows the highlighted results section" do
visit resource_locator(participatory_process).path

within ".highlighted_results" do
expect(page).to have_css(".card--list__item", count: 4)

results_titles = results.map { |r| translated(r.title) }
highlighted_results = page.all(".card--list__item .card--list__heading").map(&:text)
expect(results_titles).to include(*highlighted_results)
end
end
end
end
63 changes: 63 additions & 0 deletions spec/accountability/result_stats_calculator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim::Accountability
describe ResultStatsCalculator do
subject { described_class.new(result) }

let(:participatory_process) { create(:participatory_process, :with_steps) }
let(:current_component) { create :accountability_component, participatory_space: participatory_process }
let(:scope) { create :scope, organization: current_component.organization }
let(:parent_category) { create :category, participatory_space: current_component.participatory_space }
let!(:result) do
create(
:result,
component: current_component,
category: parent_category,
scope: scope
)
end
let(:meetings_component) do
create(:component, manifest_name: :meetings, participatory_space: participatory_process)
end
let(:meetings) do
create_list(
:meeting,
3,
component: meetings_component,
attendees_count: 2,
contributions_count: 5
)
end

let(:proposals_component) do
create(:component, manifest_name: :proposals, participatory_space: participatory_process)
end

let(:proposals) do
create_list(
:proposal,
3,
component: proposals_component
)
end

before do
result.link_resources(proposals, "included_proposals")
result.link_resources(meetings, "meetings_through_proposals")
end

describe "votes_count" do
before do
proposals.each do |proposal|
create(:proposal_vote, proposal: proposal)
end
end

it "counts the votes of the related proposals" do
expect(subject.votes_count).to eq 3
end
end
end
end
26 changes: 26 additions & 0 deletions spec/budgets/admin_manages_projects_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "spec_helper"
require "decidim/proposals/test/capybara_proposals_picker"

describe "Admin manages projects", type: :system do
let(:manifest_name) { "budgets" }
let(:budget) { create :budget, component: current_component }
let!(:project) { create :project, budget: budget }

include_context "when managing a component as an admin"

before do
budget
switch_to_host(organization.host)
login_as user, scope: :user
visit_component_admin

within find("tr", text: translated(budget.title)) do
page.find(".action-icon--edit-projects").click
end
end

it_behaves_like "manage projects"
it_behaves_like "import proposals to projects"
end
73 changes: 73 additions & 0 deletions spec/budgets/orders_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# frozen_string_literal: true

require "spec_helper"

describe "Orders", type: :system do
include_context "with a component"
let(:manifest_name) { "budgets" }

let(:organization) { create :organization, available_authorizations: %w(dummy_authorization_handler) }
let!(:user) { create :user, :confirmed, organization: organization }
let(:project) { projects.first }

let!(:component) do
create(:budgets_component,
:with_vote_threshold_percent,
manifest: manifest,
participatory_space: participatory_process)
end
let(:budget) { create :budget, component: component }

describe "show" do
let!(:project) { create(:project, budget: budget, budget_amount: 25_000_000) }

before do
visit resource_locator([budget, project]).path
end

context "with linked proposals" do
let(:proposal_component) do
create(:component, manifest_name: :proposals, participatory_space: project.component.participatory_space)
end
let(:proposals) { create_list(:proposal, 3, component: proposal_component) }

before do
project.link_resources(proposals, "included_proposals")
end

context "with supports enabled" do
let(:proposal_component) do
create(:proposal_component, :with_votes_enabled, participatory_space: project.component.participatory_space)
end

let(:proposals) { create_list(:proposal, 1, :with_votes, component: proposal_component) }

it "shows the amount of supports" do
visit_budget
click_link translated(project.title)

expect(page.find('span[class="card--list__data__number"]')).to have_content("5")
end
end

context "with supports disabled" do
let(:proposal_component) do
create(:proposal_component, participatory_space: project.component.participatory_space)
end

let(:proposals) { create_list(:proposal, 1, :with_votes, component: proposal_component) }

it "does not show supports" do
visit_budget
click_link translated(project.title)

expect(page).not_to have_selector('span[class="card--list__data__number"]')
end
end
end
end

def visit_budget
page.visit Decidim::EngineRouter.main_proxy(component).budget_projects_path(budget)
end
end
Loading

0 comments on commit e9764e7

Please sign in to comment.