diff --git a/app/models/form/question.rb b/app/models/form/question.rb index cfb1da4c3..4282e0f21 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -80,6 +80,7 @@ class Form::Question def completed?(case_log) # Special case as No is a valid answer but doesn't let you progress and use the service return false if id == "gdpr_acceptance" && case_log[id] == "No" + return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox" case_log[id].present? || !case_log.respond_to?(id.to_sym) end diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 3bd7892fc..e3166a4e1 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -58,7 +58,7 @@ class Form::Subsection end def answered_questions(case_log) - applicable_questions(case_log).select { |question| case_log[question.id].present? } + applicable_questions(case_log).select { |question| question.completed?(case_log) } end def unanswered_questions(case_log) diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 73a988b13..eb17f44de 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -423,7 +423,7 @@ "dependent_question": { "check_answer_label": "Dependent Question", "header": "Question to test page routing", - "type": "checkbox", + "type": "radio", "answer_options": { "0": "Option A", "1": "Option B" diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 2bb177a0c..532d3b59a 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -35,6 +35,17 @@ RSpec.describe Form::Subsection, type: :model do expect(subject.status(case_log)).to eq(:in_progress) end + it "has a completed status for completed subsection" do + subsection_definition = section_definition["subsections"]["household_needs"] + subject = Form::Subsection.new("household_needs", subsection_definition, section) + case_log.armedforces = "No" + case_log.illness = "No" + case_log.housingneeds_a = "Yes" + case_log.la = "York" + case_log.illness_type_1 = "Yes" + expect(subject.status(case_log)).to eq(:completed) + end + it "has status helpers" do expect(subject.is_incomplete?(case_log)).to be(true) expect(subject.is_started?(case_log)).to be(true) @@ -47,9 +58,16 @@ RSpec.describe Form::Subsection, type: :model do end it "has question helpers for the number of answered questions" do - expected_questions = %w[tenant_code age1] + subsection_definition = section_definition["subsections"]["household_needs"] + subject = Form::Subsection.new("household_needs", subsection_definition, section) + expected_questions = %w[armedforces illness accessibility_requirements la condition_effects] + case_log.armedforces = "No" + case_log.illness = "No" + case_log.housingneeds_a = "Yes" + case_log.la = "York" + case_log.illness_type_1 = "Yes" expect(subject.answered_questions(case_log).map(&:id)).to eq(expected_questions) - expect(subject.answered_questions_count(case_log)).to eq(2) + expect(subject.answered_questions_count(case_log)).to eq(5) end it "has a question helpers for the unanswered questions" do