1
0

emoji_formatter_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'rails_helper'
  2. RSpec.describe EmojiFormatter do
  3. let!(:emoji) { Fabricate(:custom_emoji, shortcode: 'coolcat') }
  4. def preformat_text(str)
  5. TextFormatter.new(str).to_s
  6. end
  7. describe '#to_s' do
  8. subject { described_class.new(text, emojis).to_s }
  9. let(:emojis) { [emoji] }
  10. context 'given text that is not marked as html-safe' do
  11. let(:text) { 'Foo' }
  12. it 'raises an argument error' do
  13. expect { subject }.to raise_error ArgumentError
  14. end
  15. end
  16. context 'given text with an emoji shortcode at the start' do
  17. let(:text) { preformat_text(':coolcat: Beep boop') }
  18. it 'converts the shortcode to an image tag' do
  19. is_expected.to match(/<img rel="emoji" draggable="false" width="16" height="16" class="emojione custom-emoji" alt=":coolcat:"/)
  20. end
  21. end
  22. context 'given text with an emoji shortcode in the middle' do
  23. let(:text) { preformat_text('Beep :coolcat: boop') }
  24. it 'converts the shortcode to an image tag' do
  25. is_expected.to match(/Beep <img rel="emoji" draggable="false" width="16" height="16" class="emojione custom-emoji" alt=":coolcat:"/)
  26. end
  27. end
  28. context 'given text with concatenated emoji shortcodes' do
  29. let(:text) { preformat_text(':coolcat::coolcat:') }
  30. it 'does not touch the shortcodes' do
  31. is_expected.to match(/:coolcat::coolcat:/)
  32. end
  33. end
  34. context 'given text with an emoji shortcode at the end' do
  35. let(:text) { preformat_text('Beep boop :coolcat:') }
  36. it 'converts the shortcode to an image tag' do
  37. is_expected.to match(/boop <img rel="emoji" draggable="false" width="16" height="16" class="emojione custom-emoji" alt=":coolcat:"/)
  38. end
  39. end
  40. end
  41. end