decidim-proposals/spec/features/proposals_spec.rb in decidim-0.1.0 vs decidim-proposals/spec/features/proposals_spec.rb in decidim-0.2.0
- old
+ new
@@ -1,18 +1,13 @@
# frozen_string_literal: true
+
require "spec_helper"
describe "Proposals", type: :feature do
include_context "feature"
- let!(:feature) do
- create(:proposal_feature,
- manifest: manifest,
- participatory_process: participatory_process)
- end
let(:manifest_name) { "proposals" }
- let!(:proposals) { create_list(:proposal, 3, feature: feature) }
let!(:category) { create :category, participatory_process: participatory_process }
let!(:scope) { create :scope, organization: organization }
let!(:user) { create :user, :confirmed, organization: organization }
let(:address) { "Carrer Pare Llaurador 113, baixos, 08224 Terrassa" }
@@ -210,10 +205,18 @@
end
end
end
context "viewing a single proposal" do
+ let!(:feature) do
+ create(:proposal_feature,
+ manifest: manifest,
+ participatory_process: participatory_process)
+ end
+
+ let!(:proposals) { create_list(:proposal, 3, feature: feature) }
+
it "allows viewing a single proposal" do
proposal = proposals.first
visit_feature
@@ -352,10 +355,15 @@
end
end
end
context "when a proposal has been linked in a project" do
+ let(:feature) do
+ create(:proposal_feature,
+ manifest: manifest,
+ participatory_process: participatory_process)
+ end
let(:proposal) { create(:proposal, feature: feature) }
let(:budget_feature) do
create(:feature, manifest_name: :budgets, participatory_process: proposal.feature.participatory_process)
end
let(:project) { create(:project, feature: budget_feature) }
@@ -372,29 +380,96 @@
end
end
context "listing proposals in a participatory process" do
it "lists all the proposals" do
+ create(:proposal_feature,
+ manifest: manifest,
+ participatory_process: participatory_process)
+
+ create_list(:proposal, 3, feature: feature)
+
visit_feature
expect(page).to have_css(".card--proposal", count: 3)
end
+ context "when voting phase is over" do
+ let!(:feature) do
+ create(:proposal_feature,
+ :with_votes_blocked,
+ manifest: manifest,
+ participatory_process: participatory_process)
+ end
+
+ let!(:most_voted_proposal) do
+ proposal = create(:proposal, feature: feature)
+ create_list(:proposal_vote, 3, proposal: proposal)
+ proposal
+ end
+
+ let!(:less_voted_proposal) { create(:proposal, feature: feature) }
+
+ before { visit_feature }
+
+ it "lists the proposals ordered by votes by default" do
+ expect(page).to have_selector("a", text: "Most voted")
+ expect(page).to have_selector("#proposals .card-grid .column:first-child", text: most_voted_proposal.title)
+ expect(page).to have_selector("#proposals .card-grid .column:last-child", text: less_voted_proposal.title)
+ end
+
+ it "shows a disabled vote button for each proposal, but no links to full proposals" do
+ expect(page).to have_button("Voting disabled", disabled: true, count: 2)
+ expect(page).to have_no_link("View proposal")
+ end
+ end
+
+ context "when voting is disabled" do
+ let!(:feature) do
+ create(:proposal_feature,
+ :with_votes_disabled,
+ manifest: manifest,
+ participatory_process: participatory_process)
+ end
+
+ let!(:lucky_proposal) { create(:proposal, title: "A", feature: feature) }
+ let!(:unlucky_proposal) { create(:proposal, title: "B", feature: feature) }
+
+ it "lists the proposals ordered randomly by default" do
+ allow_any_instance_of(Decidim::Proposals::Proposal::ActiveRecord_Relation).to \
+ receive(:order_randomly) { |scope, _seed| scope.order(title: :asc) }
+
+ visit_feature
+
+ expect(page).to have_selector("a", text: "Random")
+ expect(page).to have_selector("#proposals .card-grid .column:first-child", text: lucky_proposal.title)
+ expect(page).to have_selector("#proposals .card-grid .column:last-child", text: unlucky_proposal.title)
+ end
+
+ it "shows only links to full proposals" do
+ visit_feature
+
+ expect(page).to have_no_button("Voting disabled", disabled: true)
+ expect(page).to have_no_button("Vote")
+ expect(page).to have_link("View proposal", count: 2)
+ end
+ end
+
context "when there are a lot of proposals" do
before do
create_list(:proposal, 17, feature: feature)
end
it "paginates them" do
visit_feature
expect(page).to have_css(".card--proposal", count: 12)
- find(".pagination-next a").click
+ click_link "Next"
expect(page).to have_selector(".pagination .current", text: "2")
- expect(page).to have_css(".card--proposal", count: 8)
+ expect(page).to have_css(".card--proposal", count: 5)
end
end
context "when filtering" do
context "when official_proposals setting is enabled" do
@@ -410,32 +485,35 @@
end
end
context "by origin 'official'" do
it "lists the filtered proposals" do
- create(:proposal, :official, feature: feature, scope: scope)
+ create_list(:proposal, 2, :official, feature: feature, scope: scope)
+ create(:proposal, feature: feature, scope: scope)
visit_feature
within ".filters" do
choose "Official"
end
- expect(page).to have_css(".card--proposal", count: 1)
- expect(page).to have_content("1 PROPOSAL")
+ expect(page).to have_css(".card--proposal", count: 2)
+ expect(page).to have_content("2 PROPOSALS")
end
end
context "by origin 'citizenship'" do
it "lists the filtered proposals" do
+ create_list(:proposal, 2, feature: feature, scope: scope)
+ create(:proposal, :official, feature: feature, scope: scope)
visit_feature
within ".filters" do
choose "Citizenship"
end
- expect(page).to have_css(".card--proposal", count: proposals.size)
- expect(page).to have_content("#{proposals.size} PROPOSALS")
+ expect(page).to have_css(".card--proposal", count: 2)
+ expect(page).to have_content("2 PROPOSALS")
end
end
end
context "when official_proposals setting is not enabled" do
@@ -576,39 +654,33 @@
end
end
end
context "when ordering" do
- context "by 'most_support'" do
+ context "by 'most_voted'" do
let!(:feature) do
create(:proposal_feature,
:with_votes_enabled,
manifest: manifest,
participatory_process: participatory_process)
end
- before do
- proposals.each do |proposal|
- create(:proposal_vote, proposal: proposal)
- end
- end
-
it "lists the proposals ordered by votes" do
most_voted_proposal = create(:proposal, feature: feature)
create_list(:proposal_vote, 3, proposal: most_voted_proposal)
less_voted_proposal = create(:proposal, feature: feature)
visit_feature
within ".order-by" do
- page.find(".dropdown.menu .is-dropdown-submenu-parent").hover
+ expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Random")
+ page.find("a", text: "Random").click
+ click_link "Most voted"
end
- click_link "Most voted"
-
- expect(page.find("#proposals .card-grid .column:first-child", text: most_voted_proposal.title)).to be
- expect(page.find("#proposals .card-grid .column:last-child", text: less_voted_proposal.title)).to be
+ expect(page).to have_selector("#proposals .card-grid .column:first-child", text: most_voted_proposal.title)
+ expect(page).to have_selector("#proposals .card-grid .column:last-child", text: less_voted_proposal.title)
end
end
context "by 'recent'" do
it "lists the proposals ordered by created at" do
@@ -616,16 +688,16 @@
recent_proposal = create(:proposal, feature: feature)
visit_feature
within ".order-by" do
- page.find(".dropdown.menu .is-dropdown-submenu-parent").hover
+ expect(page).to have_selector("ul[data-dropdown-menu$=dropdown-menu]", text: "Random")
+ page.find("a", text: "Random").click
+ click_link "Recent"
end
- click_link "Recent"
-
- expect(page.find("#proposals .card-grid .column:first-child", text: recent_proposal.title)).to be
- expect(page.find("#proposals .card-grid .column:last-child", text: older_proposal.title)).to be
+ expect(page).to have_selector("#proposals .card-grid .column:first-child", text: recent_proposal.title)
+ expect(page).to have_selector("#proposals .card-grid .column:last-child", text: older_proposal.title)
end
end
end
end
end