Browse Source

feat: fix more tests

pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
4da36d28ee
  1. 4
      app/controllers/locations_controller.rb
  2. 2
      spec/features/form/accessible_autocomplete_spec.rb
  3. 5
      spec/models/form/lettings/questions/scheme_id_spec.rb
  4. 2
      spec/models/lettings_log_spec.rb
  5. 2
      spec/models/location_spec.rb

4
app/controllers/locations_controller.rb

@ -142,9 +142,7 @@ class LocationsController < ApplicationController
end end
def confirm_location def confirm_location
if [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?) @location.update!(confirmed: [@location.postcode, @location.location_admin_district, @location.location_code, @location.units, @location.type_of_unit, @location.mobility_type].all?(&:present?))
@location.update!(confirmed: true)
end
end end
def show; end def show; end

2
spec/features/form/accessible_autocomplete_spec.rb

@ -87,7 +87,7 @@ RSpec.describe "Accessible Autocomplete" do
it "displays appended text next to the options", js: true do it "displays appended text next to the options", js: true do
find("#lettings-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter) find("#lettings-log-scheme-id-field").click.native.send_keys("w", "6", :down, :enter)
expect(find(".autocomplete__option", visible: :hidden, text: scheme.service_name)).to be_present expect(find(".autocomplete__option", visible: :hidden, text: scheme.service_name)).to be_present
expect(find("span", visible: :hidden, text: "2 locations")).to be_present expect(find("span", visible: :hidden, text: "2 completed locations, 0 incomplete locations")).to be_present
end end
it "displays hint text under the options", js: true do it "displays hint text under the options", js: true do

5
spec/models/form/lettings/questions/scheme_id_spec.rb

@ -44,6 +44,7 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, organisation:) } let(:user) { FactoryBot.create(:user, organisation:) }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) } let(:scheme) { FactoryBot.create(:scheme, owning_organisation: organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) }
let(:lettings_log) { FactoryBot.create(:lettings_log, created_by: user, needstype: 2) } let(:lettings_log) { FactoryBot.create(:lettings_log, created_by: user, needstype: 2) }
before do before do
@ -84,13 +85,13 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
end end
context "when the question is answered" do context "when the question is answered" do
it "returns 'select an option' as selected answer" do it "returns scheme as selected answer" do
lettings_log.update!(scheme:) lettings_log.update!(scheme:)
answers = question.displayed_answer_options(lettings_log).map do |key, value| answers = question.displayed_answer_options(lettings_log).map do |key, value|
OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value)
end end
answers.each do |answer| answers.each do |answer|
if answer.id == scheme.id if answer.id.to_i == scheme.id
expect(question.answer_selected?(lettings_log, answer)).to eq(true) expect(question.answer_selected?(lettings_log, answer)).to eq(true)
else else
expect(question.answer_selected?(lettings_log, answer)).to eq(false) expect(question.answer_selected?(lettings_log, answer)).to eq(false)

2
spec/models/lettings_log_spec.rb

@ -2259,7 +2259,7 @@ RSpec.describe LettingsLog do
describe "resetting invalidated fields" do describe "resetting invalidated fields" do
let(:scheme) { create(:scheme, owning_organisation: created_by_user.organisation) } let(:scheme) { create(:scheme, owning_organisation: created_by_user.organisation) }
let(:location) { create(:location, location_code: "E07000223", scheme:) } let!(:location) { create(:location, location_code: "E07000223", scheme:) }
let(:lettings_log) do let(:lettings_log) do
create( create(
:lettings_log, :lettings_log,

2
spec/models/location_spec.rb

@ -798,7 +798,7 @@ RSpec.describe Location, type: :model do
before do before do
FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today) FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR", startdate: Time.zone.today)
FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day) FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ", startdate: Time.zone.today + 1.day)
FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: Time.zone.today - 1.day, units: nil, confirmed: false)
FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil) FactoryBot.create(:location, name: "GHQ", postcode: "EW1 7JK", startdate: nil)
end end

Loading…
Cancel
Save