Browse Source

WIP - fix failing test

pull/190/head
MadeTech Dushan 4 years ago committed by Kat
parent
commit
4dddbe3680
  1. 8
      app/models/form/question.rb
  2. 6
      app/models/form/subsection.rb
  3. 6
      config/forms/2021_2022.json

8
app/models/form/question.rb

@ -2,7 +2,7 @@ class Form::Question
attr_accessor :id, :header, :hint_text, :description, :questions, attr_accessor :id, :header, :hint_text, :description, :questions,
:type, :min, :max, :step, :width, :fields_to_add, :result_field, :type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label, :conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value
def initialize(id, hsh, page) def initialize(id, hsh, page)
@id = id @id = id
@ -20,6 +20,7 @@ class Form::Question
@answer_options = hsh["answer_options"] @answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"] @conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"] @inferred_answers = hsh["inferred_answers"]
@inferred_check_answers_value = hsh["inferred_check_answers_value"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"] @hidden_in_check_answers = hsh["hidden_in_check_answers"]
@page = page @page = page
end end
@ -54,6 +55,11 @@ class Form::Question
hidden_in_check_answers hidden_in_check_answers
end end
def has_inferred_check_answers_value?(case_log)
return inferred_check_answers_value["condition"].values[0] == case_log[inferred_check_answers_value["condition"].keys[0]] if inferred_check_answers_value.present?
false
end
def update_answer_link_name(case_log) def update_answer_link_name(case_log)
if type == "checkbox" if type == "checkbox"
answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer" answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer"

6
app/models/form/subsection.rb

@ -52,7 +52,7 @@ class Form::Subsection
end end
def applicable_questions(case_log) def applicable_questions(case_log)
questions.select { |q| q.page.routed_to?(case_log) && q.enabled?(case_log) && !q.hidden_in_check_answers? } questions.select { |q| displayed_to_user?(case_log, q) || q.has_inferred_check_answers_value?(case_log) }
end end
def answered_questions(case_log) def answered_questions(case_log)
@ -62,4 +62,8 @@ class Form::Subsection
def unanswered_questions(case_log) def unanswered_questions(case_log)
applicable_questions(case_log) - answered_questions(case_log) applicable_questions(case_log) - answered_questions(case_log)
end end
def displayed_to_user?(case_log, q)
q.page.routed_to?(case_log) && q.enabled?(case_log) && !q.hidden_in_check_answers?
end
end end

6
config/forms/2021_2022.json

@ -1153,7 +1153,11 @@
"hint_text": "", "hint_text": "",
"type": "text", "type": "text",
"width": 5, "width": 5,
"inferred_answers": { "la": { "is_la_inferred": true } } "inferred_answers": { "la": { "is_la_inferred": true } },
"inferred_check_answers_value": {
"condition": { "postcode_known": "No" },
"value": "Not known"
}
} }
} }
}, },

Loading…
Cancel
Save