From 8affed2ff0dad4f5eff7e3e3f22d0307055338ed Mon Sep 17 00:00:00 2001 From: Dushan Despotovic Date: Mon, 22 Aug 2022 09:35:18 +0100 Subject: [PATCH] fix specs --- ...nswers_summary_list_card_component_spec.rb | 8 ++-- spec/fixtures/forms/2021_2022.json | 37 ++++++++++++------- spec/models/form/subsection_spec.rb | 4 +- spec/models/form_handler_spec.rb | 2 +- spec/models/form_spec.rb | 2 +- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb index 741b4600a..9ccfebe51 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do context "when given a set of questions" do let(:user) { FactoryBot.build(:user) } - let(:case_log) { FactoryBot.build(:case_log, :completed) } + let(:case_log) { FactoryBot.build(:case_log, :completed, age2: 99) } let(:subsection_id) { "household_characteristics" } let(:subsection) { case_log.form.get_subsection(subsection_id) } let(:questions) { subsection.applicable_questions(case_log) } @@ -16,12 +16,12 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do it "applicable questions doesn't return questions that are hidden in check answers" do summary_list = described_class.new(questions:, case_log:, user:) expect(summary_list.applicable_questions.map(&:id).include?("retirement_value_check")).to eq(false) - end + end - it "has the correct answer label for a question" do + it "has the correct answer label for a question" do summary_list = described_class.new(questions:, case_log:, user:) sex1_question = questions[2] expect(summary_list.get_answer_label(sex1_question)).to eq("Female") - end + end end end diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 92b8b8e48..ea8b3ce40 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -168,20 +168,6 @@ "step": 1, "width": 2 }, - "retirement_value_check": { - "check_answer_label": "Retirement age soft validation", - "hidden_in_check_answers": true, - "header": "Are you sure this person is retired?", - "type": "interruption_screen", - "answer_options": { - "0": { - "value": "Yes" - }, - "1": { - "value": "No" - } - } - }, "sex2": { "check_answers_card_number": 2, "check_answer_label": "Person 2’s gender identity", @@ -204,6 +190,29 @@ } } }, + "retirement_value_check": { + "questions": { + "retirement_value_check": { + "check_answer_label": "Retirement age soft validation", + "hidden_in_check_answers": true, + "header": "Are you sure this person is retired?", + "type": "radio", + "answer_options": { + "0": { + "value": "Yes" + }, + "1": { + "value": "No" + } + } + } + }, + "depends_on": [ + { + "age2": { "operator": ">", "operand": 50 } + } + ] + }, "person_2_working_situation": { "header": "", "description": "", diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 1b876520a..95208b8e5 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -25,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do end it "has pages" do - expected_pages = %w[tenant_code_test person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode] + expected_pages = %w[tenant_code_test person_1_age person_1_gender person_1_working_situation household_number_of_members retirement_value_check person_2_working_situation propcode] expect(subsection.pages.map(&:id)).to eq(expected_pages) end it "has questions" do - expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 ecstat2 propcode] + expected_questions = %w[tenancycode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 retirement_value_check ecstat2 propcode] expect(subsection.questions.map(&:id)).to eq(expected_questions) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 2222d737e..94a3af2fe 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -17,7 +17,7 @@ RSpec.describe FormHandler do form_handler = described_class.instance form = form_handler.get_form(test_form_name) expect(form).to be_a(Form) - expect(form.pages.count).to eq(44) + expect(form.pages.count).to eq(45) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 291343cd9..4b6b66672 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -178,7 +178,7 @@ RSpec.describe Form, type: :model do describe "invalidated_page_questions" do let(:case_log) { FactoryBot.create(:case_log, :in_progress, needstype: 1) } - let(:expected_invalid) { %w[scheme_id condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } + let(:expected_invalid) { %w[scheme_id retirement_value_check condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } context "when dependencies are not met" do it "returns an array of question keys whose pages conditions are not met" do