From 4f3d39b94de945f771c881b5fe53c4fad3b43f54 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 8 Feb 2022 16:28:31 +0000 Subject: [PATCH] Add test --- spec/features/form/check_answers_page_spec.rb | 4 ++-- spec/fixtures/forms/2021_2022.json | 9 ++++++++ spec/helpers/check_answers_helper_spec.rb | 3 ++- spec/models/form/subsection_spec.rb | 22 ++++++++++++++----- spec/models/form_handler_spec.rb | 2 +- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index cadc0ec3e..e2250684f 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -38,7 +38,7 @@ RSpec.describe "Form Check Answers Page" do end context "when the user needs to check their answers for a subsection" do - let(:last_question_for_subsection) { "household-number-of-other-members" } + let(:last_question_for_subsection) { "propcode" } it "can be visited by URL" do visit("/logs/#{id}/#{subsection}/check-answers") @@ -46,7 +46,7 @@ RSpec.describe "Form Check Answers Page" do end it "redirects to the check answers page when answering the last question and clicking save and continue" do - fill_in_number_question(id, "other_hhmemb", 0, last_question_for_subsection) + fill_in_number_question(id, "propcode", 0, last_question_for_subsection) expect(page).to have_current_path("/logs/#{id}/#{subsection}/check-answers") end diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index e675ccea5..1498880fc 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -104,6 +104,15 @@ } } } + }, + "propcode": { + "questions": { + "propcode": { + "check_answer_label": "", + "header": "property reference?", + "type": "text" + } + } } } }, diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 7778ed0d9..0d1a94d6d 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -9,7 +9,7 @@ RSpec.describe CheckAnswersHelper do context "when a section hasn't been completed yet" do it "returns that you have unanswered questions" do expect(display_answered_questions_summary(subsection, case_log)) - .to match(/You have answered 2 of 4 questions./) + .to match(/You have answered 2 of 5 questions./) end end @@ -17,6 +17,7 @@ RSpec.describe CheckAnswersHelper do it "returns that you have answered all the questions" do case_log.sex1 = "F" case_log.other_hhmemb = 0 + case_log.propcode = "123" expect(display_answered_questions_summary(subsection, case_log)) .to match(/You answered all the questions./) expect(display_answered_questions_summary(subsection, case_log)) diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 6bb2a36e2..d086356f4 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -1,4 +1,5 @@ require "rails_helper" +require_relative "../../request_helper" RSpec.describe Form::Subsection, type: :model do subject(:sub_section) { described_class.new(subsection_id, subsection_definition, section) } @@ -11,6 +12,10 @@ RSpec.describe Form::Subsection, type: :model do let(:subsection_id) { "household_characteristics" } let(:subsection_definition) { section_definition["subsections"][subsection_id] } + before do + RequestHelper.stub_http_requests + end + it "has an id" do expect(sub_section.id).to eq(subsection_id) end @@ -20,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do end it "has pages" do - expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members] + expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members propcode] expect(sub_section.pages.map(&:id)).to eq(expected_pages) end it "has questions" do - expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2] + expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2 propcode] expect(sub_section.questions.map(&:id)).to eq(expected_questions) end @@ -53,9 +58,9 @@ RSpec.describe Form::Subsection, type: :model do end it "has question helpers for the number of applicable questions" do - expected_questions = %w[tenant_code age1 sex1 other_hhmemb] + expected_questions = %w[tenant_code age1 sex1 other_hhmemb propcode] expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions) - expect(sub_section.applicable_questions_count(case_log)).to eq(4) + expect(sub_section.applicable_questions_count(case_log)).to eq(5) end it "has question helpers for the number of answered questions" do @@ -72,18 +77,25 @@ RSpec.describe Form::Subsection, type: :model do end it "has a question helpers for the unanswered questions" do - expected_questions = %w[sex1 other_hhmemb] + expected_questions = %w[sex1 other_hhmemb propcode] expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) end end context "with a completed case log" do let(:case_log) { FactoryBot.build(:case_log, :completed) } + let(:case_log_too) { FactoryBot.build(:case_log, :in_progress) } it "has a status" do expect(sub_section.status(case_log)).to eq(:completed) end + it "has a status when optional fields are not filled" do + case_log.update!({ propcode: nil }) + case_log.reload + expect(sub_section.status(case_log)).to eq(:completed) + end + it "has status helpers" do expect(sub_section.is_incomplete?(case_log)).to be(false) expect(sub_section.is_started?(case_log)).to be(true) diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 932ebdc75..94a6e9f9f 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(28) + expect(form.pages.count).to eq(29) end end