Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content navigation multivariate test
Start with 4 variants: original, no nav, taxonomy nav, mainstream nav * Follow “concern” pattern setup in #513 for task list AB test * Only content with the document types listed are part of the test * The content must also be tagged to a taxon * Use a “universal_navigation” variant for all multivariate tests except original – they are largely the same, significant differences with original shouldn’t be repeated
- Loading branch information
Showing
5 changed files
with
174 additions
and
5 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
app/controllers/concerns/content_navigation_ab_testable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
module ContentNavigationABTestable | ||
CONTENT_NAVIGATION_DIMENSION = 67 | ||
CONTENT_NAVIGATION_ORIGINAL = "Original".freeze | ||
CONTENT_NAVIGATION_UNIVERSAL_NO_NAVIGATION = "UniversalNoNav".freeze | ||
CONTENT_NAVIGATION_UNIVERSAL_MAINSTREAM_NAVIGATION = "UniversalMainstreamNav".freeze | ||
CONTENT_NAVIGATION_UNIVERSAL_TAXON_NAVIGATION = "UniversalTaxonNav".freeze | ||
|
||
CONTENT_NAVIGATION_ALLOWED_VARIANTS = [ | ||
CONTENT_NAVIGATION_ORIGINAL, | ||
CONTENT_NAVIGATION_UNIVERSAL_NO_NAVIGATION, | ||
CONTENT_NAVIGATION_UNIVERSAL_MAINSTREAM_NAVIGATION, | ||
CONTENT_NAVIGATION_UNIVERSAL_TAXON_NAVIGATION | ||
].freeze | ||
|
||
GUIDANCE_DOCUMENT_TYPES = %w( | ||
answer | ||
guide | ||
detailed_guide | ||
statutory_guidance | ||
).freeze | ||
|
||
def self.included(base) | ||
base.helper_method( | ||
:content_navigation_variant, | ||
:content_navigation_ab_test_applies?, | ||
:content_navigation_test_original_variant?, | ||
:universal_navigation_without_nav?, | ||
:universal_navigation_with_taxon_nav?, | ||
:universal_navigation_with_mainstream_nav? | ||
) | ||
|
||
base.after_action :set_content_navigation_response_header | ||
end | ||
|
||
def content_navigation_ab_test | ||
@content_navigation_ab_test ||= | ||
GovukAbTesting::AbTest.new( | ||
"ContentNavigation", | ||
dimension: CONTENT_NAVIGATION_DIMENSION, | ||
allowed_variants: CONTENT_NAVIGATION_ALLOWED_VARIANTS | ||
) | ||
end | ||
|
||
# Universal navigation: | ||
# https://gov-uk.atlassian.net/wiki/spaces/GFED/pages/186351726/Sprint+1+designs | ||
# | ||
# Universal navigation must only be shown when: | ||
# * in the multivariate test | ||
# * not showing the original variant | ||
def should_present_universal_navigation? | ||
content_navigation_ab_test_applies? && !content_navigation_test_original_variant? | ||
end | ||
|
||
def content_navigation_ab_test_applies? | ||
@content_item.tagged_to_a_taxon? && content_document_type_is_guidance? | ||
end | ||
|
||
def content_document_type_is_guidance? | ||
GUIDANCE_DOCUMENT_TYPES.include? @content_item.document_type | ||
end | ||
|
||
def content_navigation_test_original_variant? | ||
content_navigation_variant.variant?(CONTENT_NAVIGATION_ORIGINAL) | ||
end | ||
|
||
def universal_navigation_without_nav? | ||
content_navigation_variant.variant?(CONTENT_NAVIGATION_UNIVERSAL_NO_NAVIGATION) | ||
end | ||
|
||
def universal_navigation_with_taxon_nav? | ||
content_navigation_variant.variant?(CONTENT_NAVIGATION_UNIVERSAL_TAXON_NAVIGATION) | ||
end | ||
|
||
def universal_navigation_with_mainstream_nav? | ||
content_navigation_variant.variant?(CONTENT_NAVIGATION_UNIVERSAL_MAINSTREAM_NAVIGATION) | ||
end | ||
|
||
def content_navigation_variant | ||
@content_navigation_variant ||= | ||
content_navigation_ab_test.requested_variant(request.headers) | ||
end | ||
|
||
def set_content_navigation_response_header | ||
content_navigation_variant.configure_response(response) if content_navigation_ab_test_applies? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
test/controllers/content_navigation_ab_testing_content_items_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'test_helper' | ||
|
||
class ContentItemsControllerTest < ActionController::TestCase | ||
include GdsApi::TestHelpers::ContentStore | ||
include GovukAbTesting::MinitestHelpers | ||
|
||
ContentItemsController::GUIDANCE_DOCUMENT_TYPES.each do |document_type| | ||
schema_name = document_type == 'statutory_guidance' ? 'publication' : document_type | ||
|
||
test "does not show universal navigation when no taxons are tagged to #{document_type}" do | ||
content_item = content_store_has_schema_example(schema_name, schema_name) | ||
path = "government/abtest/#{schema_name}" | ||
content_item['base_path'] = "/#{path}" | ||
content_item['links'] = {} | ||
|
||
content_store_has_item(content_item['base_path'], content_item) | ||
|
||
setup_ab_variant('ContentNavigation', ContentItemsController::CONTENT_NAVIGATION_ORIGINAL) | ||
get :show, params: { path: path } | ||
assert_equal [], @request.variant | ||
assert_response_not_modified_for_ab_test('ContentNavigation') | ||
end | ||
|
||
test "#{document_type} honours content navigation AB Testing cookie" do | ||
content_item = content_store_has_schema_example(schema_name, schema_name) | ||
path = "government/abtest/#{schema_name}" | ||
content_item['document_type'] = document_type | ||
content_item['base_path'] = "/#{path}" | ||
content_item['links'] = { | ||
'taxons' => [ | ||
{ | ||
'title' => 'A Taxon', | ||
'base_path' => '/a-taxon', | ||
} | ||
] | ||
} | ||
|
||
content_store_has_item(content_item['base_path'], content_item) | ||
|
||
ContentItemsController::CONTENT_NAVIGATION_ALLOWED_VARIANTS.each do |variant| | ||
with_variant ContentNavigation: variant do | ||
get :show, params: { path: path } | ||
requested = @controller.content_navigation_ab_test.requested_variant(request.headers) | ||
assert_response 200 | ||
assert requested.variant?(variant) | ||
|
||
if variant == ContentItemsController::CONTENT_NAVIGATION_ORIGINAL | ||
assert_equal [:taxonomy_navigation], @request.variant | ||
else | ||
assert_equal [:universal_navigation], @request.variant | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "defaults to original view without AB testing cookie for #{document_type}" do | ||
content_item = content_store_has_schema_example(schema_name, schema_name) | ||
path = "government/abtest/#{schema_name}" | ||
content_item['document_type'] = document_type | ||
content_item['base_path'] = "/#{path}" | ||
content_item['links'] = {} | ||
content_store_has_item(content_item['base_path'], content_item) | ||
|
||
get :show, params: { path: path } | ||
assert_response 200 | ||
assert_equal [], @request.variant | ||
end | ||
end | ||
end |