diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 573c8631a..80dfb4a88 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -35,6 +35,7 @@ class FormController < ApplicationController if @case_log @subsection = @case_log.form.subsection_for_page(page) @page = @case_log.form.get_page(page.id) + binding.pry if @page.routed_to?(@case_log) && @page.subsection.enabled?(@case_log) render "form/page" else diff --git a/app/models/form/page.rb b/app/models/form/page.rb index fc82d9096..12b1065d6 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -21,12 +21,6 @@ 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 diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index d01c44c1d..9efb7d8ee 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -1,5 +1,7 @@ { "form_type": "lettings", + "start_year": 2021, + "end_year": 2022, "sections": { "household": { "label": "About the household", @@ -250,24 +252,6 @@ "tenancy_information": { "label": "Tenancy information", "pages": { - "joint_tenancy": { - "header": "", - "description": "", - "questions": { - "jointtenancy": { - "check_answer_label": "Is this a joint tenancy?", - "header": "Is this a joint tenancy?", - "hint_text": "", - "type": "radio", - "answer_options": { - "0": "Yes", - "1": "No", - "2": "Don't know" - } - } - }, - "depends_on": { "conditions" : ["is_22_23_log?(case_log[\"startdate\"])"] } - }, "tenancy_code": { "questions": { "tenancy_code": { diff --git a/spec/fixtures/forms/2022_2023.json b/spec/fixtures/forms/2022_2023.json index c666dc37a..825336cf7 100644 --- a/spec/fixtures/forms/2022_2023.json +++ b/spec/fixtures/forms/2022_2023.json @@ -1,5 +1,7 @@ { "form_type": "lettings", + "start_year": 2022, + "end_year": 2023, "sections": { "about_this_log": { "label": "About this log", @@ -167,6 +169,174 @@ } } } + }, + "tenancy_and_property": { + "label": "Tenancy and property information", + "subsections": { + "tenancy_information": { + "label": "Tenancy information", + "pages": { + "joint_tenancy": { + "header": "", + "description": "", + "questions": { + "jointtenancy": { + "check_answer_label": "Is this a joint tenancy?", + "header": "Is this a joint tenancy?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No", + "2": "Don't know" + } + } + } + }, + "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": { + "header": "", + "description": "", + "questions": { + "lettinginshelteredaccomodation": { + "check_answer_label": "Is this letting in sheltered accommodation?", + "header": "Is this letting in sheltered accommodation?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "Yes - sheltered housing", + "1": "Yes - extra care housing", + "2": "No", + "3": "Don't know" + } + } + } + } + } + }, + "property_information": { + "label": "Property information", + "pages": { + "property_postcode": { + "header": "", + "description": "", + "questions": { + "property_postcode": { + "check_answer_label": "Postcode", + "header": "", + "hint_text": "", + "type": "text", + "width": 5, + "inferred_answers": { "la": { "is_la_inferred": true } }, + "inferred_check_answers_value": { + "condition": { "postcode_known": "No" }, + "value": "Not known" + } + } + } + }, + "do_you_know_the_local_authority": { + "header": "", + "description": "", + "questions": { + "la_known": { + "check_answer_label": "Do you know what local authority the property is located in?", + "header": "Do you know what local authority the property is located in?", + "hint_text": "", + "type": "radio", + "answer_options": { + "0": "No", + "1": "Yes" + } + } + }, + "depends_on": {"is_la_inferred": false} + }, + "property_wheelchair_accessible": { + "questions": { + "wchair": { + "check_answer_label": "Wheelchair adaptation", + "header": "Is the property built or adapted to wheelchair-user standards?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + } + } + } + }, + "conditional_question": { + "label": "Conditional question", + "pages": { + "conditional_question": { + "questions": { + "preg_occ": { + "check_answer_label": "Has the condition been met?", + "header": "Has the condition been met?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + } + }, + "conditional_question_yes_page": { + "questions": { + "cbl": { + "check_answer_label": "Has the next condition been met?", + "header": "Has the next condition been met?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + }, + "depends_on": { "preg_occ": "Yes" } + }, + "conditional_question_no_page": { + "questions": { + "conditional_question_no_question": { + "check_answer_label": "Has the condition not been met?", + "header": "Has the next condition not been met?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + }, + "depends_on": { "preg_occ": "No" } + }, + "conditional_question_no_second_page": { + "questions": { + "conditional_question_no_second_question": { + "check_answer_label": "Has the condition not been met again?", + "header": "Has the next condition not been met again?", + "type": "radio", + "answer_options": { + "0": "Yes", + "1": "No" + } + } + }, + "depends_on": { "preg_occ": "No", "sex1": "Male" } + } + } + } + } } } } diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index 184fc6deb..4d65ba104 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -243,16 +243,25 @@ RSpec.describe CaseLogsController, type: :request do context "tenancy information pages" do let(:headers) { { "Accept" => "text/html" } } + let!(:case_log_22_23_period) do + FactoryBot.create( + :case_log, + :about_completed, + startdate: Time.zone.local(2022, 10, 10), + owning_organisation: organisation, + managing_organisation: organisation, + ) + end - it "has a joint tenancy page that can be visited" do + it "has a joint tenancy page that can be visited if the case log is in the 2022-2023 period" do sign_in user - get "/logs/#{case_log.id}/joint-tenancy", headers: headers, params: { case_log_id: case_log.id } + get "/logs/#{case_log_22_23_period.id}/joint-tenancy", headers: headers, params: { case_log_id: case_log_22_23_period.id } 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 "/logs/#{case_log.id}/letting-in-sheltered-accomodation", headers: headers, params: { case_log_id: case_log.id } + get "/logs/#{case_log_22_23_period.id}/letting-in-sheltered-accomodation", headers: headers, params: { case_log_id: case_log_22_23_period.id } expect(response).to have_http_status(:success) end end