2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Banzai::Filter::EmojiFilter do
|
2015-12-23 02:04:40 +05:30
|
|
|
include FilterSpecHelper
|
|
|
|
|
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
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
it 'ignores unsupported emoji' do
|
|
|
|
exp = act = '<p>:foo:</p>'
|
|
|
|
doc = filter(act)
|
|
|
|
expect(doc.to_html).to match Regexp.escape(exp)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
it 'matches with adjacent text' do
|
|
|
|
doc = filter('+1 (:+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 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 'does not match emoji in a string' do
|
|
|
|
doc = filter("'2a00:a4c0:100::1'")
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(doc.css('gl-emoji').size).to eq 0
|
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
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
it 'keeps whitespace intact' do
|
|
|
|
doc = filter('This deserves a :+1:, big time.')
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(doc.to_html).to match(/^This deserves a <gl-emoji.+>, big time\.\z/)
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
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
|