Skip to content

Commit

Permalink
Merge pull request #3583 from alphagov/remove-autocomplete-ab
Browse files Browse the repository at this point in the history
All content finder autocomplete: Finish AB test
  • Loading branch information
kevindew authored Dec 11, 2024
2 parents d75ace4 + 5c5cb5b commit 872dd78
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 44 deletions.
22 changes: 0 additions & 22 deletions app/controllers/ab_test/search_autocomplete_ab_testable.rb

This file was deleted.

9 changes: 5 additions & 4 deletions app/controllers/finders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
class FindersController < ApplicationController
layout "finder_layout"

include AbTest::SearchAutocompleteAbTestable

before_action do
set_expiry(content_item)
set_search_autocomplete_ab_test_requested_variant if content_item.all_content_finder?
end

def show
Expand Down Expand Up @@ -61,7 +58,7 @@ def show_page_variables
@sort_presenter = sort_presenter
@pagination = pagination_presenter
@spelling_suggestion_presenter = spelling_suggestion_presenter
@ab_test_search_component = use_autocomplete? ? "search_with_autocomplete" : "search"
@search_component = use_autocomplete? ? "search_with_autocomplete" : "search"
end

private
Expand Down Expand Up @@ -390,4 +387,8 @@ def filter_query_array(arr)
arr.reject { |v| v == "all" }.compact.presence
end
end

def use_autocomplete?
true unless ENV["GOVUK_DISABLE_SEARCH_AUTOCOMPLETE"]
end
end
3 changes: 1 addition & 2 deletions app/views/finders/show_all_content_finder.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<meta name="govuk:discovery-engine-attribution-token" content="<%= result_set_presenter.discovery_engine_attribution_token %>">
<% end %>
<meta name="govuk:spelling-suggestion" content="<%= @spelling_suggestion_presenter.suggestions.first&.fetch(:keywords, "") %>">
<%= @requested_variant.analytics_meta_tag.html_safe if @requested_variant.present? %>
<% end %>
<% content_for :meta_title, content_item.title %>

Expand Down Expand Up @@ -54,7 +53,7 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<div id="keywords" role="search" aria-label="Sitewide">
<%= render "govuk_publishing_components/components/#{@ab_test_search_component}", {
<%= render "govuk_publishing_components/components/#{@search_component}", {
id: "finder-keyword-search",
name: "keywords",
type: 'search',
Expand Down
25 changes: 9 additions & 16 deletions spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,29 +252,22 @@
expect(response).to render_template("finders/show_all_content_finder")
end

describe "SearchAutocomplete AB test" do
it "does not render the search_with_autocomplete component in the A variant" do
with_variant SearchAutocomplete: "A" do
describe "search autocomplete" do
it "renders the search autocomplete when enabled" do
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: nil do
get :show, params: { slug: "search/all", keywords: "hello" }
end

expect(response.body).not_to include('"gem-c-search-with-autocomplete"')
end

it "renders the search_with_autocomplete component in the B variant" do
with_variant SearchAutocomplete: "B" do
get :show, params: { slug: "search/all", keywords: "hello" }
expect(response.body).to include("gem-c-search-with-autocomplete")
end

expect(response.body).to include('"gem-c-search-with-autocomplete"')
end

it "does not render the search_with_autocomplete component in the Z variant" do
with_variant SearchAutocomplete: "Z" do
it "does not render the autocomplete when disabled" do
ClimateControl.modify GOVUK_DISABLE_SEARCH_AUTOCOMPLETE: "1" do
get :show, params: { slug: "search/all", keywords: "hello" }
end

expect(response.body).not_to include('"gem-c-search-with-autocomplete"')
expect(response.body).not_to include("gem-c-search-with-autocomplete")
expect(response.body).to include("gem-c-search")
end
end
end

Expand Down

0 comments on commit 872dd78

Please sign in to comment.