Skip to content

Commit

Permalink
Update calculators_helper_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVajnagi authored Jan 20, 2025
1 parent 477d2b2 commit 8c7b500
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions spec/helpers/calculators/calculators_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,25 @@
'<img src="image.png" alt="example image" style="width:100px;">'
end

let(:result) { |html| helper.sanitized_notes(html) }

it "allows specific tags and attributes" do
expect(result(valid_html)).to include('<p class="text-bold">')
expect(result(valid_html)).to include("<strong>bold</strong>")
expect(result(valid_html)).to include("<em>italic</em>")
expect(result(valid_html)).to include('<a href="http://example.com" target="_blank">Link</a>')
expect(helper.sanitized_notes(valid_html)).to include('<p class="text-bold">')
expect(helper.sanitized_notes(valid_html)).to include("<strong>bold</strong>")
expect(helper.sanitized_notes(valid_html)).to include("<em>italic</em>")
expect(helper.sanitized_notes(valid_html)).to include('<a href="http://example.com" target="_blank">Link</a>')
end

it "removes disallowed tags" do
expect(result(invalid_html)).not_to include("<script>")
expect(helper.sanitized_notes(invalid_html)).not_to include("<script>")
end

it "removes disallowed tags but keeps allowed tags and attributes" do
expect(result(mixed_html)).to include("<p>This is <strong>bold</strong>")
expect(result(mixed_html)).not_to include("<script>")
expect(result(mixed_html)).to include('<a href="http://example.com">Link</a>')
expect(helper.sanitized_notes(mixed_html)).to include("<p>This is <strong>bold</strong>")
expect(helper.sanitized_notes(mixed_html)).not_to include("<script>")
expect(helper.sanitized_notes(mixed_html)).to include('<a href="http://example.com">Link</a>')
end

it "does not remove allowed attributes from tags" do
expect(result(html_with_attributes)).to eq('<img src="image.png" alt="example image" style="width:100px;">')
expect(helper.sanitized_notes(html_with_attributes)).to eq('<img src="image.png" alt="example image" style="width:100px;">')
end
end
end

0 comments on commit 8c7b500

Please sign in to comment.