You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

  1. require 'rails_helper'
  2. RSpec.describe Glitch::KeywordMuteHelper do
  3. describe '#matches?' do
  4. let(:alice) { Fabricate(:account, username: 'alice').tap(&:save!) }
  5. let(:helper) { Glitch::KeywordMuteHelper.new(alice) }
  6. it 'ignores names of HTML tags in status text' do
  7. status = Fabricate(:status, text: '<addr>uh example</addr>')
  8. Glitch::KeywordMute.create!(account: alice, keyword: 'addr')
  9. expect(helper.matches?(status)).to be false
  10. end
  11. it 'ignores properties of HTML tags in status text' do
  12. status = Fabricate(:status, text: '<a href="https://www.example.org">uh example</a>')
  13. Glitch::KeywordMute.create!(account: alice, keyword: 'href')
  14. expect(helper.matches?(status)).to be false
  15. end
  16. it 'matches text inside HTML tags' do
  17. status = Fabricate(:status, text: '<p>HEY THIS IS SOMETHING ANNOYING</p>')
  18. Glitch::KeywordMute.create!(account: alice, keyword: 'annoying')
  19. expect(helper.matches?(status)).to be true
  20. end
  21. it 'matches < in HTML-stripped text' do
  22. status = Fabricate(:status, text: '<p>I <3 oats</p>')
  23. Glitch::KeywordMute.create!(account: alice, keyword: '<3')
  24. expect(helper.matches?(status)).to be true
  25. end
  26. it 'matches &lt; in HTML text' do
  27. status = Fabricate(:status, text: '<p>I &lt;3 oats</p>')
  28. Glitch::KeywordMute.create!(account: alice, keyword: '<3')
  29. expect(helper.matches?(status)).to be true
  30. end
  31. it 'matches link hrefs in HTML text' do
  32. status = Fabricate(:status, text: '<p><a href="https://example.com/it-was-milk">yep</a></p>')
  33. Glitch::KeywordMute.create!(account: alice, keyword: 'milk')
  34. expect(helper.matches?(status)).to be true
  35. end
  36. end
  37. end