Browse Source

Extract partial answers table, rename variable in helper method

pull/25/head
Kat 3 years ago committed by MadeTech Dushan
parent
commit
e086f1c131
  1. 8
      app/controllers/case_logs_controller.rb
  2. 4
      app/helpers/check_answers_helper.rb
  3. 13
      app/views/form/_check_answers_table.html.erb
  4. 17
      app/views/form/check_answers.html.erb
  5. 2
      spec/features/case_log_spec.rb

8
app/controllers/case_logs_controller.rb

@ -28,13 +28,13 @@ class CaseLogsController < ApplicationController
answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) }
@case_log.update!(answers_for_page)
next_page = form.next_page(previous_page)
redirect_path = if next_page == :check_answers
redirect_path = if next_page == :check_answers
subsection = form.subsection_for_page(previous_page)
"case_log_#{subsection}_check_answers_path"
else
else
"case_log_#{next_page}_path"
end
redirect_to(send(redirect_path, @case_log))
end
@ -44,7 +44,7 @@ class CaseLogsController < ApplicationController
current_url = request.env['PATH_INFO']
subsection = current_url.split('/')[-2]
subsection_pages = form.pages_for_subsection(subsection)
render "form/check_answers", locals: { case_log_id: @case_log.id, case_log: @case_log, subsection_pages: subsection_pages }
render "form/check_answers", locals: { case_log: @case_log, subsection_pages: subsection_pages }
end
form = Form.new(2021, 2022)

4
app/helpers/check_answers_helper.rb

@ -13,8 +13,8 @@ module CheckAnswersHelper
link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe
end
def create_next_missing_question_link(case_log_id, subsections, case_log)
empty_question = subsections.keys.find{|x| case_log[x].blank? }
def create_next_missing_question_link(case_log_id, subsection_pages, case_log)
empty_question = subsection_pages.keys.find{|x| case_log[x].blank? }
url = "/case_logs/#{case_log_id}/#{empty_question}"
link_to('Answer the missing questions', url, class: "govuk-link").html_safe

13
app/views/form/_check_answers_table.html.erb

@ -0,0 +1,13 @@
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= page_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[page] %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(case_log[page], case_log["id"], page)%>
</dd>
</div>
</dl>

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

@ -1,24 +1,11 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
<h1 class="govuk-heading-l">Check the answers you gave for household characteristics</h1>
<p>You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions</p>
<%= create_next_missing_question_link(case_log_id, subsection_pages, case_log) %>
<%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= page_info["check_answer_label"].to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= case_log[page] %>
</dd>
<dd class="govuk-summary-list__actions">
<%= create_update_answer_link(case_log[page], case_log_id, page)%>
</dd>
</div>
</dl>
<%= render partial: 'form/check_answers_table', locals: { page: page, page_info: page_info, case_log: case_log } %>
<% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>

2
spec/features/case_log_spec.rb

@ -59,7 +59,7 @@ RSpec.describe "Test Features" do
when "text"
fill_in(question.to_s, with: answer)
when "radio"
choose("#{question.to_s.tr('_', '-')}-#{answer.parameterize}-field")
choose("#{question.to_s.dasherize}-#{answer.parameterize}-field")
else
fill_in(question.to_s, with: answer)
end

Loading…
Cancel
Save