SVG helper specs
Wed Dec 14 2022 21:08:03 GMT+0000 (Coordinated Universal Time)
Saved by
@metamoni
#ruby
#rubyonrails
describe SvgHelper do
include SvgHelper
describe '#inline_svg' do
subject { inline_svg(svg, options) }
let(:svg) do
'<svg viewBox="0 0 10 20"><circle cx="50" cy="50" r="50"/></svg>'
end
let(:parsed_file) { Nokogiri::HTML::DocumentFragment.parse(svg) }
before do
allow(File).to receive(:read).and_return(parsed_file)
end
context "when no options are passed" do
let(:options) { {} }
it "returns hidden svg" do
expect(subject).to include 'aria-hidden="true"'
end
end
context "when options are passed" do
let(:options) { { title: 'test', style: 'background-color:Blue' } }
it "returns svg with a role of img" do
expect(subject).to include 'role="img"'
end
it "adds title with correct id" do
expect(subject).to include '<title id="svg-title">test</title>'
end
it "adds aria-labelledby attribute" do
expect(subject).to include 'aria-labelledby="svg-title"'
end
it "updates svg styles" do
expect(subject).to include 'style="background-color:Blue"'
end
end
end
end
content_copyCOPY
Specs for [Rails SVG helper](https://www.thiscodeworks.com/svg-helper-ruby-rubyonrails/639a39fa4eef07001571e0b1)
Comments