diff --git a/app/controllers/ab_tests/explore_menu_ab_testable.rb b/app/controllers/ab_tests/explore_menu_ab_testable.rb new file mode 100644 index 000000000..f774acfcf --- /dev/null +++ b/app/controllers/ab_tests/explore_menu_ab_testable.rb @@ -0,0 +1,26 @@ +module AbTests::ExploreMenuAbTestable + CUSTOM_DIMENSION = 47 + + ALLOWED_VARIANTS = %w[A B Z].freeze + + def explore_menu_test + @explore_menu_test ||= GovukAbTesting::AbTest.new( + "ExploreMenuAbTestable", + dimension: CUSTOM_DIMENSION, + allowed_variants: ALLOWED_VARIANTS, + control_variant: "Z", + ) + end + + def explore_menu_variant + explore_menu_test.requested_variant(request.headers) + end + + def set_explore_menu_response + explore_menu_variant.configure_response(response) if explore_menu_testable? + end + + def explore_menu_testable? + explore_menu_variant.variant?("B") + end +end diff --git a/app/controllers/content_items_controller.rb b/app/controllers/content_items_controller.rb index f7c0bea41..330bfa7b7 100644 --- a/app/controllers/content_items_controller.rb +++ b/app/controllers/content_items_controller.rb @@ -1,5 +1,8 @@ class ContentItemsController < ApplicationController include GovukPersonalisation::AccountConcern + include Slimmer::Template + include AbTests::ExploreMenuAbTestable + rescue_from GdsApi::HTTPForbidden, with: :error_403 rescue_from GdsApi::HTTPNotFound, with: :error_notfound rescue_from GdsApi::HTTPGone, with: :error_410 @@ -10,6 +13,11 @@ class ContentItemsController < ApplicationController rescue_from PresenterBuilder::SpecialRouteReturned, with: :error_notfound rescue_from PresenterBuilder::GovernmentReturned, with: :error_notfound + before_action :set_explore_menu_response + after_action :set_slimmer_template + + helper_method :explore_menu_variant, :explore_menu_testable? + attr_accessor :content_item, :taxonomy_navigation def show @@ -47,6 +55,14 @@ def service_sign_in_options private + def set_slimmer_template + if explore_menu_testable? + slimmer_template "core_layout_explore_header" + else + slimmer_template "core_layout" + end + end + def is_history_page? @content_item.document_type == "history" end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index dc8d3f9ab..d7ca0896a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -27,10 +27,12 @@ <% end %> + <%= explore_menu_variant.analytics_meta_tag.html_safe if explore_menu_testable? %> + <%= yield :extra_head_content %> - <% unless content_for(:simple_header) %> + <% unless content_for(:simple_header) || explore_menu_testable? %> <%= render 'govuk_publishing_components/components/government_navigation', active: active_proposition %> <% end %> diff --git a/test/controllers/content_items_controller_test.rb b/test/controllers/content_items_controller_test.rb index 1261b4448..69fa078a7 100644 --- a/test/controllers/content_items_controller_test.rb +++ b/test/controllers/content_items_controller_test.rb @@ -3,6 +3,7 @@ class ContentItemsControllerTest < ActionController::TestCase include GdsApi::TestHelpers::ContentStore include GovukAbTesting::MinitestHelpers + include AbTests::ExploreMenuAbTestable test "routing handles paths with no format or locale" do assert_routing( @@ -366,6 +367,12 @@ class ContentItemsControllerTest < ActionController::TestCase assert_equal response.headers["Access-Control-Allow-Origin"], "*" end + test "request for Explore navigational super menu from slimmer" do + content_item = content_store_has_schema_example("case_study", "case_study") + get :show, params: { path: path_for(content_item) } + assert_response_not_modified_for_ab_test(AbTests::ExploreMenuAbTestable) + end + def path_for(content_item, locale = nil) base_path = content_item["base_path"].sub(/^\//, "") base_path.gsub!(/\.#{locale}$/, "") if locale