Skip to content

Commit

Permalink
Add system spec to test delegation vote
Browse files Browse the repository at this point in the history
  • Loading branch information
sauloperez committed Sep 21, 2020
1 parent 68a9dc5 commit 5947dbb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(() => {
});

delegationVoteButtons.click((e) => {
delegationDialog.foundation("close");
voteDialog.foundation("open");
delegationField.val($(e.currentTarget).data("delegation-id"));
delegationCalloutsMessage.text($(e.currentTarget).data("delegation-granter-name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
method: :delete,
remote: true,
data: { disable: true },
class: "button expanded success unvote_button" do %>
class: "button expanded success delegation_unvote_button" do %>
<%= hidden_field_tag "decidim_consultations_delegation_id", delegation.id, id: "decidim_consultations_delegation_id_delete_#{delegation.id}" %>
<div class="vote-button-caption"
data-original="<%= t("questions.vote_button.already_voted", scope: "decidim") %>"
Expand Down
44 changes: 44 additions & 0 deletions spec/system/decidim/action_delegator/delegations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require "spec_helper"

describe "Delegation vote", type: :system do
let(:organization) { create(:organization) }
let(:question) { create :question, :published, consultation: consultation }

context "when active consultation" do
let(:consultation) { create(:consultation, :active, organization: organization) }
let(:user) { create(:user, :confirmed, organization: organization) }

context "and authenticated user" do
context "and never voted before" do
let!(:response) { create :response, question: question }
let(:setting) { create(:setting, consultation: consultation) }
let(:granter) { create(:user, :confirmed, organization: organization) }
let!(:delegation) { create(:delegation, setting: setting, granter: granter, grantee: user) }

before do
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim_consultations.question_path(question)
end

it "Page contains a link to the delegations modal" do
expect(page).to have_link(id: "delegations-button")
end

it "lets the user vote on behalf of some other member" do
click_link(id: "delegations-button")
click_link(class: "delegation-vote-button")

expect(page).to have_content(I18n.t("decidim.action_delegator.delegations_modal.callout"))

click_button translated(response.title)
click_button "Confirm"

expect(page).to have_button(class: "delegation_unvote_button", visible: :hidden)
end
end
end
end
end

0 comments on commit 5947dbb

Please sign in to comment.