From da4dfb3946256932672db23fc0d1315e10e33c0c Mon Sep 17 00:00:00 2001 From: ramya vidapanakal Date: Wed, 4 Sep 2024 15:12:20 +0100 Subject: [PATCH] added switch app menu item Added test to verify switch app menu item Updated code to include system test for switch app menu item updated code in user helper to remove warning messages in test suite --- app/views/layouts/application.html.erb | 4 ++++ spec/rails_helper.rb | 3 +++ spec/support/users_helper.rb | 12 ++++++------ spec/system/main_menu_spec.rb | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 spec/system/main_menu_spec.rb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 34187413..69937dd6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -24,6 +24,10 @@ href: root_path, active: current_page?(root_path), }, + { + text: "Switch app", + href: Plek.external_url_for("signon"), + }, ], } %> diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 95965ab1..672e9b96 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -24,4 +24,7 @@ config.expose_dsl_globally = false config.infer_spec_type_from_file_location! config.use_transactional_fixtures = true + config.before(:each, type: :system) do + driven_by :rack_test + end end diff --git a/spec/support/users_helper.rb b/spec/support/users_helper.rb index 3da4261d..a1cd5ee2 100644 --- a/spec/support/users_helper.rb +++ b/spec/support/users_helper.rb @@ -11,11 +11,11 @@ def as_other_department_user(&block) end def as_logged_in_user(permissions, organisation_slug, &_block) - allow(@controller).to receive(:authenticate_user!).and_return(true) - allow(@controller).to receive(:user_signed_in?).and_return(true) - allow(@controller).to receive(:current_user).and_return(User.new(permissions:, organisation_slug:)) + allow_any_instance_of(ApplicationController).to receive(:authenticate_user!).and_return(true) + allow_any_instance_of(ApplicationController).to receive(:user_signed_in?).and_return(true) + allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(User.new(permissions:, organisation_slug:)) yield - allow(@controller).to receive(:authenticate_user!).and_call_original - allow(@controller).to receive(:user_signed_in?).and_call_original - allow(@controller).to receive(:current_user).and_call_original + allow_any_instance_of(ApplicationController).to receive(:authenticate_user!).and_call_original + allow_any_instance_of(ApplicationController).to receive(:user_signed_in?).and_call_original + allow_any_instance_of(ApplicationController).to receive(:current_user).and_call_original end diff --git a/spec/system/main_menu_spec.rb b/spec/system/main_menu_spec.rb new file mode 100644 index 00000000..694f83db --- /dev/null +++ b/spec/system/main_menu_spec.rb @@ -0,0 +1,16 @@ +require "rails_helper" + +RSpec.describe "Main menu" do + context "as a normal user" do + it "shows the Services/Switch app menu items and goes to signon when Switch app is clicked" do + as_gds_editor do + visit "/admin" + + within(".govuk-header__container") do + expect(page).to have_link("Services") + expect(page).to have_link("Switch app") + end + end + end + end +end