Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
- prevent as many test failures due to the previous changes as possible.
  • Loading branch information
andysellick authored and leenagupte committed Dec 20, 2021
1 parent b920db5 commit 4158f25
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
8 changes: 4 additions & 4 deletions spec/components/brexit_cta_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def assert_link_with_text_in(selector, link, text)

it "shows standard brexit call to action" do
render_component({ content_item: content_item })
assert_select ".gem-c-contextual-sidebar__brexit-heading", text: "Brexit"
assert_link_with_text_in(".gem-c-contextual-sidebar__brexit-text", "/brexit", "Check what you need to do")
assert_select ".gem-c-contextual-sidebar__heading", text: "Brexit"
assert_link_with_text_in(".gem-c-contextual-sidebar__text", "/brexit", "Check what you need to do")
end

it "shows standard brexit call to action for Welsh pages" do
I18n.with_locale(:cy) { render_component({ content_item: welsh_content_item }) }
assert_select ".gem-c-contextual-sidebar__brexit-heading", text: "Brexit"
assert_link_with_text_in(".gem-c-contextual-sidebar__brexit-text", "/brexit.cy", "Gwiriwch beth mae angen i chi wneud")
assert_select ".gem-c-contextual-sidebar__heading", text: "Brexit"
assert_link_with_text_in(".gem-c-contextual-sidebar__text", "/brexit.cy", "Gwiriwch beth mae angen i chi wneud")
end
end
10 changes: 5 additions & 5 deletions spec/components/contextual_sidebar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def component_name
},
}
render_component(content_item: content_item)
assert_select ".gem-c-contextual-sidebar__brexit-cta"
assert_select ".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit"
end

it "does not render Brexit CTA when we have a document id exception" do
Expand All @@ -65,7 +65,7 @@ def component_name
},
}
render_component(content_item: content_item)
assert_select ".gem-c-contextual-sidebar__brexit-cta", 0
assert_select ".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit", 0
end

it "does not render Brexit CTA when we have a document type exception" do
Expand All @@ -85,7 +85,7 @@ def component_name
},
}
render_component(content_item: content_item)
assert_select ".gem-c-contextual-sidebar__brexit-cta", 0
assert_select ".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit", 0
end

it "does not render Brexit CTA when we have a taxon exception" do
Expand All @@ -112,7 +112,7 @@ def component_name
},
}
render_component(content_item: content_item)
assert_select ".gem-c-contextual-sidebar__brexit-cta", 0
assert_select ".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit", 0
end

it "does not render Brexit CTA when locale is not 'en' or 'cy'" do
Expand All @@ -139,6 +139,6 @@ def component_name
},
}
render_component(content_item: content_item)
assert_select ".gem-c-contextual-sidebar__brexit-cta", 0
assert_select ".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit", 0
end
end
36 changes: 36 additions & 0 deletions spec/components/covid_cta_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require "rails_helper"

describe "CovidCta", type: :view do
def component_name
"contextual_sidebar/covid_cta"
end

before(:each) do
I18n.locale = :en
end

let(:content_item) do
{
"base_path" => "/any-page",
"content_id" => SecureRandom.uuid,
}
end

let(:welsh_content_item) { content_item.merge("locale" => "cy") }

def assert_link_with_text_in(selector, link, text)
assert_select "#{selector} a[href=\"#{link}\"]", text: text
end

it "shows standard covid call to action" do
render_component({ content_item: content_item })
assert_select ".gem-c-contextual-sidebar__heading", text: "Covid"
assert_link_with_text_in(".gem-c-contextual-sidebar__text", "/covid", "Check what you need to do")
end

it "shows standard covid call to action for Welsh pages" do
I18n.with_locale(:cy) { render_component({ content_item: welsh_content_item }) }
assert_select ".gem-c-contextual-sidebar__heading", text: "Covid"
assert_link_with_text_in(".gem-c-contextual-sidebar__text", "/covid.cy", "Gwiriwch beth mae angen i chi wneud")
end
end
6 changes: 3 additions & 3 deletions spec/features/contextual_navigation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,14 @@ def then_i_see_the_brexit_individuals_contextual_breadcrumbs

def and_i_see_the_brexit_call_to_action
within ".gem-c-contextual-sidebar" do
expect(page).to have_selector(".gem-c-contextual-sidebar__brexit-cta")
expect(page).to have_css(".gem-c-contextual-sidebar__brexit-heading", text: I18n.t("components.related_navigation.transition.title"))
expect(page).to have_selector(".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit")
expect(page).to have_css(".gem-c-contextual-sidebar__heading", text: I18n.t("components.related_navigation.transition.title"))
end
end

def and_i_do_not_see_the_brexit_call_to_action
within ".gem-c-contextual-sidebar" do
expect(page).not_to have_selector(".gem-c-contextual-sidebar__brexit-cta")
expect(page).not_to have_selector(".gem-c-contextual-sidebar__cta.gem-c-contextual-sidebar__cta--brexit")
end
end

Expand Down

0 comments on commit 4158f25

Please sign in to comment.