From 3f756365e7f29c20f0d6a46fcce8f4ba912260b3 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Thu, 17 Nov 2022 11:24:32 +0000 Subject: [PATCH] test: mock new locations layout feature toggle in tests --- spec/features/schemes_spec.rb | 29 ++++++++---- spec/requests/locations_controller_spec.rb | 52 +++++++++++++--------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 5c668324e..42a2b31ec 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -195,7 +195,7 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_link("Locations") end - context "when I click locations link" do + context "when I click locations link and the new locations layout feature toggle is enabled" do before do click_link("Locations") end @@ -204,14 +204,25 @@ RSpec.describe "Schemes scheme Features" do locations.each do |location| expect(page).to have_content(location.id) expect(page).to have_content(location.postcode) - if FeatureToggle.new_locations_table_layout_enabled? - expect(page).to have_content(location.name) - expect(page).to have_content("Active") - else - expect(page).to have_content(location.units) - expect(page).to have_content(location.type_of_unit) - expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) - end + expect(page).to have_content(location.name) + expect(page).to have_content("Active") + end + end + end + + context "when I click locations link and the new locations layout feature toggle is disabled" do + before do + allow(FeatureToggle).to receive(:new_locations_table_layout_enabled?).and_return(false) + click_link("Locations") + end + + it "shows details of those locations" do + locations.each do |location| + expect(page).to have_content(location.id) + expect(page).to have_content(location.postcode) + expect(page).to have_content(location.units) + expect(page).to have_content(location.type_of_unit) + expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) end end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index b44360b9e..91f2e913c 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -867,19 +867,25 @@ RSpec.describe LocationsController, type: :request do end end - it "shows locations with correct data" do + it "shows locations with correct data wben the new locations layout feature toggle is enabled" do locations.each do |location| expect(page).to have_content(location.id) expect(page).to have_content(location.postcode) - if FeatureToggle.new_locations_table_layout_enabled? - expect(page).to have_content(location.name) - expect(page).to have_content(location.status) - else - expect(page).to have_content(location.type_of_unit) - expect(page).to have_content(location.mobility_type) - expect(page).to have_content(location.location_admin_district) - expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) - end + expect(page).to have_content(location.name) + expect(page).to have_content(location.status) + end + end + + it "shows locations with correct data wben the new locations layout feature toggle is disabled" do + allow(FeatureToggle).to receive(:new_locations_table_layout_enabled?).and_return(false) + get "/schemes/#{scheme.id}/locations" + locations.each do |location| + expect(page).to have_content(location.id) + expect(page).to have_content(location.postcode) + expect(page).to have_content(location.type_of_unit) + expect(page).to have_content(location.mobility_type) + expect(page).to have_content(location.location_admin_district) + expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) end end @@ -977,19 +983,25 @@ RSpec.describe LocationsController, type: :request do get "/schemes/#{scheme.id}/locations" end - it "shows locations with correct data" do + it "shows locations with correct data wben the new locations layout feature toggle is enabled" do locations.each do |location| expect(page).to have_content(location.id) expect(page).to have_content(location.postcode) - if FeatureToggle.new_locations_table_layout_enabled? - expect(page).to have_content(location.name) - expect(page).to have_content(location.status) - else - expect(page).to have_content(location.type_of_unit) - expect(page).to have_content(location.mobility_type) - expect(page).to have_content(location.location_admin_district) - expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) - end + expect(page).to have_content(location.name) + expect(page).to have_content(location.status) + end + end + + it "shows locations with correct data wben the new locations layout feature toggle is disabled" do + allow(FeatureToggle).to receive(:new_locations_table_layout_enabled?).and_return(false) + get "/schemes/#{scheme.id}/locations" + locations.each do |location| + expect(page).to have_content(location.id) + expect(page).to have_content(location.postcode) + expect(page).to have_content(location.type_of_unit) + expect(page).to have_content(location.mobility_type) + expect(page).to have_content(location.location_admin_district) + expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) end end