Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.4 KiB

require "rails_helper"
require_relative "helpers"
RSpec.describe "Form Conditional Questions" do
CLDC-1917 Add Startdate Validation (#1378) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2
2 years ago
around do |example|
Timecop.freeze(Time.zone.local(2022, 1, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
include Helpers
let(:user) { FactoryBot.create(:user) }
let(:lettings_log) do
FactoryBot.create(
:lettings_log,
:in_progress,
created_by: user,
)
end
let(:sales_log) do
FactoryBot.create(
:sales_log,
:completed,
created_by: user,
CLDC-1917 Add Startdate Validation (#1378) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2
2 years ago
saledate: Time.zone.local(2022, 1, 1),
)
end
let(:id) { lettings_log.id }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
sign_in user
end
context "with a page where some questions are only conditionally shown, depending on how you answer the first question" do
before do
allow(sales_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
it "initially hides conditional questions" do
visit("/lettings-logs/#{id}/armed-forces")
expect(page).not_to have_selector("#armed_forces_injured_div")
end
it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do
visit("/lettings-logs/#{id}/armed-forces")
# Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here
choose("lettings-log-armedforces-1-field", allow_label_click: true)
fill_in("lettings-log-leftreg-field", with: "text")
choose("lettings-log-armedforces-4-field", allow_label_click: true)
expect(page).not_to have_field("lettings-log-leftreg-field")
choose("lettings-log-armedforces-1-field", allow_label_click: true)
expect(page).to have_field("lettings-log-leftreg-field", with: "")
end
end
context "when a conditional question has a saved answer", js: true do
before do
allow(sales_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
it "is displayed correctly" do
lettings_log.update!(postcode_known: 1, postcode_full: "NW1 6RT")
visit("/lettings-logs/#{id}/property-postcode")
expect(page).to have_field("lettings-log-postcode-full-field", with: "NW1 6RT")
end
it "gets cleared if the conditional question is hidden after editing the answer" do
sales_log.update!(age1_known: 0, age1: 50)
visit("/sales-logs/#{sales_log.id}/buyer-1-age")
expect(page).to have_field("sales-log-age1-field", with: 50)
choose("sales-log-age1-known-1-field", allow_label_click: true)
choose("sales-log-age1-known-0-field", allow_label_click: true)
expect(page).to have_field("sales-log-age1-field", with: "")
end
end
context "when a conditional question has an error" do
let(:lettings_log) do
FactoryBot.create(
:lettings_log,
:completed,
created_by: user,
)
end
before do
FormHandler.instance.use_real_forms!
end
it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do
visit("/lettings-logs/#{id}/lead-tenant-age")
choose("lettings-log-age1-known-0-field", allow_label_click: true)
fill_in("lettings-log-age1-field", with: "200")
click_button("Save and continue")
expect(page).not_to have_field("lettings-log-age1-field")
expect(page).to have_field("lettings-log-age1-field-error")
choose("lettings-log-age1-known-1-field", allow_label_click: true)
expect(page).not_to have_field("lettings-log-age1-field")
expect(page).not_to have_field("lettings-log-age1-field-error")
choose("lettings-log-age1-known-0-field", allow_label_click: true)
expect(page).not_to have_field("lettings-log-age1-field")
expect(page).to have_field("lettings-log-age1-field-error", with: "")
end
end
end