Skip to content

Commit

Permalink
Add read more links to poll question component
Browse files Browse the repository at this point in the history
  • Loading branch information
decabeza authored and Senen committed Oct 14, 2022
1 parent 991cfad commit e5dc702
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/components/polls/questions/question_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
<div id="<%= dom_id(question) %>_answers" class="padding">
<%= render Polls::Questions::AnswersComponent.new(question) %>
</div>

<% if question.answers_with_read_more? %>
<div>
<p><%= t("poll_questions.read_more_about") %></p>
<p><%= sanitize answers_read_more_links %></p>
</div>
<% end %>
</div>
6 changes: 6 additions & 0 deletions app/components/polls/questions/question_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ class Polls::Questions::QuestionComponent < ApplicationComponent
def initialize(question:)
@question = question
end

def answers_read_more_links
question.answers_with_read_more.map do |answer|
link_to answer.title, "#answer_#{answer.id}"
end.join(", ")
end
end
1 change: 1 addition & 0 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ en:
description:
unique: "You can select a maximum of 1 answer."
multiple: "You can select a maximum of %{maximum} answers."
read_more_about: "Read more about:"
proposal_notifications:
new:
title: "Send notification"
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ es:
description:
unique: "Puedes seleccionar un máximo de 1 respuesta."
multiple: "Puedes seleccionar un máximo de %{maximum} respuestas."
read_more_about: "Leer más:"
proposal_notifications:
new:
title: "Enviar notificación"
Expand Down
18 changes: 18 additions & 0 deletions spec/components/polls/questions/question_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "rails_helper"

describe Polls::Questions::QuestionComponent do
it "renders more information links when any question answer has additional information" do
question = create(:poll_question)
answer_a = create(:poll_question_answer, question: question, title: "Answer A")
answer_b = create(:poll_question_answer, question: question, title: "Answer B")
allow_any_instance_of(Poll::Question::Answer).to receive(:with_read_more?).and_return(true)

render_inline Polls::Questions::QuestionComponent.new(question: question)

poll_question = page.find("#poll_question_#{question.id}")
expect(poll_question).to have_content("Read more about")
expect(poll_question).to have_link("Answer A", href: "#answer_#{answer_a.id}")
expect(poll_question).to have_link("Answer B", href: "#answer_#{answer_b.id}")
expect(poll_question).to have_content("Answer A, Answer B")
end
end

0 comments on commit e5dc702

Please sign in to comment.