From da3cec0ddb7873980abd76919b01c66f457c8dd3 Mon Sep 17 00:00:00 2001
From: chao-xian <kelvin.gan@digital.cabinet-office.gov.uk>
Date: Tue, 22 Jun 2021 22:18:05 +0100
Subject: [PATCH 1/2] Add ExploreMenuABTestable AB Test code

For the ContentItemsController to allow views to display a different template from Static that includes the new header if users are in the B variant.
---
 .../ab_tests/explore_menu_ab_testable.rb      | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 app/controllers/ab_tests/explore_menu_ab_testable.rb

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

From 945b49cb97eb92ebc7e459de0a55285b214fe560 Mon Sep 17 00:00:00 2001
From: chao-xian <kelvin.gan@digital.cabinet-office.gov.uk>
Date: Mon, 5 Jul 2021 12:38:45 +0100
Subject: [PATCH 2/2] Update to show new Explore Super Menu Header

For users who are in the B variant of the AB Test, they get a template from Static that has the new Explore Super-menu Navigation.
---
 app/controllers/content_items_controller.rb      | 16 ++++++++++++++++
 app/views/layouts/application.html.erb           |  4 +++-
 .../controllers/content_items_controller_test.rb |  7 +++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

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 @@
     <meta name="description" content="<%= strip_tags(@content_item.description) %>" />
   <% end %>
 
+  <%= explore_menu_variant.analytics_meta_tag.html_safe if explore_menu_testable? %>
+
   <%= yield :extra_head_content %>
 </head>
 <body>
-  <% 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