Skip to content

Commit

Permalink
Hide more information link when there's no description
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed May 8, 2022
1 parent 5867dc8 commit aa4cc65
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
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? ||
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

0 comments on commit aa4cc65

Please sign in to comment.