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. 2
      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

2
app/controllers/case_logs_controller.rb

@ -44,7 +44,7 @@ class CaseLogsController < ApplicationController
current_url = request.env['PATH_INFO'] current_url = request.env['PATH_INFO']
subsection = current_url.split('/')[-2] subsection = current_url.split('/')[-2]
subsection_pages = form.pages_for_subsection(subsection) 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 end
form = Form.new(2021, 2022) 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 link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe
end end
def create_next_missing_question_link(case_log_id, subsections, case_log) def create_next_missing_question_link(case_log_id, subsection_pages, case_log)
empty_question = subsections.keys.find{|x| case_log[x].blank? } empty_question = subsection_pages.keys.find{|x| case_log[x].blank? }
url = "/case_logs/#{case_log_id}/#{empty_question}" url = "/case_logs/#{case_log_id}/#{empty_question}"
link_to('Answer the missing questions', url, class: "govuk-link").html_safe 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 %> <%= turbo_frame_tag "case_log_form", target: "_top" do %>
<h1 class="govuk-heading-l">Check the answers you gave for household characteristics</h1> <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> <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| %> <% subsection_pages.each do |page, page_info| %>
<dl class="govuk-summary-list govuk-!-margin-bottom-9"> <%= render partial: 'form/check_answers_table', locals: { page: page, page_info: page_info, case_log: case_log } %>
<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>
<% end %> <% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<% end %> <% end %>
<% end %> <% end %>

2
spec/features/case_log_spec.rb

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

Loading…
Cancel
Save