Skip to content

Commit

Permalink
Add spec ensuring viewBox is properly capitalised (#462)
Browse files Browse the repository at this point in the history
XML (and therefore SVG) is case sensitive and viewBox is the correct
attribute name, based on @aliuk2012's suggestion.

Refs #459, #461
  • Loading branch information
peteryates authored Nov 16, 2023
2 parents 2e57116 + 5db5ad1 commit c8e97e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/components/govuk_component/footer_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
expect(rendered_content).to have_tag('footer', with: { class: component_css_class }) do
with_tag("div", with: { class: "govuk-footer__meta" }) do
with_tag("svg", with: { class: "govuk-footer__licence-logo", 'aria-hidden' => true })
expect(html).to contain_svgs_with_viewBox_attributes
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/components/govuk_component/header_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
specify 'the crown SVG is rendered along with no fallback image' do
expect(rendered_content).to have_tag('.govuk-header__logotype') do
with_tag('svg', with: { class: 'govuk-header__logotype-crown', 'aria-hidden' => true })
expect(html).to contain_svgs_with_viewBox_attributes
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/components/govuk_component/pagination_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@
expect(rendered_content).to have_tag("nav") do
with_tag("div", class: "govuk-pagination__prev")
with_tag("div", class: "govuk-pagination__next")

expect(html).to contain_svgs_with_viewBox_attributes
end
end

Expand All @@ -326,6 +328,7 @@
specify "has an arrow" do
expect(rendered_content).to have_tag(selector) do
with_tag("svg", with: { class: ["govuk-pagination__icon", "govuk-pagination__icon--#{page.suffix}"] })
expect(html).to contain_svgs_with_viewBox_attributes
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
specify 'the link contains an SVG chevron' do
expect(rendered_content).to have_tag('a') do
with_tag('svg', with: { 'aria-hidden' => true }) { with_tag('path') }
expect(html).to contain_svgs_with_viewBox_attributes
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/components/shared/custom_matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RSpec.configure do
RSpec::Matchers.define(:contain_svgs_with_viewBox_attributes) do
match do |element|
all_svgs = element.search("//xmlns:svg", "xmlns" => "http://www.w3.org/2000/svg")
svgs_with_viewbox = element.search("//xmlns:svg[@viewBox]", "xmlns" => "http://www.w3.org/2000/svg")

expect(all_svgs).to match_array(svgs_with_viewbox)
end

failure_message do |element|
"expected #{element} to contain <svg> element with a viewBox attribute"
end
end
end

0 comments on commit c8e97e8

Please sign in to comment.