diff --git a/app/models/form/question.rb b/app/models/form/question.rb index a3b8ea21b..ca1eef09a 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -86,15 +86,18 @@ class Form::Question end end - def update_answer_link_name(case_log) - link_type = if has_inferred_check_answers_value?(case_log) - "Change" - elsif type == "checkbox" - answer_options.keys.any? { |key| value_is_yes?(case_log[key]) } ? "Change" : "Answer" - else - case_log[id].blank? ? "Answer" : "Change" - end - "#{link_type} #{check_answer_label.to_s.downcase}".html_safe + def action_text(case_log) + if has_inferred_check_answers_value?(case_log) + "Change" + elsif type == "checkbox" + answer_options.keys.any? { |key| value_is_yes?(case_log[key]) } ? "Change" : "Answer" + else + case_log[id].blank? ? "Answer" : "Change" + end + end + + def action_href(case_log, page_id) + "/logs/#{case_log.id}/#{page_id.to_s.dasherize}?referrer=check_answers" end def completed?(case_log) diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index c34c868e0..afae78056 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -1,14 +1,14 @@ -
-
- <%= question.check_answer_label.to_s.presence || question.header.to_s %> -
-
+<% summary_list.row do |row| %> + <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> + <% row.value do %> <%= get_answer_label(question, @case_log) %>
<% question.get_inferred_answers(@case_log).each do |inferred_answer| %> - <%= inferred_answer %>
+ <%= inferred_answer %> <% end %> -
-
- <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}?referrer=check_answers").html_safe %> -
-
+ <% 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 %> diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index d38cb1f0a..b7ac5c24b 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -19,11 +19,15 @@ <% end %> <%= display_answered_questions_summary(subsection, @case_log) %> -
+ <%= govuk_summary_list do |summary_list| %> <% subsection.applicable_questions(@case_log).each do |question| %> - <%= render partial: "form/check_answers_table", locals: { question:, case_log: @case_log } %> + <%= render partial: "form/check_answers_table", locals: { + summary_list:, + question:, + case_log: @case_log, + } %> <% end %> -
+ <% end %> <%= form_with model: @case_log, method: "get" do |f| %> <%= f.govuk_submit "Save and return to log" do %> diff --git a/app/views/form/review.html.erb b/app/views/form/review.html.erb index 2bfb8f9e3..0254e1022 100644 --- a/app/views/form/review.html.erb +++ b/app/views/form/review.html.erb @@ -21,14 +21,18 @@

<%= subsection.label %>

-
+ <%= govuk_summary_list do |summary_list| %> <% subsection.applicable_questions(@case_log).each do |question| %> - <%= render partial: 'form/check_answers_table', locals: { question: question, case_log: @case_log } %> + <%= render partial: 'form/check_answers_table', locals: { + summary_list:, + question:, + case_log: @case_log, + } %> <% end %> -
+ <% end %>
<% end %> <% end %> - \ No newline at end of file + diff --git a/spec/models/form/question_spec.rb b/spec/models/form/question_spec.rb index 094351870..5ae5790f9 100644 --- a/spec/models/form/question_spec.rb +++ b/spec/models/form/question_spec.rb @@ -226,9 +226,14 @@ RSpec.describe Form::Question, type: :model do end it "has an update answer link text helper" do - expect(question.update_answer_link_name(case_log)).to match(/Answer/) + expect(question.action_text(case_log)).to match(/Answer/) case_log["incfreq"] = 0 - expect(question.update_answer_link_name(case_log)).to match(/Change/) + expect(question.action_text(case_log)).to match(/Change/) + end + + it "has an update answer link href helper" do + case_log.id = 1 + expect(question.action_href(case_log, page.id)).to eq("/logs/1/net-income?referrer=check_answers") end context "when the question has an inferred answer" do @@ -239,7 +244,7 @@ RSpec.describe Form::Question, type: :model do let(:question_id) { "postcode_full" } it "displays 'change' in the check answers link text" do - expect(question.update_answer_link_name(case_log)).to match(/Change/) + expect(question.action_text(case_log)).to match(/Change/) end end