-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case to ensure viewBox attribute on root element of SVG
- Loading branch information
Showing
1 changed file
with
10 additions
and
8 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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'SVG files' do | ||
Dir[Rails.root.join('**', '*.svg')].reject { |f| f.include?('node_modules') }.each do |svg_path| | ||
relative_path = svg_path.sub(Rails.root.to_s, '') | ||
|
||
next if %w[vendor node_modules].include?(relative_path.split('/')[1]) | ||
|
||
files = Dir.glob('{app,public}/**/*.svg', base: Rails.root) | ||
files.reject! { |f| f.start_with? 'public/assets/' } | ||
files.each do |relative_path| | ||
describe relative_path do | ||
it 'does not contain inline style tags (that render poorly in IE due to CSP)' do | ||
doc = Nokogiri::XML(File.read(svg_path)) | ||
let(:subject) { Nokogiri::XML(File.read(Rails.root.join(relative_path))) } | ||
|
||
expect(doc.css('style')).to be_empty.or( | ||
it 'does not contain inline style tags (that render poorly in IE due to CSP)' do | ||
expect(subject.css('style')).to be_empty.or( | ||
have_attributes(text: match(%r{^\s*/\*\!lint-ignore\*/})), | ||
) | ||
end | ||
|
||
it 'defines viewBox attribute on root svg tag' do | ||
expect(subject.css(':root[viewBox]')).to be_present | ||
end | ||
end | ||
end | ||
end |