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.

75 lines
2.4 KiB

require "rails_helper"
require_relative "helpers"
require_relative "../../request_helper"
RSpec.describe "Checkboxes" do
include Helpers
let(:user) { FactoryBot.create(:user) }
let(:lettings_log) do
FactoryBot.create(
:lettings_log,
:in_progress,
created_by: user,
)
end
let(:id) { lettings_log.id }
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
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
RequestHelper.stub_http_requests
sign_in user
end
context "when exclusive checkbox is selected", js: true do
it "deselects all other checkboxes" do
visit("/lettings-logs/#{id}/accessibility-requirements")
page.check("lettings-log-accessibility-requirements-housingneeds-a-field", allow_label_click: true)
click_button("Save and continue")
lettings_log.reload
expect(lettings_log["housingneeds_a"]).to eq(1)
visit("/lettings-logs/#{id}/accessibility-requirements")
page.check("lettings-log-accessibility-requirements-housingneeds-h-field", allow_label_click: true)
click_button("Save and continue")
lettings_log.reload
expect(lettings_log["housingneeds_a"]).to eq(0)
expect(lettings_log["housingneeds_h"]).to eq(1)
end
end
context "when a checkbox question is submitted with invalid answers" do
before do
lettings_log.illness = 100
lettings_log.save!(validate: false)
allow(lettings_log).to receive(:update).and_return(false)
end
it "shows an error summary" do
visit("/lettings-logs/#{id}/condition-effects")
page.check("lettings-log-condition-effects-illness-type-1-field")
page.check("lettings-log-condition-effects-illness-type-2-field")
click_button("Save and continue")
expect(page).to have_title("Error")
end
it "persists the original selections" do
visit("/lettings-logs/#{id}/condition-effects")
page.check("lettings-log-condition-effects-illness-type-1-field")
page.check("lettings-log-condition-effects-illness-type-2-field")
click_button("Save and continue")
expect(page).to have_checked_field("lettings-log-condition-effects-illness-type-2-field")
end
end
end