html_aware_formatter_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe HtmlAwareFormatter do
  4. describe '#to_s' do
  5. subject { described_class.new(text, local).to_s }
  6. context 'when local' do
  7. let(:local) { true }
  8. let(:text) { 'Foo bar' }
  9. it 'returns formatted text' do
  10. expect(subject).to eq '<p>Foo bar</p>'
  11. end
  12. end
  13. context 'when remote' do
  14. let(:local) { false }
  15. context 'when given plain text' do
  16. let(:text) { 'Beep boop' }
  17. it 'keeps the plain text' do
  18. expect(subject).to include 'Beep boop'
  19. end
  20. end
  21. context 'when given text containing script tags' do
  22. let(:text) { '<script>alert("Hello")</script>' }
  23. it 'strips the scripts' do
  24. expect(subject).to_not include '<script>alert("Hello")</script>'
  25. end
  26. end
  27. context 'when given text containing malicious classes' do
  28. let(:text) { '<span class="mention status__content__spoiler-link">Show more</span>' }
  29. it 'strips the malicious classes' do
  30. expect(subject).to_not include 'status__content__spoiler-link'
  31. end
  32. end
  33. end
  34. end
  35. end