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 %>">
<h3><%= answer.title %></h3>
<h2><%= question.title %></h2>
<% 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? %>
<%= render "polls/gallery", answer: answer %>
<% end %>
<% if answer.images.any? %>
<%= render "polls/gallery", answer: answer %>
<% end %>
<% if answer.description.present? %>
<div class="margin-top">
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short">
<%= wysiwyg(answer.description) %>
<% if answer.description.present? %>
<div class="margin-top">
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short">
<%= 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 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>
<% end %>
<% if answer.documents.present? %>
<div class="document-link">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong>
</p>
<% answer.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div>
</div>
<% end %>
<% end %>
<% if answer.documents.present? %>
<div class="document-link">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t("polls.show.documents") %></strong>
</p>
<% if answer.videos.present? %>
<div class="video-link">
<p>
<span class="icon-video"></span>&nbsp;
<strong><%= t("polls.show.videos") %></strong>
</p>
<% answer.documents.each do |document| %>
<%= link_to document.title,
document.attachment,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div>
<% end %>
<% if answer.videos.present? %>
<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>
<% answer.videos.each do |video| %>
<%= link_to video.title,
video.url,
target: "_blank",
rel: "nofollow" %><br>
<% end %>
</div>
<% end %>
</div>
<% end %>

View File

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

View File

@@ -19,8 +19,6 @@ class PollsController < ApplicationController
def show
@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
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
end

View File

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

View File

@@ -3,13 +3,28 @@ require "rails_helper"
describe Polls::Questions::ReadMoreAnswerComponent do
include Rails.application.routes.url_helpers
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) }
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
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")
end
@@ -17,7 +32,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with images" do
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']"
end
@@ -25,7 +40,7 @@ describe Polls::Questions::ReadMoreAnswerComponent do
it "renders answers with documents" do
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")
end

View File

@@ -183,18 +183,6 @@ describe "Polls" do
expect("Second question").to appear_before("Third question")
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
question = create(:poll_question, :yes_no, poll: poll)
create(:image, imageable: question.question_answers.last, title: "The no movement")