diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 50e9c8b5..aa4438f5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,23 +1,16 @@ class ApplicationController < ActionController::Base helper Mitlibraries::Theme::Engine.helpers - # Set active tab based on feature flag and params - # Also stores the last used tab in a cookie for future searches when passed via params. - # We set this in a session cookie to persist user preference across searches. - # Clicking on a different tab will update the cookie. + # Set active tab based on params (no persistent cookie). This intentionally + # avoids storing the user's last-used tab in a cookie per UXWS request. def set_active_tab # GeoData doesn't use the tab system. return if Feature.enabled?(:geodata) @active_tab = if params[:tab].present? && valid_tab?(params[:tab]) - # If params[:tab] is set and valid, use it and set session - cookies[:last_tab] = params[:tab] - elsif cookies[:last_tab].present? && valid_tab?(cookies[:last_tab]) - # Otherwise, check for last used tab in session if valid - cookies[:last_tab] + params[:tab] else - # Default behavior when no tab is specified in params or session - cookies[:last_tab] = 'all' + 'all' end end diff --git a/test/controllers/application_controller_test.rb b/test/controllers/application_controller_test.rb index 9f926988..af054e04 100644 --- a/test/controllers/application_controller_test.rb +++ b/test/controllers/application_controller_test.rb @@ -2,8 +2,6 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest test 'set_active_tab sets default to all when no feature flag or params' do - assert_nil cookies[:last_tab] - get root_path assert_select '#tab-to-target' do assert_select '[value=?]', 'all' @@ -11,8 +9,6 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest refute_select '[value=?]', 'primo' refute_select '[value=?]', 'timdex' end - - assert_equal cookies[:last_tab], 'all' end test 'set_active_tab sets to geodata when feature flag enabled' do @@ -37,8 +33,7 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest end end - test 'set_active_tab sets to param tab when provided even if cookie is set and updates cookie' do - cookies[:last_tab] = 'timdex' + test 'set_active_tab sets to param tab when provided (param takes precedence)' do get root_path, params: { tab: 'primo' } assert_select '#tab-to-target' do @@ -47,17 +42,14 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest refute_select '[value=?]', 'timdex' refute_select '[value=?]', 'all' end - - assert_equal cookies[:last_tab], 'primo' end - test 'set_active_tab uses cookie last_tab when no param provided' do - cookies[:last_tab] = 'timdex' + test 'set_active_tab defaults to all when no param provided' do get root_path assert_select '#tab-to-target' do - refute_select '[value=?]', 'all' + assert_select '[value=?]', 'all' refute_select '[value=?]', 'primo' - assert_select '[value=?]', 'timdex' + refute_select '[value=?]', 'timdex' end end @@ -65,7 +57,7 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest app_controller = ApplicationController.new assert app_controller.send(:valid_tab?, 'primo') - assert app_controller.send(:valid_tab?, 'timdex') + assert app_controller.send(:valid_tab?, 'timdex') assert app_controller.send(:valid_tab?, 'all') end @@ -84,43 +76,31 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest assert_select '[value=?]', 'all' refute_select '[value=?]', 'invalid_tab' end - - assert_equal cookies[:last_tab], 'all' end test 'set_active_tab ignores invalid cookie value and uses default' do - cookies[:last_tab] = 'invalid_cookie_value' get root_path assert_select '#tab-to-target' do assert_select '[value=?]', 'all' refute_select '[value=?]', 'invalid_cookie_value' end - - assert_equal cookies[:last_tab], 'all' end test 'set_active_tab prioritizes valid param over invalid cookie' do - cookies[:last_tab] = 'invalid_cookie' get root_path, params: { tab: 'timdex' } assert_select '#tab-to-target' do - refute_select '[value=?]', 'invalid_cookie' assert_select '[value=?]', 'timdex' end - - assert_equal cookies[:last_tab], 'timdex' end - test 'set_active_tab falls back to valid cookie when param is invalid' do - cookies[:last_tab] = 'primo' + test 'set_active_tab with invalid param uses default' do get root_path, params: { tab: 'foo' } assert_select '#tab-to-target' do refute_select '[value=?]', 'foo' - assert_select '[value=?]', 'primo' + assert_select '[value=?]', 'all' end - - assert_equal cookies[:last_tab], 'primo' end end diff --git a/test/controllers/application_controller_unit_test.rb b/test/controllers/application_controller_unit_test.rb index 99b3eace..47fd1f7c 100644 --- a/test/controllers/application_controller_unit_test.rb +++ b/test/controllers/application_controller_unit_test.rb @@ -29,37 +29,20 @@ class ApplicationControllerUnitTest < ActionController::TestCase refute @controller.send(:valid_tab?, '') end - test 'set_active_tab defaults @active_tab to all when no params or cookies are set' do + test 'set_active_tab defaults @active_tab to all when no params are set' do @controller.stubs(:params).returns({}) - @controller.stubs(:cookies).returns({}) @controller.set_active_tab assert_equal 'all', @controller.instance_variable_get(:@active_tab) end test 'set_active_tab sets @active_tab to tab when tab params is valid' do @controller.stubs(:params).returns({ tab: 'primo' }) - @controller.stubs(:cookies).returns({}) @controller.set_active_tab assert_equal 'primo', @controller.instance_variable_get(:@active_tab) end - test 'set_active_tab sets @active_tab to all when tab params is invalid and no cookie is set' do + test 'set_active_tab sets @active_tab to all when tab param is invalid' do @controller.stubs(:params).returns({ tab: 'supertab' }) - @controller.stubs(:cookies).returns({}) - @controller.set_active_tab - assert_equal 'all', @controller.instance_variable_get(:@active_tab) - end - - test 'set_active_tab sets @active_tab to cookie value when tab params is invalid and valid cookie is set' do - @controller.stubs(:params).returns({ tab: 'supertab' }) - @controller.stubs(:cookies).returns({ last_tab: 'timdex' }) - @controller.set_active_tab - assert_equal 'timdex', @controller.instance_variable_get(:@active_tab) - end - - test 'set_active_tab sets @active_tab to all value when tab params is invalid and cookie is invalid' do - @controller.stubs(:params).returns({ tab: 'supertab' }) - @controller.stubs(:cookies).returns({ last_tab: 'woohoo' }) @controller.set_active_tab assert_equal 'all', @controller.instance_variable_get(:@active_tab) end