-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
¨Oscar Wyatt¨
committed
Jul 13, 2021
1 parent
a8345ed
commit 3399f9f
Showing
7 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
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,39 @@ | ||
module SabPagesTestable | ||
CUSTOM_DIMENSION = 65 | ||
|
||
def self.included(base) | ||
base.helper_method( | ||
:sab_page_variant, | ||
:is_testable_sab_page?, | ||
:should_show_sab_intervention?, | ||
) | ||
base.after_action :set_test_response_header | ||
end | ||
|
||
def sab_page_variant | ||
@sab_page_variant ||= sab_page_test.requested_variant(request.headers) | ||
end | ||
|
||
def is_testable_sab_page? | ||
request.headers["HTTP_GOVUK_ABTEST_ISSTARTABUSINESSPAGE"] == "true" | ||
end | ||
|
||
def should_show_sab_intervention? | ||
sab_page_variant.variant?("B") && is_testable_sab_page? | ||
end | ||
|
||
private | ||
|
||
def sab_page_test | ||
@sab_page_test ||= GovukAbTesting::AbTest.new( | ||
"StartABusinessSegment", | ||
dimension: CUSTOM_DIMENSION, | ||
allowed_variants: %w[A B C], | ||
control_variant: "A", | ||
) | ||
end | ||
|
||
def set_test_response_header | ||
sab_page_variant.configure_response(response) | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
require "test_helper" | ||
|
||
class ContentItemsControllerTest < ActionController::TestCase | ||
include GovukAbTesting::MinitestHelpers | ||
INTERVENTION_CSS_SELECTOR = "gem-c-intervention".freeze | ||
|
||
test "shows intervention for variant B" do | ||
for_each_schema do |schema| | ||
with_variant StartABusinessSegment: "B" do | ||
with_is_sab_page_header("true") do | ||
set_up_and_visit_content_item_for_schema(schema) | ||
assert has_intervention_css_selector | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "doesn't show intervention for variant A" do | ||
for_each_schema do |schema| | ||
with_variant StartABusinessSegment: "A" do | ||
with_is_sab_page_header("true") do | ||
set_up_and_visit_content_item_for_schema(schema) | ||
|
||
assert_not has_intervention_css_selector | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "doesn't show intervention for variant C" do | ||
for_each_schema do |schema| | ||
with_variant StartABusinessSegment: "C" do | ||
with_is_sab_page_header("true") do | ||
set_up_and_visit_content_item_for_schema(schema) | ||
|
||
assert_not has_intervention_css_selector | ||
end | ||
end | ||
end | ||
end | ||
|
||
test "doesn't show intervention if SaB header is not included" do | ||
for_each_schema do |schema| | ||
with_variant StartABusinessSegment: "B", assert_meta_tag: false do | ||
set_up_and_visit_content_item_for_schema(schema) | ||
|
||
assert_not has_intervention_css_selector | ||
end | ||
end | ||
end | ||
|
||
test "doesn't show intervention if SaB header is set to false" do | ||
for_each_schema do |schema| | ||
with_variant StartABusinessSegment: "B", assert_meta_tag: false do | ||
with_is_sab_page_header("false") do | ||
set_up_and_visit_content_item_for_schema(schema) | ||
|
||
assert_not has_intervention_css_selector | ||
end | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_up_and_visit_content_item_for_schema(schema) | ||
content_item = content_store_has_schema_example(schema, schema) | ||
stub_content_store_has_item(content_item["base_path"], content_item) | ||
path = content_item["base_path"][1..] | ||
|
||
get :show, params: { path: path } | ||
end | ||
|
||
def has_intervention_css_selector | ||
response.body.include?(INTERVENTION_CSS_SELECTOR) | ||
end | ||
|
||
def with_is_sab_page_header(is_sab_header) | ||
request.headers["HTTP_GOVUK_ABTEST_ISSTARTABUSINESSPAGE"] = is_sab_header | ||
yield | ||
end | ||
|
||
def for_each_schema(&block) | ||
%w[guide answer document_collection].each(&block) | ||
end | ||
end |