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.

52 lines
1.8 KiB

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