Show question title before answers additional information

This commit is contained in:
decabeza
2022-09-01 12:29:26 +02:00
committed by Senén Rodero Rodríguez
parent 815a526d78
commit b92b38f48f
6 changed files with 81 additions and 77 deletions

View File

@@ -1,60 +1,63 @@
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>"> <h2><%= question.title %></h2>
<h3><%= answer.title %></h3> <% question.question_answers.each do |answer| %>
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>">
<h3><%= answer.title %></h3>
<% if answer.images.any? %> <% if answer.images.any? %>
<%= render "polls/gallery", answer: answer %> <%= render "polls/gallery", answer: answer %>
<% end %> <% end %>
<% if answer.description.present? %> <% if answer.description.present? %>
<div class="margin-top"> <div class="margin-top">
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short"> <div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short">
<%= wysiwyg(answer.description) %> <%= wysiwyg(answer.description) %>
</div>
<div class="read-more">
<button type="button" id="read_more_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide">
<%= t("polls.show.read_more", answer: answer.title) %>
</button>
<button type="button" id="read_less_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>"
data-toggler="hide"
class="hide">
<%= t("polls.show.read_less", answer: answer.title) %>
</button>
</div>
</div> </div>
<div class="read-more"> <% end %>
<button type="button" id="read_more_<%= answer.id %>"
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" <% if answer.documents.present? %>
data-toggler="hide"> <div class="document-link">
<%= t("polls.show.read_more", answer: answer.title) %> <p>
</button> <span class="icon-document"></span>&nbsp;
<button type="button" id="read_less_<%= answer.id %>" <strong><%= t("polls.show.documents") %></strong>
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" </p>
data-toggler="hide"
class="hide"> <% answer.documents.each do |document| %>
<%= t("polls.show.read_less", answer: answer.title) %> <%= link_to document.title,
</button> document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div> </div>
</div> <% end %>
<% end %>
<% if answer.documents.present? %> <% if answer.videos.present? %>
<div class="document-link"> <div class="video-link">
<p> <p>
<span class="icon-document"></span>&nbsp; <span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong> <strong><%= t("polls.show.videos") %></strong>
</p> </p>
<% answer.documents.each do |document| %> <% answer.videos.each do |video| %>
<%= link_to document.title, <%= link_to video.title,
document.attachment, video.url,
target: "_blank", target: "_blank",
rel: "nofollow" %><br> rel: "nofollow" %><br>
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
</div>
<% if answer.videos.present? %> <% end %>
<div class="video-link">
<p>
<span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.videos") %></strong>
</p>
<% answer.videos.each do |video| %>
<%= link_to video.title,
video.url,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div>
<% end %>
</div>

View File

@@ -1,9 +1,9 @@
class Polls::Questions::ReadMoreAnswerComponent < ApplicationComponent class Polls::Questions::ReadMoreAnswerComponent < ApplicationComponent
with_collection_parameter :answer with_collection_parameter :question
attr_reader :answer attr_reader :question
delegate :wysiwyg, to: :helpers delegate :wysiwyg, to: :helpers
def initialize(answer:) def initialize(question:)
@answer = answer @question = question
end end
end end

View File

@@ -19,8 +19,6 @@ class PollsController < ApplicationController
def show def show
@questions = @poll.questions.for_render.sort_for_list @questions = @poll.questions.for_render.sort_for_list
@poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
.with_content.order(:given_order)
@commentable = @poll @commentable = @poll
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order) @comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
end end

View File

@@ -46,7 +46,7 @@
<div id="poll_more_info_answers" class="expanded poll-more-info-answers"> <div id="poll_more_info_answers" class="expanded poll-more-info-answers">
<div class="row padding"> <div class="row padding">
<%= render Polls::Questions::ReadMoreAnswerComponent.with_collection(@poll_questions_answers) %> <%= render Polls::Questions::ReadMoreAnswerComponent.with_collection(@questions) %>
</div> </div>
</div> </div>

View File

@@ -3,13 +3,28 @@ require "rails_helper"
describe Polls::Questions::ReadMoreAnswerComponent do describe Polls::Questions::ReadMoreAnswerComponent do
include Rails.application.routes.url_helpers include Rails.application.routes.url_helpers
let(:poll) { create(:poll) } let(:poll) { create(:poll) }
let(:question) { create(:poll_question, poll: poll) } let(:question) { create(:poll_question, poll: poll, title: "Question title?") }
let(:answer) { create(:poll_question_answer, question: question) } let(:answer) { create(:poll_question_answer, question: question) }
it "renders question title" do
render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_content "Question title?"
end
it "renders answers in the given order" do
create(:poll_question_answer, title: "Answer A", question: question, given_order: 2)
create(:poll_question_answer, title: "Answer B", question: question, given_order: 1)
render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect("Answer B").to appear_before("Answer A")
end
it "renders answers with videos" do it "renders answers with videos" do
create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123") create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123")
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123") expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123")
end end
@@ -17,7 +32,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with images" do it "renders answers with images" do
create(:image, imageable: answer, title: "The yes movement") create(:image, imageable: answer, title: "The yes movement")
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_css "img[alt='The yes movement']" expect(page).to have_css "img[alt='The yes movement']"
end end
@@ -25,7 +40,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with documents" do it "renders answers with documents" do
create(:document, documentable: answer, title: "The yes movement") create(:document, documentable: answer, title: "The yes movement")
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) render_inline Polls::Questions::ReadMoreAnswerComponent.new(question: question)
expect(page).to have_link("The yes movement") expect(page).to have_link("The yes movement")
end end

View File

@@ -183,18 +183,6 @@ describe "Polls" do
expect("Second question").to appear_before("Third question") expect("Second question").to appear_before("Third question")
end end
scenario "More info answers appear in the given order" do
question = create(:poll_question, poll: poll)
answer1 = create(:poll_question_answer, title: "First", question: question, given_order: 2)
answer2 = create(:poll_question_answer, title: "Second", question: question, given_order: 1)
visit poll_path(poll)
within("div.poll-more-info-answers") do
expect(answer2.title).to appear_before(answer1.title)
end
end
scenario "Buttons to slide through images work back and forth" do scenario "Buttons to slide through images work back and forth" do
question = create(:poll_question, :yes_no, poll: poll) question = create(:poll_question, :yes_no, poll: poll)
create(:image, imageable: question.question_answers.last, title: "The no movement") create(:image, imageable: question.question_answers.last, title: "The no movement")