From d241ad2c0921a93072cdf8ce87216bad9172bcbf Mon Sep 17 00:00:00 2001 From: MadeTech Dushan Date: Fri, 10 Dec 2021 12:25:24 +0000 Subject: [PATCH] add test for conditional display of page --- app/helpers/tasklist_helper.rb | 2 +- app/models/form/page.rb | 11 +++++++++++ config/forms/2021_2022.json | 3 ++- spec/features/form/page_routing_spec.rb | 24 +++++++++++++++++++++++ spec/fixtures/forms/2021_2022.json | 21 ++++++++++---------- spec/requests/case_log_controller_spec.rb | 12 ++++++------ 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/helpers/tasklist_helper.rb b/app/helpers/tasklist_helper.rb index a6935f620..7b97f1ca6 100644 --- a/app/helpers/tasklist_helper.rb +++ b/app/helpers/tasklist_helper.rb @@ -29,7 +29,7 @@ module TasklistHelper path = if subsection.is_started?(case_log) "case_log_#{subsection.id}_check_answers_path" else - "case_log_#{subsection.pages.first.id}_path" + "case_log_#{subsection.applicable_questions(case_log).first.page.id}_path" end send(path, case_log) end diff --git a/app/models/form/page.rb b/app/models/form/page.rb index 12b1065d6..dfa68521b 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -21,11 +21,22 @@ class Form::Page soft_validations.present? end + def is_22_23_log?(startdate) + return false if startdate.blank? + + startdate.to_date > Date.parse("2022-04-01") && startdate.to_date < Date.parse("2023-04-01") + end + def routed_to?(case_log) return true unless depends_on depends_on.all? do |question, value| !case_log[question].nil? && case_log[question] == value + if question == "conditions" + return value.all? { |condition| eval(condition) } + end + + case_log[question].present? && case_log[question] == value end end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index ea6e9a9c3..58d7227e9 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1069,7 +1069,8 @@ "2": "Don't know" } } - } + }, + "depends_on": { "conditions" : ["is_22_23_log?(case_log[\"startdate\"])"] } }, "starter_tenancy": { "header": "", diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 8f9d42ad9..9a80e8ed5 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -72,4 +72,28 @@ RSpec.describe "Form Page Routing" do expect(page).to have_current_path("/logs/#{id}/property-wheelchair-accessible") end end + + context "routing based on start date period", js: true do + it "the first question in tenancy information section is joint tenancy if startdate is in 2022/23 period" do + visit("/case-logs/#{id}/startdate") + fill_in("case_log_startdate_3i", with: 10) + fill_in("case_log_startdate_2i", with: 10) + fill_in("case_log_startdate_1i", with: 2022) + click_button("Save and continue") + visit("/case-logs/#{id}") + click_link(text: "Tenancy information") + expect(page).to have_current_path("/case-logs/#{id}/joint-tenancy") + end + + it "the first question in tenancy information section is not joint tenancy if startdate is in 2021/22 period" do + visit("/case-logs/#{id}/startdate") + fill_in("case_log_startdate_3i", with: 10) + fill_in("case_log_startdate_2i", with: 10) + fill_in("case_log_startdate_1i", with: 2021) + click_button("Save and continue") + visit("/case-logs/#{id}") + click_link(text: "Tenancy information") + expect(page).to have_current_path("/case-logs/#{id}/tenancy-code") + end + end end diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 7e96cbf1f..d01c44c1d 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -250,16 +250,6 @@ "tenancy_information": { "label": "Tenancy information", "pages": { - "tenancy_code": { - "questions": { - "tenancy_code": { - "check_answer_label": "What is the tenancy code?", - "header": "What is the tenancy code?", - "type": "text", - "width": 10 - } - } - }, "joint_tenancy": { "header": "", "description": "", @@ -275,6 +265,17 @@ "2": "Don't know" } } + }, + "depends_on": { "conditions" : ["is_22_23_log?(case_log[\"startdate\"])"] } + }, + "tenancy_code": { + "questions": { + "tenancy_code": { + "check_answer_label": "What is the tenancy code?", + "header": "What is the tenancy code?", + "type": "text", + "width": 10 + } } }, "letting_in_sheltered_accomodation": { diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index 55c5adc30..c1eddafcd 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -243,19 +243,19 @@ RSpec.describe CaseLogsController, type: :request do context "tenancy information pages" do let(:headers) { { "Accept" => "text/html" } } - + it "has a joint tenancy page that can be visited" do sign_in user get "/case-logs/#{case_log.id}/joint-tenancy", headers: headers, params: { case_log_id: case_log.id } - expect(response).to have_http_status(:success) - end + expect(response).to have_http_status(:success) + end it "has a letting in sheltered accomondation page that can be visited" do sign_in user get "/case-logs/#{case_log.id}/letting-in-sheltered-accomodation", headers: headers, params: { case_log_id: case_log.id } - expect(response).to have_http_status(:success) - end - end + expect(response).to have_http_status(:success) + end + end end context "Check answers" do