Skip to content

Commit

Permalink
Merge pull request #1009 from alphagov/remove-sidebar-on-b-sample-for…
Browse files Browse the repository at this point in the history
…-whitehall

Remove contextual sidebar on variant B for whitehall
  • Loading branch information
sihugh authored Jul 31, 2018
2 parents 6a845d2 + 9e0867f commit 6c16a66
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/controllers/concerns/content_pages_nav_ab_testable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def self.included(base)
base.helper_method(
:content_pages_nav_test_variant,
:show_new_navigation?,
:page_in_scope?
:page_in_scope?,
:should_show_sidebar?
)
base.after_action :set_test_response_header
end
Expand Down Expand Up @@ -48,4 +49,8 @@ def has_a_live_taxon?
@content_item.taxons.present? &&
@content_item.taxons.detect { |taxon| taxon["phase"] == "live" }
end

def should_show_sidebar?
content_pages_nav_test_variant.variant?("A") || @content_item.content_item.parsed_content['publishing_app'] != "whitehall"
end
end
8 changes: 5 additions & 3 deletions app/views/shared/_sidebar_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
end
%>

<div class="column-one-third">
<%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: content_item %>
</div>
<% if should_show_sidebar? %>
<div class="column-one-third">
<%= render 'govuk_publishing_components/components/contextual_sidebar', content_item: content_item %>
</div>
<% end %>
25 changes: 25 additions & 0 deletions test/controllers/content_pages_nav_ab_testable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ class ContentItemsControllerTest < ActionController::TestCase
end
end

test "should_show_sidebar? is true for variant A" do
content_item = content_store_has_schema_example("guide", "single-page-guide")
setup_ab_variant("ContentPagesNav", "A")
get :show, params: { path: path_for(content_item) }
assert @controller.should_show_sidebar?
end

test "should_show_sidebar? is true for variant B if the publishing app is not whitehall" do
content_item = content_store_has_schema_example("guide", "single-page-guide")
setup_ab_variant("ContentPagesNav", "B")
get :show, params: { path: path_for(content_item) }

assert @controller.should_show_sidebar?
end

test "should_show_sidebar? is false for variant B if the publishing app is whitehall" do
content_item = govuk_content_schema_example("guide", "single-page-guide").merge("publishing_app" => "whitehall")
content_store_has_item(content_item['base_path'], content_item)

setup_ab_variant("ContentPagesNav", "B")
get :show, params: { path: path_for(content_item) }

refute @controller.should_show_sidebar?
end

def ensure_ab_test_is_correctly_setup(test_variant, content_item)
content_store_has_item(content_item['base_path'], content_item)

Expand Down
24 changes: 24 additions & 0 deletions test/integration/content_pages_navigation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ class ContentPagesNavigationTest < ActionDispatch::IntegrationTest
end
end

test "ContentPagesNav variant A shows sidebar" do
stub_rummager
setup_sidebar_variant_a

setup_and_visit_content_from_publishing_app(publishing_app: 'publisher')
assert page.has_css?('.gem-c-related-navigation__main-heading', text: 'Related content')
end

test "ContentPagesNav variant B hides sidebar" do
stub_rummager
setup_sidebar_variant_b

setup_and_visit_content_from_publishing_app(publishing_app: 'whitehall')
refute page.has_css?('.gem-c-related-navigation__main-heading', text: 'Related content')
end

test "shows the Services section title and documents with tracking" do
stub_rummager
stub_empty_guidance
Expand Down Expand Up @@ -261,6 +277,14 @@ def setup_variant_b
ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(true)
end

def setup_sidebar_variant_a
ContentItemsController.any_instance.stubs(:should_show_sidebar?).returns(true)
end

def setup_sidebar_variant_b
ContentItemsController.any_instance.stubs(:should_show_sidebar?).returns(false)
end

def schema_type
"guide"
end
Expand Down
16 changes: 16 additions & 0 deletions test/support/content_pages_nav_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ def stub_empty_rummager
)
end

def setup_and_visit_content_from_publishing_app(publishing_app: nil)
content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: schema_type) do |payload|
payload.merge('publishing_app' => publishing_app) unless publishing_app.nil?
payload
end

content_id = content_item["content_id"]
path = content_item["base_path"]

stub_request(:get, %r{#{path}})
.to_return(status: 200, body: content_item.to_json, headers: {})
visit path

assert_selector %{meta[name="govuk:content-id"][content="#{content_id}"}, visible: false
end

SINGLE_TAXON = [
{
"base_path" => "/education/becoming-an-apprentice",
Expand Down

0 comments on commit 6c16a66

Please sign in to comment.