Browse Source

fix pushing to wrong branch

pull/833/head
Ted-U 3 years ago
parent
commit
c15fc54f8d
  1. 25
      app/components/check_answers_summary_list_card_component.html.erb
  2. 18
      app/components/check_answers_summary_list_card_component.rb
  3. 4
      app/helpers/check_answers_helper.rb
  4. 3
      app/models/form/question.rb
  5. 10
      app/views/form/check_answers.html.erb
  6. 5
      app/views/form/review.html.erb
  7. 10
      config/forms/2021_2022.json
  8. 16
      spec/components/check_answers_summary_list_card_component_spec.rb

25
app/components/check_answers_summary_list_card_component.html.erb

@ -0,0 +1,25 @@
<div class="check-answers-summary-list">
<%= govuk_summary_list do |summary_list| %>
<% applicable_questions.each do |question| %>
<% summary_list.row do |row| %>
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %>
<% row.value do %>
<span class="govuk-!-margin-right-4"><%= get_answer_label(question) %></span>
<% extra_value = question.get_extra_check_answer_value(case_log) %>
<% if extra_value %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span>
<% end %>
<br>
<% question.get_inferred_answers(case_log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
<% end %>
<% row.action(
text: question.action_text(case_log),
href: question.action_href(case_log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>
<% end %>
<% end %>
</div>

18
app/components/check_answers_summary_list_card_component.rb

@ -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

4
app/helpers/check_answers_helper.rb

@ -41,8 +41,4 @@ private
def total_applicable_questions(subsection, case_log, current_user)
subsection.applicable_questions(case_log).reject { |q| q.hidden_in_check_answers?(case_log, current_user) }
end
def get_answer_label(question, case_log)
question.answer_label(case_log).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end

3
app/models/form/question.rb

@ -3,7 +3,7 @@ class Form::Question
:type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
:guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived
:guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, :check_answers_card_number
module GuidancePosition
TOP = 1
@ -37,6 +37,7 @@ class Form::Question
@suffix = hsh["suffix"]
@requires_js = hsh["requires_js"]
@fields_added = hsh["fields_added"]
@check_answers_card_number = hsh["check_answers_card_number"]
end
end

10
app/views/form/check_answers.html.erb

@ -17,10 +17,12 @@
<% end %>
<%= display_answered_questions_summary(subsection, @case_log, current_user) %>
<%= render partial: "form/check_answers_summary_list", locals: {
subsection:,
case_log: @case_log,
} %>
<% subsection.applicable_questions(@case_log).group_by(&:check_answers_card_number).values.each do |question_group| %>
<%= render CheckAnswersSummaryListCardComponent.new(questions: question_group, case_log: @case_log, user: current_user) %>
<br>
<br>
<br>
<% end %>
<%= form_with model: @case_log, method: "get" do |f| %>
<%= f.govuk_submit "Save and return to log" do %>

5
app/views/form/review.html.erb

@ -21,10 +21,7 @@
<h3 class="x-govuk-summary-card__title"><%= subsection.label %></h3>
</div>
<div class="x-govuk-summary-card__body">
<%= render partial: "form/check_answers_summary_list", locals: {
subsection:,
case_log: @case_log,
} %>
<%= render CheckAnswersSummaryListCardComponent.new(questions: subsection.applicable_questions(@case_log), case_log: @case_log, user: current_user) %>
</div>
</div>
<% end %>

10
config/forms/2021_2022.json

@ -1063,6 +1063,7 @@
"header": "",
"guidance_partial": "privacy_notice",
"check_answer_label": "Tenant has seen the privacy notice",
"check_answers_card_number": 0,
"type": "checkbox",
"answer_options": {
"declaration": {
@ -1077,6 +1078,7 @@
"description": "",
"questions": {
"hhmemb": {
"check_answers_card_number": 0,
"check_answer_label": "Number of household members",
"header": "How many people live in the household for this letting?",
"hint_text": "You can provide details for a maximum of 8 people.",
@ -1176,6 +1178,7 @@
"description": "",
"questions": {
"age1_known": {
"check_answers_card_number": 1,
"header": "Do you know the lead tenant’s age?",
"hint_text": "The ’lead’ or ’main’ tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@ -1307,6 +1310,7 @@
"questions": {
"sex1": {
"check_answer_label": "Lead tenant’s gender identity",
"check_answers_card_number": 1,
"header": "Which of these best describes the lead tenant’s gender identity?",
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@ -1419,6 +1423,7 @@
"questions": {
"ethnic_group": {
"check_answer_label": "Lead tenant’s ethnic group",
"check_answers_card_number": 0,
"header": "What is the lead tenant’s ethnic group?",
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
@ -1652,6 +1657,7 @@
"ecstat1": {
"check_answer_label": "Lead tenant’s working situation",
"header": "Which of these best describes the lead tenant’s working situation?",
"check_answers_card_number": 0,
"hint_text": "The lead tenant is the person in the household who does the most paid work. If several people do the same paid work, the lead tenant is whoever is the oldest.",
"type": "radio",
"answer_options": {
@ -1789,6 +1795,7 @@
"questions": {
"details_known_2": {
"check_answer_label": "Details known for person 2",
"check_answers_card_number": 1,
"header": "Do you know details for person 2?",
"hint_text": "You must provide details for everyone in the household if you know them.",
"type": "radio",
@ -1832,6 +1839,7 @@
"questions": {
"relat2": {
"check_answer_label": "Person 2’s relationship to the lead tenant",
"check_answers_card_number": 1,
"header": "What is person 2’s relationship to the lead tenant?",
"hint_text": "",
"type": "radio",
@ -2005,6 +2013,7 @@
"sex2": {
"check_answer_label": "Person 2’s gender identity",
"header": "Which of these best describes person 2’s gender identity?",
"check_answers_card_number": 1,
"hint_text": "",
"type": "radio",
"answer_options": {
@ -2126,6 +2135,7 @@
"questions": {
"ecstat2": {
"check_answer_label": "Person 2’s working situation",
"check_answers_card_number": 1,
"header": "Which of these best describes person 2’s working situation?",
"hint_text": "",
"type": "radio",

16
spec/components/check_answers_summary_list_card_component_spec.rb

@ -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…
Cancel
Save