Skip to content

Commit

Permalink
Simplify control data code, and add tests
Browse files Browse the repository at this point in the history
For variants A and B, all browse pages will contain popular links.
For variants C and Z ie the control state, only business and benefits will
contain popular links. The other 14 will default to hiding popular tasks
entirely - as this is the default behaviour currently live on GOV.UK

This commit adds specs to highlight this, and simplifies the existing code. There
is no behavioural change.
  • Loading branch information
hannako committed Aug 21, 2024
1 parent a9f92eb commit d97f9e0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 30 deletions.
42 changes: 12 additions & 30 deletions app/helpers/browse_helper.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
module BrowseHelper
def variant_a_popular_links?(slug)
I18n.exists?("#{slug}.variant_a", scope: "browse.popular_links")
end

def variant_a_popular_links(slug)
I18n.t("#{slug}.variant_a", scope: "browse.popular_links")
end

def variant_b_popular_links?(slug)
I18n.exists?("#{slug}.variant_b", scope: "browse.popular_links")
end

def variant_b_popular_links(slug)
I18n.t("#{slug}.variant_b", scope: "browse.popular_links")
def display_popular_links_for_slug?(slug)
popular_links_data(slug).present?
end

def control_popular_links?(slug)
def control_key_is_present?(slug)
I18n.exists?("#{slug}.control", scope: "browse.popular_links")
end

def control_popular_links(slug)
I18n.t("#{slug}.control", scope: "browse.popular_links")
end

def display_popular_links_for_slug?(slug)
if popular_tasks_variant_a_page?
variant_a_popular_links?(slug)
elsif popular_tasks_variant_b_page?
variant_b_popular_links?(slug)
def control_data(slug)
if control_key_is_present?(slug)
I18n.t("browse.popular_links.#{slug}.control")
else
control_popular_links?(slug)
[]
end
end

def variant_popular_links_for_slug(slug)
def popular_links_data(slug)
if popular_tasks_variant_a_page?
variant_a_popular_links(slug)
I18n.t("browse.popular_links.#{slug}.variant_a")
elsif popular_tasks_variant_b_page?
variant_b_popular_links(slug)
I18n.t("browse.popular_links.#{slug}.variant_b")
else
control_popular_links(slug)
control_data(slug)
end
end

def popular_links_for_slug(slug)
links = variant_popular_links_for_slug(slug)
links = popular_links_data(slug)
count = links.length
links.map.with_index(1) do |link, index|
{
Expand Down
68 changes: 68 additions & 0 deletions spec/features/mainstream_browsing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,74 @@
end
end

context "Control variants" do
scenario "when visiting business and benefits i.e. pages that originally had popular tasks" do
with_variant PopularTasks: "C" do
content_item["base_path"] = "/browse/business"
stub_content_store_has_item("/browse/business", content_item)
visit "/browse/business"
expect(page).to have_content("Popular tasks")

links = I18n.t("browse.popular_links.business.control")
links.each do |link|
expect(page).to have_link(link["title"])
end

content_item["base_path"] = "/browse/benefits"
stub_content_store_has_item("/browse/benefits", content_item)
visit "/browse/benefits"
expect(page).to have_content("Popular tasks")

links = I18n.t("browse.popular_links.benefits.control")
links.each do |link|
expect(page).to have_link(link["title"])
end
end

with_variant PopularTasks: "Z" do
content_item["base_path"] = "/browse/business"
stub_content_store_has_item("/browse/business", content_item)
visit "/browse/business"
expect(page).to have_content("Popular tasks")

links = I18n.t("browse.popular_links.business.control")
links.each do |link|
expect(page).to have_link(link["title"])
end

content_item["base_path"] = "/browse/benefits"
stub_content_store_has_item("/browse/benefits", content_item)
visit "/browse/benefits"
expect(page).to have_content("Popular tasks")

links = I18n.t("browse.popular_links.benefits.control")
links.each do |link|
expect(page).to have_link(link["title"])
end
end
end

scenario "when visiting pages that originally had no popular tasks" do
slugs_with_no_popular_tasks_originally = browse_slugs - %i[benefits business]

slugs_with_no_popular_tasks_originally.each do |browse_slug|
browse_path = "/browse/#{browse_slug}"
content_item["base_path"] = browse_path
stub_content_store_has_item(browse_path, content_item)

with_variant PopularTasks: "C" do
visit browse_path
expect(page).not_to have_content("Popular tasks")
end

with_variant PopularTasks: "Z" do
visit browse_path
expect(page).not_to have_content("Popular tasks")
end
end
end
end

browse_slugs.each do |browse_slug|
browse_path = "/browse/#{browse_slug}"

Expand Down

0 comments on commit d97f9e0

Please sign in to comment.