require 'inline_svg/transform_pipeline'
describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
it "adds a role attribute to the SVG document" do
document = Nokogiri::XML::Document.parse('')
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value({})
expect(transformation.transform(document).to_html).to eq(
"\n"
)
end
context "aria-labelledby attribute" do
it "adds 'title' when a title element is present" do
document = Nokogiri::XML::Document.parse('')
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "some-salt").
and_return("some-id")
expect(transformation.transform(document).to_html).to eq(
"\n"
)
end
it "adds 'desc' when a description element is present" do
document = Nokogiri::XML::Document.parse('')
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "some-salt").
and_return("some-id")
expect(transformation.transform(document).to_html).to eq(
"\n"
)
end
it "adds both 'desc' and 'title' when title and description elements are present" do
document = Nokogiri::XML::Document.parse('')
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "some-salt").
and_return("some-id")
expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "some-salt").
and_return("some-other-id")
expect(transformation.transform(document).to_html).to eq(
"\n"
)
end
it "uses existing IDs when they exist" do
document = Nokogiri::XML::Document.parse('')
transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value("some-salt")
expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "some-salt").
and_return("some-id")
expect(InlineSvg::IdGenerator).to receive(:generate).with("my-desc", "some-salt").
and_return("some-other-id")
expect(transformation.transform(document).to_html).to eq(
"\n"
)
end
end
end