From 7cf68cd33b54c02f2e093d9ef21ba6309532ed09 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 8 Jun 2023 11:59:56 +1000 Subject: [PATCH] Ensure that specs restore default window size --- spec/support/request/ui_component_helper.rb | 28 +++++++++++++-------- spec/system/consumer/authentication_spec.rb | 11 +++----- spec/system/consumer/multilingual_spec.rb | 3 ++- spec/system/consumer/white_label_spec.rb | 16 ++---------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index ba2f997d64..989efa40a0 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -1,24 +1,30 @@ # frozen_string_literal: true module UIComponentHelper - def browse_as_small - Capybara.current_session.current_window - .resize_to(640, 480) + def browse_as_small(&block) + browse_with_window_size(640, 480, &block) end - def browse_as_medium - Capybara.current_session.current_window - .resize_to(1024, 768) + def browse_as_medium(&block) + browse_with_window_size(1024, 768, &block) end - def browse_as_default - Capybara.current_session.current_window - .resize_to(1200, 800) + def browse_as_default(&block) + browse_with_window_size(1200, 800) + block&.call end - def browse_as_large + def browse_as_large(&block) + browse_with_window_size(1280, 800, &block) + end + + def browse_with_window_size(width, height, &block) Capybara.current_session.current_window - .resize_to(1280, 800) + .resize_to(width, height) + return unless block + + block.call + browse_as_default end def click_login_button diff --git a/spec/system/consumer/authentication_spec.rb b/spec/system/consumer/authentication_spec.rb index e3dfe2bbfd..a1ca62e60d 100644 --- a/spec/system/consumer/authentication_spec.rb +++ b/spec/system/consumer/authentication_spec.rb @@ -25,8 +25,9 @@ describe "Authentication" do visit root_path end describe "as large" do + around { |example| browse_as_large { example.run } } + before do - browse_as_large open_login_modal end @@ -173,12 +174,8 @@ describe "Authentication" do end describe "as medium" do - before do - browse_as_medium - end - after do - browse_as_large - end + around { |example| browse_as_medium { example.run } } + it "showing login" do open_off_canvas open_login_modal diff --git a/spec/system/consumer/multilingual_spec.rb b/spec/system/consumer/multilingual_spec.rb index 228c128bc5..556b59b893 100644 --- a/spec/system/consumer/multilingual_spec.rb +++ b/spec/system/consumer/multilingual_spec.rb @@ -100,7 +100,8 @@ describe 'Multilingual' do end describe "using the language switcher UI" do - before { browse_as_large } + around { |example| browse_as_large { example.run } } + context "when there is only one language available" do before do allow(ENV).to receive(:[]).and_call_original diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 083b89256e..e4e66b41a3 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -32,13 +32,7 @@ describe 'White label setting' do shared_examples "hides the OFN navigation for mobile view as well" do context "mobile view" do - before do - browse_as_small - end - - after do - browse_as_default - end + around { |example| browse_as_small { example.run } } it "hides OFN navigation" do find("a.left-off-canvas-toggle").click @@ -55,13 +49,7 @@ describe 'White label setting' do shared_examples "does not hide the OFN navigation for mobile view as well" do context "mobile view" do - before do - browse_as_small - end - - after do - browse_as_default - end + around { |example| browse_as_small { example.run } } it "does not hide OFN navigation" do find("a.left-off-canvas-toggle").click