Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide more information link when there's no description on an election #9099

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def ordered_answers(question)
end

def more_information?(answer)
answer.description || answer.proposals.any? || answer.photos.any?
translated_attribute(answer.description).present? ||
andreslucena marked this conversation as resolved.
Show resolved Hide resolved
answer.proposals.any? ||
answer.photos.any?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
module Decidim
module Elections
describe VotesHelper do
let(:question) { create :question, :complete, answers: 3, random_answers_order: random_answers_order }
let(:random_answers_order) { true }

let(:helper) do
Class.new(ActionView::Base) do
include VotesHelper
include TranslatableAttributes
end.new(ActionView::LookupContext.new(ActionController::Base.view_paths), {}, [])
end

describe "ordered_answers" do
subject(:uniq_results) { repetitions.times.map { helper.ordered_answers(question) }.uniq }

let(:question) { create :question, :complete, answers: 3, random_answers_order: random_answers_order }
let(:repetitions) { 100 }
let(:random_answers_order) { true }

it "orders answers in different order on different calls" do
# This test could randomly fail with a very low probability (6*(5.0/6)**100, or 1 of 13.802.995 times)
Expand All @@ -33,6 +41,33 @@ module Elections
end
end
end

describe "more_information?" do
let(:answer) { question.answers.first }
let(:show_more_information) { helper.more_information?(answer) }

context "when the answer has a description" do
before do
answer.description = { "en" => "Description" }
answer.save!
end

it "returns true" do
expect(show_more_information).to be_truthy
end
end

context "when the answer has no description" do
before do
answer.description = {}
answer.save!
end

it "returns false" do
expect(show_more_information).to be_falsey
end
end
end
end
end
end
30 changes: 30 additions & 0 deletions decidim-elections/spec/system/vote_online_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@

uses_the_voting_booth
end

context "when there's description in a question" do
before do
# rubocop:disable Rails/SkipsModelValidations
Decidim::Elections::Answer.update_all(description: { en: "Some text" })
# rubocop:enable Rails/SkipsModelValidations
end

it "shows a link to view more information about the election" do
visit_component
click_link translated(election.title)
click_link "Start voting"
expect(page).to have_content("MORE INFORMATION")
end
end

context "when there's no description in a question" do
before do
# rubocop:disable Rails/SkipsModelValidations
Decidim::Elections::Answer.update_all(description: {})
# rubocop:enable Rails/SkipsModelValidations
end

it "does not show the more information link" do
visit_component
click_link translated(election.title)
click_link "Start voting"
expect(page).not_to have_content("MORE INFORMATION")
end
end
end

context "when the election is not published" do
Expand Down