From 7a98ccbd4df75726e9a61157721040fe6d451661 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 30 Mar 2022 14:03:14 +0100 Subject: [PATCH] Update content and add more tests for previous page --- config/forms/2021_2022.json | 2 +- config/locales/en.yml | 6 +-- spec/features/form/validations_spec.rb | 4 +- spec/fixtures/forms/2021_2022.json | 2 +- .../helpers/interuption_screen_helper_spec.rb | 2 +- spec/models/form_spec.rb | 42 ++++++++++++++++--- .../validations/household_validations_spec.rb | 2 +- 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index f14084727..076c80c2b 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -4575,7 +4575,7 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "Net income is outside the expected range based on the main tenant’s working situation", + "title_text": "Net income is outside the expected range based on the lead tenant’s working situation", "informative_text": { "translation": "soft_validations.net_income.hint_text", "argument": {"ecstat1": "question", "earnings": "question"} diff --git a/config/locales/en.yml b/config/locales/en.yml index ab8c70099..f659bef3e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -219,11 +219,11 @@ en: soft_validations: net_income: - hint_text: "

You told us the main tenant’s working situation is: %{ecstat1}

The household income you have entered is %{earnings}

" + hint_text: "

You told us the lead tenant’s working situation is: %{ecstat1}

The household income you have entered is %{earnings}

" in_soft_min_range: - message: "Net income is lower than expected based on the main tenant’s working situation. Are you sure this is correct?" + message: "Net income is lower than expected based on the lead tenant’s working situation. Are you sure this is correct?" in_soft_max_range: - message: "Net income is higher than expected based on the main tenant’s working situation. Are you sure this is correct?" + message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" rent: min: hint_text: "

The minimum rent for a property in %{la} is £%{soft_min} every week.

You entered %{brent}

" diff --git a/spec/features/form/validations_spec.rb b/spec/features/form/validations_spec.rb index 34f6fbfd5..e1947bf87 100644 --- a/spec/features/form/validations_spec.rb +++ b/spec/features/form/validations_spec.rb @@ -130,8 +130,8 @@ RSpec.describe "validations" do choose("case-log-incfreq-0-field", allow_label_click: true) click_button("Save and continue") expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check") - expect(page).to have_content("Net income is outside the expected range based on the main tenant’s working situation") - expect(page).to have_content("You told us the main tenant’s working situation is: Full-time – 30 hours or more") + expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") + expect(page).to have_content("You told us the lead tenant’s working situation is: Full-time – 30 hours or more") expect(page).to have_content("The household income you have entered is £750.00 every week") choose("case-log-net-income-value-check-0-field", allow_label_click: true) click_button("Save and continue") diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 06c471ff2..c61582c2f 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -559,7 +559,7 @@ }, "net_income_value_check": { "depends_on": [{ "net_income_soft_validation_triggered?": true }], - "title_text": "Net income is outside the expected range based on the main tenant’s working situation", + "title_text": "Net income is outside the expected range based on the lead tenant’s working situation", "informative_text": { "translation": "soft_validations.net_income.hint_text", "argument": {"ecstat1": "question", "earnings": "question"} diff --git a/spec/helpers/interuption_screen_helper_spec.rb b/spec/helpers/interuption_screen_helper_spec.rb index 9b050cf14..efcf4d1e2 100644 --- a/spec/helpers/interuption_screen_helper_spec.rb +++ b/spec/helpers/interuption_screen_helper_spec.rb @@ -25,7 +25,7 @@ RSpec.describe InteruptionScreenHelper do "argument" => { "ecstat1": "question", "earnings": "question" }, } expect(display_informative_text(informative_text, case_log)) - .to eq("

You told us the main tenant’s working situation is: Full-time – 30 hours or more

The household income you have entered is £750.00 every week

") + .to eq("

You told us the lead tenant’s working situation is: Full-time – 30 hours or more

The household income you have entered is £750.00 every week

") end end diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 488947bb4..61387969b 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -14,13 +14,43 @@ RSpec.describe Form, type: :model do expect(form.next_page(previous_page, case_log)).to eq("person_1_gender") end - it "returns the previuos page if the current page is a value check page with a `No` answer and the page is routed to" do - case_log.net_income_value_check = 1 - case_log.incfreq = 0 - case_log.earnings = 140 - case_log.ecstat1 = 1 + context "when the current page is a value check page" do + before do + case_log.incfreq = 0 + case_log.earnings = 140 + case_log.ecstat1 = 1 + end + + it "returns the previous page if answer is `No` and the page is routed to" do + case_log.net_income_value_check = 1 + expect(form.next_page(value_check_previous_page, case_log)).to eq("net_income") + end + + it "returns the next page if answer is `Yes` answer and the page is routed to" do + case_log.net_income_value_check = 0 + expect(form.next_page(value_check_previous_page, case_log)).to eq("net_income_uc_proportion") + end + end + end - expect(form.next_page(value_check_previous_page, case_log)).to eq("net_income") + describe ".previous_page" do + context "when the current page is not a value check page" do + let!(:subsection) { form.get_subsection("conditional_question") } + let!(:page_ids) { subsection.pages.map(&:id) } + + before do + case_log.preg_occ = 1 + end + + it "returns the previous page if the page is routed to" do + page_index = page_ids.index("conditional_question_no_second_page") + expect(form.previous_page(page_ids, page_index, case_log)).to eq("conditional_question_no_page") + end + + it "returns the page before the previous one if the previous page is not routed to" do + page_index = page_ids.index("conditional_question_no_page") + expect(form.previous_page(page_ids, page_index, case_log)).to eq("conditional_question") + end end end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index de78e01d9..9d1a00282 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -86,7 +86,7 @@ RSpec.describe Validations::HouseholdValidations do end end - context "and they are the main tenant and under 51" do + context "and they are the lead tenant and under 51" do it "pregnancy can be yes" do record.preg_occ = 0 record.sex1 = "F"