From cf2e20d12a690af7cf2caad3d949a7c0cbf088c6 Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Fri, 4 Feb 2022 10:42:54 +0000 Subject: [PATCH] check answers changes and other fixes --- app/helpers/check_answers_helper.rb | 26 ++++++++++++++++---- app/models/form.rb | 4 +++ app/models/form/question.rb | 3 +++ app/views/form/_check_answers_table.html.erb | 3 +++ spec/fixtures/complete_case_log.json | 3 ++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 6797b00af..b4b74c2d3 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -12,12 +12,28 @@ module CheckAnswersHelper end def get_answer_label(question, case_log) - answer = question.prefix == "£" ? ActionController::Base.helpers.number_to_currency(question.answer_label(case_log), delimiter: ",", format: "%n") : question.answer_label(case_log) - - if answer.present? - [question.prefix, answer, question.suffix].join("") + unless question.id == "earnings" + answer = question.prefix == "£" ? ActionController::Base.helpers.number_to_currency(question.answer_label(case_log), delimiter: ",", format: "%n") : question.answer_label(case_log) + if answer.present? + [question.prefix, answer, question.suffix].join("") + else + "You didn’t answer this question".html_safe + end else - "You didn’t answer this question".html_safe + linked_question = case_log.form.get_question("incfreq") + if(question.answer_label(case_log).present? && linked_question.answer_label(case_log).present?) + suffix = case linked_question.answer_label(case_log) + when "Weekly" + " every week" + when "Monthly" + " every month" + when "Yearly" + " every year" + end + [question.prefix, question.answer_label(case_log), suffix].join("") + else + "You didn’t answer this question".html_safe + end end end end diff --git a/app/models/form.rb b/app/models/form.rb index f00507f50..d21728def 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -24,6 +24,10 @@ class Form pages.find { |p| p.id == id.to_s.underscore } end + def get_question(id) + questions.find { |q| q.id == id.to_s.underscore } + end + def subsection_for_page(page) subsections.find { |s| s.pages.find { |p| p.id == page.id } } end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 3510c8c38..d6dd902ea 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -75,6 +75,9 @@ class Form::Question else case_log[id].blank? ? "Answer" : "Change" end + if id == "earnings" + link_type = case_log[id].blank? || case_log["incfreq"].blank? ? "Answer" : "Change" + end "#{link_type} #{check_answer_label.to_s.downcase}".html_safe end diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb index 0ba792f1f..be019eefb 100644 --- a/app/views/form/_check_answers_table.html.erb +++ b/app/views/form/_check_answers_table.html.erb @@ -1,3 +1,5 @@ + +<% unless question.id == "incfreq" %>
<%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %> @@ -12,3 +14,4 @@ <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %>
+<% end %> \ No newline at end of file diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index d3b9396bf..268283c2a 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -74,8 +74,9 @@ "mrcyear": 2020, "offered": 2, "wchair": "Yes", - "net_income_known": "Weekly", + "net_income_known": "Yes", "earnings": 150, + "incfreq": "Weekly", "benefits": "Some", "hb": "Universal Credit with housing element (excluding housing benefit)", "period": "Every 2 weeks",