9 changed files with 57 additions and 19 deletions
@ -1,23 +1,25 @@ |
|||||||
|
<div class="check-answers-summary-list"> |
||||||
<%= govuk_summary_list do |summary_list| %> |
<%= govuk_summary_list do |summary_list| %> |
||||||
<% total_applicable_questions(subsection, @case_log, current_user).each do |question| %> |
<% applicable_questions.each do |question| %> |
||||||
<% summary_list.row do |row| %> |
<% summary_list.row do |row| %> |
||||||
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> |
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> |
||||||
<% row.value do %> |
<% row.value do %> |
||||||
<span class="govuk-!-margin-right-4"><%= get_answer_label(question, @case_log) %></span> |
<span class="govuk-!-margin-right-4"><%= get_answer_label(question) %></span> |
||||||
<% extra_value = question.get_extra_check_answer_value(@case_log) %> |
<% extra_value = question.get_extra_check_answer_value(case_log) %> |
||||||
<% if extra_value %> |
<% if extra_value %> |
||||||
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span> |
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span> |
||||||
<% end %> |
<% end %> |
||||||
<br> |
<br> |
||||||
<% question.get_inferred_answers(@case_log).each do |inferred_answer| %> |
<% question.get_inferred_answers(case_log).each do |inferred_answer| %> |
||||||
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> |
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
<% row.action( |
<% row.action( |
||||||
text: question.action_text(@case_log), |
text: question.action_text(case_log), |
||||||
href: question.action_href(@case_log, question.page.id), |
href: question.action_href(case_log, question.page.id), |
||||||
visually_hidden_text: question.check_answer_label.to_s.downcase, |
visually_hidden_text: question.check_answer_label.to_s.downcase, |
||||||
) %> |
) %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
<% end %> |
<% end %> |
||||||
|
</div> |
@ -0,0 +1,18 @@ |
|||||||
|
class CheckAnswersSummaryListCardComponent < ViewComponent::Base |
||||||
|
attr_reader :questions, :case_log, :user |
||||||
|
|
||||||
|
def initialize(questions:, case_log:, user:) |
||||||
|
@questions = questions |
||||||
|
@case_log = case_log |
||||||
|
@user = user |
||||||
|
super |
||||||
|
end |
||||||
|
|
||||||
|
def applicable_questions |
||||||
|
questions.reject { |q| q.hidden_in_check_answers?(case_log, user) } |
||||||
|
end |
||||||
|
|
||||||
|
def get_answer_label(question) |
||||||
|
question.answer_label(case_log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,16 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do |
||||||
|
context "when given a set of questions" do |
||||||
|
let(:user) { FactoryBot.build(:user) } |
||||||
|
let(:case_log) { FactoryBot.build(:case_log, :completed) } |
||||||
|
let(:subsection_id) { "household_characteristics" } |
||||||
|
let(:subsection) { case_log.form.get_subsection(subsection_id) } |
||||||
|
let(:questions) { subsection.applicable_questions(case_log) } |
||||||
|
|
||||||
|
it "renders a summary list card for the answers to those questions" do |
||||||
|
result = render_inline(described_class.new(questions:, case_log:, user:)) |
||||||
|
expect(result).to have_content(questions.first.answer_label(case_log)) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue