diff --git a/app/components/polls/questions/question_component.html.erb b/app/components/polls/questions/question_component.html.erb index 3cd99a1b4..ac675a889 100644 --- a/app/components/polls/questions/question_component.html.erb +++ b/app/components/polls/questions/question_component.html.erb @@ -12,4 +12,11 @@
<%= render Polls::Questions::AnswersComponent.new(question) %>
+ + <% if question.answers_with_read_more? %> +
+

<%= t("poll_questions.read_more_about") %>

+

<%= answers_read_more_links %>

+
+ <% end %> diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb index d1a4edf27..09b8cacd9 100644 --- a/app/components/polls/questions/question_component.rb +++ b/app/components/polls/questions/question_component.rb @@ -4,4 +4,10 @@ class Polls::Questions::QuestionComponent < ApplicationComponent def initialize(question:) @question = question end + + def answers_read_more_links + safe_join(question.answers_with_read_more.map do |answer| + link_to answer.title, "#answer_#{answer.id}" + end, ", ") + end end diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index afc277ef4..9d7c80499 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -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" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 382b302e6..c69b4259e 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -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" diff --git a/spec/components/polls/questions/question_component_spec.rb b/spec/components/polls/questions/question_component_spec.rb new file mode 100644 index 000000000..4ca884af5 --- /dev/null +++ b/spec/components/polls/questions/question_component_spec.rb @@ -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