Browse Source

check answers changes and other fixes

pull/273/head
MadeTech Dushan 3 years ago
parent
commit
cf2e20d12a
  1. 26
      app/helpers/check_answers_helper.rb
  2. 4
      app/models/form.rb
  3. 3
      app/models/form/question.rb
  4. 3
      app/views/form/_check_answers_table.html.erb
  5. 3
      spec/fixtures/complete_case_log.json

26
app/helpers/check_answers_helper.rb

@ -12,12 +12,28 @@ module CheckAnswersHelper
end end
def get_answer_label(question, case_log) 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) 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? if answer.present?
[question.prefix, answer, question.suffix].join("") [question.prefix, answer, question.suffix].join("")
else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
else else
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".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
"<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end end
end end
end end

4
app/models/form.rb

@ -24,6 +24,10 @@ class Form
pages.find { |p| p.id == id.to_s.underscore } pages.find { |p| p.id == id.to_s.underscore }
end end
def get_question(id)
questions.find { |q| q.id == id.to_s.underscore }
end
def subsection_for_page(page) def subsection_for_page(page)
subsections.find { |s| s.pages.find { |p| p.id == page.id } } subsections.find { |s| s.pages.find { |p| p.id == page.id } }
end end

3
app/models/form/question.rb

@ -75,6 +75,9 @@ class Form::Question
else else
case_log[id].blank? ? "Answer" : "Change" case_log[id].blank? ? "Answer" : "Change"
end end
if id == "earnings"
link_type = case_log[id].blank? || case_log["incfreq"].blank? ? "Answer" : "Change"
end
"#{link_type}<span class=\"govuk-visually-hidden\"> #{check_answer_label.to_s.downcase}</span>".html_safe "#{link_type}<span class=\"govuk-visually-hidden\"> #{check_answer_label.to_s.downcase}</span>".html_safe
end end

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

@ -1,3 +1,5 @@
<% unless question.id == "incfreq" %>
<div class="govuk-summary-list__row"> <div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key"> <dt class="govuk-summary-list__key">
<%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %> <%= 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 %> <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %>
</dd> </dd>
</div> </div>
<% end %>

3
spec/fixtures/complete_case_log.json vendored

@ -74,8 +74,9 @@
"mrcyear": 2020, "mrcyear": 2020,
"offered": 2, "offered": 2,
"wchair": "Yes", "wchair": "Yes",
"net_income_known": "Weekly", "net_income_known": "Yes",
"earnings": 150, "earnings": 150,
"incfreq": "Weekly",
"benefits": "Some", "benefits": "Some",
"hb": "Universal Credit with housing element (excluding housing benefit)", "hb": "Universal Credit with housing element (excluding housing benefit)",
"period": "Every 2 weeks", "period": "Every 2 weeks",

Loading…
Cancel
Save