From 58403c67f01c2aa2c832a13c6fe701875161645d Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 16 Jun 2022 16:37:20 +0100 Subject: [PATCH] Fix remaining tests --- db/schema.rb | 4 ++-- spec/features/form/check_answers_page_spec.rb | 3 ++- spec/features/form/form_navigation_spec.rb | 4 ++-- spec/fixtures/forms/2021_2022.json | 16 ++++++++++++---- spec/fixtures/forms/2022_2023.json | 2 +- spec/helpers/tasklist_helper_spec.rb | 10 +++++----- spec/models/case_log_spec.rb | 4 ++-- spec/models/form/subsection_spec.rb | 2 +- spec/models/form_handler_spec.rb | 2 +- spec/models/form_spec.rb | 1 + spec/requests/case_logs_controller_spec.rb | 2 +- spec/requests/form_controller_spec.rb | 4 ++-- 12 files changed, 32 insertions(+), 22 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index d83363804..97a617b4d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -192,9 +192,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do t.integer "joint" t.bigint "created_by_id" t.integer "illness_type_0" - t.integer "retirement_value_check" t.integer "tshortfall_known" t.integer "shelteredaccom" + t.integer "retirement_value_check" t.integer "pregnancy_value_check" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" @@ -247,7 +247,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do create_table "logs_exports", force: :cascade do |t| t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } - t.datetime "started_at", null: false + t.datetime "started_at", precision: nil, null: false t.integer "base_number", default: 1, null: false t.integer "increment_number", default: 1, null: false t.boolean "empty_export", default: false, null: false diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index 77e5a8445..08daa57a0 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -194,6 +194,7 @@ RSpec.describe "Form Check Answers Page" do :in_progress, owning_organisation: user.organisation, managing_organisation: user.organisation, + needstype: 1, tenant_code: nil, age1: nil, layear: 2, @@ -226,7 +227,7 @@ RSpec.describe "Form Check Answers Page" do it "they can click a button to cycle around to the next incomplete section" do visit("/logs/#{cycle_sections_case_log.id}/declaration/check-answers") click_link("Save and go to next incomplete section") - expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code") + expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code-test") end end end diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb index adc7d6bce..ac6116e84 100644 --- a/spec/features/form/form_navigation_spec.rb +++ b/spec/features/form/form_navigation_spec.rb @@ -16,7 +16,7 @@ RSpec.describe "Form Navigation" do let(:id) { case_log.id } let(:question_answers) do { - tenant_code: { type: "text", answer: "BZ737", path: "tenant-code" }, + tenant_code: { type: "text", answer: "BZ737", path: "tenant-code-test" }, age1: { type: "numeric", answer: 25, path: "person-1-age" }, sex1: { type: "radio", answer: "Female", path: "person-1-gender" }, ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" }, @@ -61,7 +61,7 @@ RSpec.describe "Form Navigation" do end it "go back to tenant code page from tenant age page", js: true do - visit("/logs/#{id}/tenant-code") + visit("/logs/#{id}/tenant-code-test") click_button("Save and continue") visit("/logs/#{id}/person-1-age") click_link(text: "Back") diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 3b83b3499..93f3166d1 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -10,7 +10,7 @@ "household_characteristics": { "label": "Household characteristics", "pages": { - "tenant_code": { + "tenant_code_test": { "questions": { "tenant_code": { "check_answer_label": "Tenant code", @@ -27,7 +27,7 @@ { "housingneeds_a": null } - ] }, + ]}, "person_1_age": { "questions": { "age1": { @@ -39,7 +39,15 @@ "step": 1, "width": 2 } - } + }, + "depends_on": [ + { + "housingneeds_a": 1 + }, + { + "housingneeds_a": null + } + ] }, "person_1_gender": { "questions": { @@ -212,7 +220,7 @@ "header": "property reference?", "type": "text" } - } + } } } }, diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index bde22b8b7..9c8b60f89 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -9,7 +9,7 @@ "household_characteristics": { "label": "Household characteristics", "pages": { - "tenant_code": { + "tenant_code_test": { "questions": { "tenant_code": { "check_answer_label": "Tenant code", diff --git a/spec/helpers/tasklist_helper_spec.rb b/spec/helpers/tasklist_helper_spec.rb index 13079f615..5cc3b6fbb 100644 --- a/spec/helpers/tasklist_helper_spec.rb +++ b/spec/helpers/tasklist_helper_spec.rb @@ -6,12 +6,12 @@ RSpec.describe TasklistHelper do describe "get next incomplete section" do it "returns the first subsection name if it is not completed" do - expect(get_next_incomplete_section(case_log).id).to eq("household_characteristics") + expect(get_next_incomplete_section(case_log).id).to eq("setup") end it "returns the first subsection name if it is partially completed" do case_log["tenant_code"] = 123 - expect(get_next_incomplete_section(case_log).id).to eq("household_characteristics") + expect(get_next_incomplete_section(case_log).id).to eq("setup") end end @@ -29,7 +29,7 @@ RSpec.describe TasklistHelper do end it "returns the number of sections in progress" do - expect(get_subsections_count(case_log, :in_progress)).to eq(3) + expect(get_subsections_count(case_log, :in_progress)).to eq(4) end it "returns 0 for invalid state" do @@ -48,9 +48,9 @@ RSpec.describe TasklistHelper do expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/) end - it "when first question being not routed to returns the second question link" do + it "when first question being not routed to returns the next routed question link" do empty_case_log.housingneeds_a = "No" - expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-age/) + expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-gender/) end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 00e06959a..b6941220c 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1700,10 +1700,10 @@ RSpec.describe CaseLog do end context "when the question type does not have answer options" do - let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, tenant_code: "test") } + let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, age1: 19) } it "clears the answer" do - expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :tenant_code).from("test").to(nil) + expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :age1).from(19).to(nil) end end diff --git a/spec/models/form/subsection_spec.rb b/spec/models/form/subsection_spec.rb index 412f722e5..2b89df93e 100644 --- a/spec/models/form/subsection_spec.rb +++ b/spec/models/form/subsection_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Form::Subsection, type: :model do end it "has pages" do - expected_pages = %w[tenant_code 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 person_2_working_situation propcode] expect(subsection.pages.map(&:id)).to eq(expected_pages) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 6975db713..8632e387a 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(38) + expect(form.pages.count).to eq(41) end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 08cd1718e..eadaf2216 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -134,6 +134,7 @@ RSpec.describe Form, type: :model do case_log.relat2 = "P" case_log.sex2 = "F" case_log.ecstat2 = 1 + case_log.needstype = 1 end it "returns the first page of the next incomplete subsection if the subsection is not in progress" do diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index e1c577d99..e230b15c7 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -624,7 +624,7 @@ RSpec.describe CaseLogsController, type: :request do it "displays a section status for a case log" do assert_select ".govuk-tag", text: /Not started/, count: 7 - assert_select ".govuk-tag", text: /In progress/, count: 1 + assert_select ".govuk-tag", text: /In progress/, count: 2 assert_select ".govuk-tag", text: /Completed/, count: 0 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index c5e50beba..b0b2048a5 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -80,9 +80,9 @@ RSpec.describe FormController, type: :request do let(:case_log_year_2) { FactoryBot.create(:case_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation) } it "displays the correct question details for each case log based on form year" do - get "/logs/#{case_log_year_1.id}/tenant-code", headers: headers, params: {} + get "/logs/#{case_log_year_1.id}/tenant-code-test", headers: headers, params: {} expect(response.body).to include("What is the tenant code?") - get "/logs/#{case_log_year_2.id}/tenant-code", headers: headers, params: {} + get "/logs/#{case_log_year_2.id}/tenant-code-test", headers: headers, params: {} expect(response.body).to match("Different question header text for this year - 2023") end end