about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
authorDavid Underwood <davefp@gmail.com>2018-04-01 17:55:42 -0400
committerEugen Rochko <eugen@zeonfederated.com>2018-04-01 23:55:42 +0200
commit123a343d116d3e83cbd04460cc7bd0b6f3d208c4 (patch)
tree7d834be5438d835fe90744e0ba011f585cf252b1 /spec/lib
parentf464f98fd3b8ef33b3afa5acf09e829c046134de (diff)
[WIP] Enable custom emoji on account pages and in the sidebar (#6124)
Federate custom emojis with accounts
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/formatter_spec.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb
index 67fbfe92d..6e849f379 100644
--- a/spec/lib/formatter_spec.rb
+++ b/spec/lib/formatter_spec.rb
@@ -394,6 +394,45 @@ RSpec.describe Formatter do
         end
       end
 
+      context 'with custom_emojify option' do
+        let!(:emoji) { Fabricate(:custom_emoji) }
+
+        before { account.note = text }
+        subject { Formatter.instance.simplified_format(account, custom_emojify: true) }
+
+        context 'with emoji at the start' do
+          let(:text) { ':coolcat: Beep boop' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/<p><img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+
+        context 'with emoji in the middle' do
+          let(:text) { 'Beep :coolcat: boop' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/Beep <img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+
+        context 'with concatenated emoji' do
+          let(:text) { ':coolcat::coolcat:' }
+
+          it 'does not touch the shortcodes' do
+            is_expected.to match(/:coolcat::coolcat:/)
+          end
+        end
+
+        context 'with emoji at the end' do
+          let(:text) { 'Beep boop :coolcat:' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/boop <img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+      end
+
       include_examples 'encode and link URLs'
     end
 
@@ -404,6 +443,46 @@ RSpec.describe Formatter do
       it 'reformats' do
         is_expected.to_not include '<script>alert("Hello")</script>'
       end
+
+      context 'with custom_emojify option' do
+        let!(:emoji) { Fabricate(:custom_emoji, domain: remote_account.domain) }
+
+        before { remote_account.note = text }
+
+        subject { Formatter.instance.simplified_format(remote_account, custom_emojify: true) }
+
+        context 'with emoji at the start' do
+          let(:text) { '<p>:coolcat: Beep boop<br />' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/<p><img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+
+        context 'with emoji in the middle' do
+          let(:text) { '<p>Beep :coolcat: boop</p>' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/Beep <img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+
+        context 'with concatenated emoji' do
+          let(:text) { '<p>:coolcat::coolcat:</p>' }
+
+          it 'does not touch the shortcodes' do
+            is_expected.to match(/<p>:coolcat::coolcat:<\/p>/)
+          end
+        end
+
+        context 'with emoji at the end' do
+          let(:text) { '<p>Beep boop<br />:coolcat:</p>' }
+
+          it 'converts shortcode to image tag' do
+            is_expected.to match(/<br><img draggable="false" class="emojione" alt=":coolcat:"/)
+          end
+        end
+      end
     end
   end