# frozen_string_literal: true
require 'spec_helper'
RSpec.describe HtmlSanitizer do
subject { described_class }
context "when HTML has supported tags" do
it "keeps supported regular tags" do
supported_tags = %w[h1 h2 h3 h4 div p b i u a strong em del pre blockquote ul ol li figure]
supported_tags.each do |tag|
html = "<#{tag}>Content#{tag}>"
sanitized_html = subject.sanitize(html)
expect(sanitized_html).to eq(html), "Expected '#{tag}' to be preserved."
end
end
it "keeps supported void tags" do
supported_tags = %w[br hr]
supported_tags.each do |tag|
html = "<#{tag}>"
sanitized_html = subject.sanitize(html)
expect(sanitized_html).to eq(html), "Expected '#{tag}' to be preserved."
end
end
it "handles nested tags" do
html = '
Item 1
Item 2
'
expect(subject.sanitize(html)).to eq(html)
end
end
context "when HTML has dangerous tags" do
it "removes script tags" do
html = "Hello !"
expect(subject.sanitize(html)).to eq "Hello alert!"
end
it "removes iframe tags" do
html = "Content "
expect(subject.sanitize(html)).to eq "Content "
end
it "removes object tags" do
html = ""
expect(subject.sanitize(html)).to eq ""
end
it "removes embed tags" do
html = "