summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/filter/emoji_filter_spec.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
committerDouwe Maan <douwe@gitlab.com>2015-12-15 15:51:16 +0100
commit7781bda9bd82997f4a03de4cf911b1156ceb2cde (patch)
treea632a12b295694232205e2190f784f9bb79235ee /spec/lib/banzai/filter/emoji_filter_spec.rb
parent9451db3819ae45734c4343e55a74d347cdacf70d (diff)
downloadgitlab-ce-7781bda9bd82997f4a03de4cf911b1156ceb2cde.tar.gz
Move Markdown/reference logic from Gitlab::Markdown to Banzai
Diffstat (limited to 'spec/lib/banzai/filter/emoji_filter_spec.rb')
-rw-r--r--spec/lib/banzai/filter/emoji_filter_spec.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/emoji_filter_spec.rb b/spec/lib/banzai/filter/emoji_filter_spec.rb
new file mode 100644
index 00000000000..cf314058158
--- /dev/null
+++ b/spec/lib/banzai/filter/emoji_filter_spec.rb
@@ -0,0 +1,98 @@
+require 'spec_helper'
+
+describe Banzai::Filter::EmojiFilter, lib: true do
+ include FilterSpecHelper
+
+ before do
+ @original_asset_host = ActionController::Base.asset_host
+ ActionController::Base.asset_host = 'https://foo.com'
+ end
+
+ after do
+ ActionController::Base.asset_host = @original_asset_host
+ end
+
+ it 'replaces supported emoji' do
+ doc = filter('<p>:heart:</p>')
+ expect(doc.css('img').first.attr('src')).to eq 'https://foo.com/assets/emoji/2764.png'
+ end
+
+ 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>')
+ expect(doc.css('img').first.attr('src')).to eq 'https://foo.com/assets/emoji/1F44D.png'
+ end
+
+ it 'matches at the start of a string' do
+ doc = filter(':+1:')
+ expect(doc.css('img').size).to eq 1
+ end
+
+ it 'matches at the end of a string' do
+ doc = filter('This gets a :-1:')
+ expect(doc.css('img').size).to eq 1
+ end
+
+ it 'matches with adjacent text' do
+ doc = filter('+1 (:+1:)')
+ expect(doc.css('img').size).to eq 1
+ end
+
+ it 'matches multiple emoji in a row' do
+ doc = filter(':see_no_evil::hear_no_evil::speak_no_evil:')
+ expect(doc.css('img').size).to eq 3
+ end
+
+ it 'has a title attribute' do
+ doc = filter(':-1:')
+ expect(doc.css('img').first.attr('title')).to eq ':-1:'
+ end
+
+ it 'has an alt attribute' do
+ doc = filter(':-1:')
+ expect(doc.css('img').first.attr('alt')).to eq ':-1:'
+ end
+
+ it 'has an align attribute' do
+ doc = filter(':8ball:')
+ expect(doc.css('img').first.attr('align')).to eq 'absmiddle'
+ end
+
+ it 'has an emoji class' do
+ doc = filter(':cat:')
+ expect(doc.css('img').first.attr('class')).to eq 'emoji'
+ end
+
+ it 'has height and width attributes' do
+ doc = filter(':dog:')
+ img = doc.css('img').first
+
+ expect(img.attr('width')).to eq '20'
+ expect(img.attr('height')).to eq '20'
+ end
+
+ it 'keeps whitespace intact' do
+ doc = filter('This deserves a :+1:, big time.')
+
+ expect(doc.to_html).to match(/^This deserves a <img.+>, big time\.\z/)
+ end
+
+ it 'uses a custom asset_root context' do
+ root = Gitlab.config.gitlab.url + 'gitlab/root'
+
+ doc = filter(':smile:', asset_root: root)
+ expect(doc.css('img').first.attr('src')).to start_with(root)
+ end
+
+ it 'uses a custom asset_host context' do
+ ActionController::Base.asset_host = 'https://cdn.example.com'
+
+ doc = filter(':frowning:', asset_host: 'https://this-is-ignored-i-guess?')
+ expect(doc.css('img').first.attr('src')).to start_with('https://cdn.example.com')
+ end
+end