debian-mirror-gitlab/spec/lib/banzai/filter/emoji_filter_spec.rb

102 lines
2.8 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Banzai::Filter::EmojiFilter do
2015-12-23 02:04:40 +05:30
include FilterSpecHelper
2021-04-17 20:07:23 +05:30
it_behaves_like 'emoji filter' do
let(:emoji_name) { ':+1:' }
end
2016-11-03 12:29:30 +05:30
it 'replaces supported name emoji' do
2015-12-23 02:04:40 +05:30
doc = filter('<p>:heart:</p>')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').first.text).to eq '❤'
2015-12-23 02:04:40 +05:30
end
2016-11-03 12:29:30 +05:30
it 'replaces supported unicode emoji' do
doc = filter('<p>❤️</p>')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').first.text).to eq '❤'
2016-11-03 12:29:30 +05:30
end
2021-01-29 00:20:46 +05:30
it 'ignores unicode versions of trademark, copyright, and registered trademark' do
exp = act = '<p>™ © ®</p>'
doc = filter(act)
expect(doc.to_html).to match Regexp.escape(exp)
end
it 'replaces name versions of trademark, copyright, and registered trademark' do
doc = filter('<p>:tm: :copyright: :registered:</p>')
expect(doc.css('gl-emoji')[0].text).to eq '™'
expect(doc.css('gl-emoji')[1].text).to eq '©'
expect(doc.css('gl-emoji')[2].text).to eq '®'
end
2015-12-23 02:04:40 +05:30
it 'correctly encodes the URL' do
doc = filter('<p>:+1:</p>')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').first.text).to eq '👍'
2015-12-23 02:04:40 +05:30
end
2016-11-03 12:29:30 +05:30
it 'correctly encodes unicode to the URL' do
doc = filter('<p>👍</p>')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').first.text).to eq '👍'
2016-11-03 12:29:30 +05:30
end
2015-12-23 02:04:40 +05:30
it 'matches at the start of a string' do
doc = filter(':+1:')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 1
2015-12-23 02:04:40 +05:30
end
2016-11-03 12:29:30 +05:30
it 'unicode matches at the start of a string' do
doc = filter("'👍'")
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 1
2016-11-03 12:29:30 +05:30
end
2015-12-23 02:04:40 +05:30
it 'matches at the end of a string' do
doc = filter('This gets a :-1:')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 1
2015-12-23 02:04:40 +05:30
end
2016-11-03 12:29:30 +05:30
it 'unicode matches at the end of a string' do
doc = filter('This gets a 👍')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 1
2016-11-03 12:29:30 +05:30
end
it 'unicode matches with adjacent text' do
doc = filter('+1 (👍)')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 1
2016-11-03 12:29:30 +05:30
end
2017-08-17 22:00:37 +05:30
it 'does not match multiple emoji in a row' do
2015-12-23 02:04:40 +05:30
doc = filter(':see_no_evil::hear_no_evil::speak_no_evil:')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 0
2015-12-23 02:04:40 +05:30
end
2016-11-03 12:29:30 +05:30
it 'unicode matches multiple emoji in a row' do
doc = filter("'🙈🙉🙊'")
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 3
2016-11-03 12:29:30 +05:30
end
it 'mixed matches multiple emoji in a row' do
doc = filter("'🙈:see_no_evil:🙉:hear_no_evil:🙊:speak_no_evil:'")
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').size).to eq 6
2016-11-03 12:29:30 +05:30
end
2017-08-17 22:00:37 +05:30
it 'has a data-name attribute' do
2015-12-23 02:04:40 +05:30
doc = filter(':-1:')
2017-08-17 22:00:37 +05:30
expect(doc.css('gl-emoji').first.attr('data-name')).to eq 'thumbsdown'
2015-12-23 02:04:40 +05:30
end
2017-08-17 22:00:37 +05:30
it 'has a data-unicode-version attribute' do
doc = filter(':-1:')
expect(doc.css('gl-emoji').first.attr('data-unicode-version')).to eq '6.0'
2016-11-03 12:29:30 +05:30
end
it 'unicode keeps whitespace intact' do
doc = filter('This deserves a 🎱, big time.')
2017-08-17 22:00:37 +05:30
expect(doc.to_html).to match(/^This deserves a <gl-emoji.+>, big time\.\z/)
2016-11-03 12:29:30 +05:30
end
2015-12-23 02:04:40 +05:30
end