Commit 0c9dbf79 authored by Stan Hu's avatar Stan Hu

Merge branch 'brodock/tanuki_emoji' into 'master'

Switch from `Gemojione` to `TanukiEmoji`

See merge request gitlab-org/gitlab!68787
parents 1e7c0d24 d229bbf9
...@@ -290,7 +290,7 @@ gem 'autoprefixer-rails', '10.2.5.1' ...@@ -290,7 +290,7 @@ gem 'autoprefixer-rails', '10.2.5.1'
gem 'terser', '1.0.2' gem 'terser', '1.0.2'
gem 'addressable', '~> 2.8' gem 'addressable', '~> 2.8'
gem 'gemojione', '~> 3.3' gem 'tanuki_emoji', '~> 0.5'
gem 'gon', '~> 6.4.0' gem 'gon', '~> 6.4.0'
gem 'request_store', '~> 1.5' gem 'request_store', '~> 1.5'
gem 'base32', '~> 0.3.0' gem 'base32', '~> 0.3.0'
...@@ -348,6 +348,8 @@ group :development do ...@@ -348,6 +348,8 @@ group :development do
# thin instead webrick # thin instead webrick
gem 'thin', '~> 1.8.0' gem 'thin', '~> 1.8.0'
gem 'sprite-factory', '~> 1.7'
end end
group :development, :test do group :development, :test do
......
...@@ -436,8 +436,6 @@ GEM ...@@ -436,8 +436,6 @@ GEM
ruby-progressbar (~> 1.4) ruby-progressbar (~> 1.4)
fuzzyurl (0.9.0) fuzzyurl (0.9.0)
gemoji (3.0.1) gemoji (3.0.1)
gemojione (3.3.0)
json
get_process_mem (0.2.5) get_process_mem (0.2.5)
ffi (~> 1.0) ffi (~> 1.0)
gettext (3.3.6) gettext (3.3.6)
...@@ -1216,6 +1214,7 @@ GEM ...@@ -1216,6 +1214,7 @@ GEM
spring (2.1.1) spring (2.1.1)
spring-commands-rspec (1.0.4) spring-commands-rspec (1.0.4)
spring (>= 0.9.1) spring (>= 0.9.1)
sprite-factory (1.7.1)
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
...@@ -1246,6 +1245,7 @@ GEM ...@@ -1246,6 +1245,7 @@ GEM
sys-filesystem (1.1.9) sys-filesystem (1.1.9)
ffi ffi
sysexits (1.2.0) sysexits (1.2.0)
tanuki_emoji (0.5.0)
temple (0.8.2) temple (0.8.2)
terminal-table (1.8.0) terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1) unicode-display_width (~> 1.1, >= 1.1.1)
...@@ -1454,7 +1454,6 @@ DEPENDENCIES ...@@ -1454,7 +1454,6 @@ DEPENDENCIES
fog-rackspace (~> 0.1.1) fog-rackspace (~> 0.1.1)
fugit (~> 1.2.1) fugit (~> 1.2.1)
fuubar (~> 2.2.0) fuubar (~> 2.2.0)
gemojione (~> 3.3)
gettext (~> 3.3) gettext (~> 3.3)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
...@@ -1622,11 +1621,13 @@ DEPENDENCIES ...@@ -1622,11 +1621,13 @@ DEPENDENCIES
spamcheck (~> 0.1.0) spamcheck (~> 0.1.0)
spring (~> 2.1.0) spring (~> 2.1.0)
spring-commands-rspec (~> 1.0.4) spring-commands-rspec (~> 1.0.4)
sprite-factory (~> 1.7)
sprockets (~> 3.7.0) sprockets (~> 3.7.0)
sshkey (~> 2.0) sshkey (~> 2.0)
stackprof (~> 0.2.15) stackprof (~> 0.2.15)
state_machines-activerecord (~> 0.8.0) state_machines-activerecord (~> 0.8.0)
sys-filesystem (~> 1.1.6) sys-filesystem (~> 1.1.6)
tanuki_emoji (~> 0.5)
terser (= 1.0.2) terser (= 1.0.2)
test-prof (~> 1.0.7) test-prof (~> 1.0.7)
test_file_finder (~> 0.1.3) test_file_finder (~> 0.1.3)
......
...@@ -9,6 +9,7 @@ let emojiMap = null; ...@@ -9,6 +9,7 @@ let emojiMap = null;
let validEmojiNames = null; let validEmojiNames = null;
export const FALLBACK_EMOJI_KEY = 'grey_question'; export const FALLBACK_EMOJI_KEY = 'grey_question';
// Keep the version in sync with `lib/gitlab/emoji.rb`
export const EMOJI_VERSION = '1'; export const EMOJI_VERSION = '1';
const isLocalStorageAvailable = AccessorUtilities.canUseLocalStorage(); const isLocalStorageAvailable = AccessorUtilities.canUseLocalStorage();
......
...@@ -40,7 +40,7 @@ class AwardEmojisFinder ...@@ -40,7 +40,7 @@ class AwardEmojisFinder
def validate_name_param def validate_name_param
return unless params[:name] return unless params[:name]
raise ArgumentError, 'Invalid name param' unless params[:name].to_s.in?(Gitlab::Emoji.emojis_names) raise ArgumentError, 'Invalid name param' unless TanukiEmoji.find_by_alpha_code(params[:name].to_s)
end end
def validate_awarded_by_param def validate_awarded_by_param
......
# frozen_string_literal: true # frozen_string_literal: true
module EmojiHelper module EmojiHelper
def emoji_icon(*args) def emoji_icon(emoji_name, *options)
raw Gitlab::Emoji.gl_emoji_tag(*args) emoji = TanukiEmoji.find_by_alpha_code(emoji_name)
raw Gitlab::Emoji.gl_emoji_tag(emoji, *options)
end end
end end
...@@ -7,7 +7,8 @@ module ReminderEmailsHelper ...@@ -7,7 +7,8 @@ module ReminderEmailsHelper
s_('InviteReminderEmail|Invitation pending') s_('InviteReminderEmail|Invitation pending')
when 1 when 1
if format == :html if format == :html
s_('InviteReminderEmail|Hey there %{wave_emoji}').html_safe % { wave_emoji: Gitlab::Emoji.gl_emoji_tag('wave') } wave_emoji_tag = Gitlab::Emoji.gl_emoji_tag(TanukiEmoji.find_by_alpha_code('wave'))
s_('InviteReminderEmail|Hey there %{wave_emoji}').html_safe % { wave_emoji: wave_emoji_tag }
else else
s_('InviteReminderEmail|Hey there!') s_('InviteReminderEmail|Hey there!')
end end
......
...@@ -14,7 +14,7 @@ class AwardEmoji < ApplicationRecord ...@@ -14,7 +14,7 @@ class AwardEmoji < ApplicationRecord
validates :user, presence: true validates :user, presence: true
validates :awardable, presence: true, unless: :importing? validates :awardable, presence: true, unless: :importing?
validates :name, presence: true, inclusion: { in: Gitlab::Emoji.emojis_names } validates :name, presence: true, 'gitlab/emoji_name': true
validates :name, uniqueness: { scope: [:user, :awardable_type, :awardable_id] }, unless: -> { ghost_user? || importing? } validates :name, uniqueness: { scope: [:user, :awardable_type, :awardable_id] }, unless: -> { ghost_user? || importing? }
participant :user participant :user
......
...@@ -31,7 +31,7 @@ class CustomEmoji < ApplicationRecord ...@@ -31,7 +31,7 @@ class CustomEmoji < ApplicationRecord
private private
def valid_emoji_name def valid_emoji_name
if Gitlab::Emoji.emoji_exists?(name) if TanukiEmoji.find_by_alpha_code(name)
errors.add(:name, _('%{name} is already being used for another emoji') % { name: self.name }) errors.add(:name, _('%{name} is already being used for another emoji') % { name: self.name })
end end
end end
......
...@@ -22,7 +22,7 @@ class UserStatus < ApplicationRecord ...@@ -22,7 +22,7 @@ class UserStatus < ApplicationRecord
enum availability: { not_set: 0, busy: 1 } enum availability: { not_set: 0, busy: 1 }
validates :user, presence: true validates :user, presence: true
validates :emoji, inclusion: { in: Gitlab::Emoji.emojis_names } validates :emoji, 'gitlab/emoji_name': true
validates :message, length: { maximum: 100 }, allow_blank: true validates :message, length: { maximum: 100 }, allow_blank: true
scope :scheduled_for_cleanup, -> { where(arel_table[:clear_status_at].lteq(Time.current)) } scope :scheduled_for_cleanup, -> { where(arel_table[:clear_status_at].lteq(Time.current)) }
......
...@@ -4,24 +4,24 @@ class AwardEmojiPresenter < Gitlab::View::Presenter::Delegated ...@@ -4,24 +4,24 @@ class AwardEmojiPresenter < Gitlab::View::Presenter::Delegated
presents ::AwardEmoji, as: :award_emoji presents ::AwardEmoji, as: :award_emoji
def description def description
as_emoji['description'] as_emoji&.description
end end
def unicode def unicode
as_emoji['unicode'] as_emoji&.hex
end end
def emoji def emoji
as_emoji['moji'] as_emoji&.codepoints
end end
def unicode_version def unicode_version
Gitlab::Emoji.emoji_unicode_version(award_emoji.name) as_emoji&.unicode_version
end end
private private
def as_emoji def as_emoji
@emoji ||= Gitlab::Emoji.emojis[award_emoji.name] || {} @emoji ||= TanukiEmoji.find_by_alpha_code(award_emoji.name)
end end
end end
...@@ -14,7 +14,7 @@ module AwardEmojis ...@@ -14,7 +14,7 @@ module AwardEmojis
private private
def normalize_name(name) def normalize_name(name)
Gitlab::Emoji.normalize_emoji_name(name) TanukiEmoji.find_by_alpha_code(name)&.name || name
end end
# Provide more error state data than what BaseService allows. # Provide more error state data than what BaseService allows.
......
# frozen_string_literal: true
# Gitlab::EmojiNameValidator
#
# Validates that the provided value matches an indexed emoji alpha code
#
# @example Usage
# class AwardEmoji < ApplicationRecord
# validate :name, 'gitlab/emoji_name': true
# end
module Gitlab
class EmojiNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless TanukiEmoji.find_by_alpha_code(value.to_s)
record.errors.add(attribute, (options[:message] || 'is not a valid emoji name'))
end
end
end
end
...@@ -199,7 +199,7 @@ module Gitlab ...@@ -199,7 +199,7 @@ module Gitlab
config.assets.enabled = true config.assets.enabled = true
# Support legacy unicode file named img emojis, `1F939.png` # Support legacy unicode file named img emojis, `1F939.png`
config.assets.paths << Gemojione.images_path config.assets.paths << TanukiEmoji.images_path
config.assets.paths << "#{config.root}/vendor/assets/fonts" config.assets.paths << "#{config.root}/vendor/assets/fonts"
config.assets.precompile << "application_utilities.css" config.assets.precompile << "application_utilities.css"
......
require './spec/support/sidekiq_middleware' require './spec/support/sidekiq_middleware'
Gitlab::Seeder.quiet do Gitlab::Seeder.quiet do
EMOJI = Gitlab::Emoji.emojis.keys
def seed_award_emoji(klass) def seed_award_emoji(klass)
klass.order(Gitlab::Database.random).limit(klass.count / 2).each do |awardable| klass.order(Gitlab::Database.random).limit(klass.count / 2).each do |awardable|
awardable.project.authorized_users.where('project_authorizations.access_level > ?', Gitlab::Access::GUEST).sample(2).each do |user| awardable.project.authorized_users.where('project_authorizations.access_level > ?', Gitlab::Access::GUEST).sample(2).each do |user|
AwardEmojis::AddService.new(awardable, EMOJI.sample, user).execute AwardEmojis::AddService.new(awardable, TanukiEmoji.index.all.sample.name, user).execute
awardable.notes.user.sample(2).each do |note| awardable.notes.user.sample(2).each do |note|
AwardEmojis::AddService.new(note, EMOJI.sample, user).execute AwardEmojis::AddService.new(note, TanukiEmoji.index.all.sample.name, user).execute
end end
print '.' print '.'
......
This diff is collapsed.
...@@ -8,7 +8,6 @@ module Banzai ...@@ -8,7 +8,6 @@ module Banzai
# Based on HTML::Pipeline::EmojiFilter # Based on HTML::Pipeline::EmojiFilter
class EmojiFilter < HTML::Pipeline::Filter class EmojiFilter < HTML::Pipeline::Filter
IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set
IGNORE_UNICODE_EMOJIS = %w(™ © ®).freeze
def call def call
doc.xpath('descendant-or-self::text()').each do |node| doc.xpath('descendant-or-self::text()').each do |node|
...@@ -35,7 +34,8 @@ module Banzai ...@@ -35,7 +34,8 @@ module Banzai
def emoji_name_element_unicode_filter(text) def emoji_name_element_unicode_filter(text)
text.gsub(emoji_pattern) do |match| text.gsub(emoji_pattern) do |match|
name = Regexp.last_match(1) name = Regexp.last_match(1)
Gitlab::Emoji.gl_emoji_tag(name) emoji = TanukiEmoji.find_by_alpha_code(name)
Gitlab::Emoji.gl_emoji_tag(emoji)
end end
end end
...@@ -46,26 +46,19 @@ module Banzai ...@@ -46,26 +46,19 @@ module Banzai
# Returns a String with unicode emoji replaced with gl-emoji unicode. # Returns a String with unicode emoji replaced with gl-emoji unicode.
def emoji_unicode_element_unicode_filter(text) def emoji_unicode_element_unicode_filter(text)
text.gsub(emoji_unicode_pattern) do |moji| text.gsub(emoji_unicode_pattern) do |moji|
emoji_info = Gitlab::Emoji.emojis_by_moji[moji] emoji = TanukiEmoji.find_by_codepoints(moji)
Gitlab::Emoji.gl_emoji_tag(emoji_info['name']) Gitlab::Emoji.gl_emoji_tag(emoji)
end end
end end
# Build a regexp that matches all valid :emoji: names. # Build a regexp that matches all valid :emoji: names.
def self.emoji_pattern def self.emoji_pattern
@emoji_pattern ||= @emoji_pattern ||= TanukiEmoji.index.alpha_code_pattern
%r{(?<=[^[:alnum:]:]|\n|^)
:(#{Gitlab::Emoji.emojis_names.map { |name| Regexp.escape(name) }.join('|')}):
(?=[^[:alnum:]:]|$)}x
end end
# Build a regexp that matches all valid unicode emojis names. # Build a regexp that matches all valid unicode emojis names.
def self.emoji_unicode_pattern def self.emoji_unicode_pattern
@emoji_unicode_pattern ||= @emoji_unicode_pattern ||= TanukiEmoji.index.codepoints_pattern
begin
filtered_emojis = Gitlab::Emoji.emojis_unicodes - IGNORE_UNICODE_EMOJIS
/(#{filtered_emojis.map { |moji| Regexp.escape(moji) }.join('|')})/
end
end end
private private
......
...@@ -4,40 +4,15 @@ module Gitlab ...@@ -4,40 +4,15 @@ module Gitlab
module Emoji module Emoji
extend self extend self
def emojis # When updating emoji assets increase the version below
Gemojione.index.instance_variable_get(:@emoji_by_name) # and update the version number in `app/assets/javascripts/emoji/index.js`
end EMOJI_VERSION = 1
def emojis_by_moji
Gemojione.index.instance_variable_get(:@emoji_by_moji)
end
def emojis_unicodes
emojis_by_moji.keys
end
def emojis_names
emojis.keys
end
def emojis_aliases
@emoji_aliases ||= Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json')))
end
def emoji_filename(name)
emojis[name]["unicode"]
end
def emoji_unicode_filename(moji)
emojis_by_moji[moji]["unicode"]
end
def emoji_unicode_version(name)
emoji_unicode_versions_by_name[name]
end
def normalize_emoji_name(name) # Return a Pathname to emoji's current versioned folder
emojis_aliases[name] || name #
# @return [Pathname] Absolute Path to versioned emojis folder in `public`
def emoji_public_absolute_path
Rails.root.join("public/-/emojis/#{EMOJI_VERSION}")
end end
def emoji_image_tag(name, src) def emoji_image_tag(name, src)
...@@ -54,23 +29,19 @@ module Gitlab ...@@ -54,23 +29,19 @@ module Gitlab
ActionController::Base.helpers.tag(:img, image_options) ActionController::Base.helpers.tag(:img, image_options)
end end
def emoji_exists?(name)
emojis.has_key?(name)
end
# CSS sprite fallback takes precedence over image fallback # CSS sprite fallback takes precedence over image fallback
def gl_emoji_tag(name, options = {}) # @param [TanukiEmoji::Character] emoji
emoji_name = emojis_aliases[name] || name # @param [Hash] options
emoji_info = emojis[emoji_name] def gl_emoji_tag(emoji, options = {})
return unless emoji_info return unless emoji
data = { data = {
name: emoji_name, name: emoji.name,
unicode_version: emoji_unicode_version(emoji_name) unicode_version: emoji.unicode_version
} }
options = { title: emoji_info['description'], data: data }.merge(options) options = { title: emoji.description, data: data }.merge(options)
ActionController::Base.helpers.content_tag('gl-emoji', emoji_info['moji'], options) ActionController::Base.helpers.content_tag('gl-emoji', emoji.codepoints, options)
end end
def custom_emoji_tag(name, image_source) def custom_emoji_tag(name, image_source)
...@@ -82,12 +53,5 @@ module Gitlab ...@@ -82,12 +53,5 @@ module Gitlab
emoji_image_tag(name, image_source).html_safe emoji_image_tag(name, image_source).html_safe
end end
end end
private
def emoji_unicode_versions_by_name
@emoji_unicode_versions_by_name ||=
Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json')))
end
end end
end end
...@@ -56,13 +56,13 @@ describe('gl_emoji', () => { ...@@ -56,13 +56,13 @@ describe('gl_emoji', () => {
'bomb emoji just with name attribute', 'bomb emoji just with name attribute',
'<gl-emoji data-name="bomb"></gl-emoji>', '<gl-emoji data-name="bomb"></gl-emoji>',
'<gl-emoji data-name="bomb" data-unicode-version="6.0" title="bomb">💣</gl-emoji>', '<gl-emoji data-name="bomb" data-unicode-version="6.0" title="bomb">💣</gl-emoji>',
'<gl-emoji data-name="bomb" data-unicode-version="6.0" title="bomb"><img class="emoji" title=":bomb:" alt=":bomb:" src="/-/emojis/1/bomb.png" width="20" height="20" align="absmiddle"></gl-emoji>', `<gl-emoji data-name="bomb" data-unicode-version="6.0" title="bomb"><img class="emoji" title=":bomb:" alt=":bomb:" src="/-/emojis/${EMOJI_VERSION}/bomb.png" width="20" height="20" align="absmiddle"></gl-emoji>`,
], ],
[ [
'bomb emoji with name attribute and unicode version', 'bomb emoji with name attribute and unicode version',
'<gl-emoji data-name="bomb" data-unicode-version="6.0">💣</gl-emoji>', '<gl-emoji data-name="bomb" data-unicode-version="6.0">💣</gl-emoji>',
'<gl-emoji data-name="bomb" data-unicode-version="6.0">💣</gl-emoji>', '<gl-emoji data-name="bomb" data-unicode-version="6.0">💣</gl-emoji>',
'<gl-emoji data-name="bomb" data-unicode-version="6.0"><img class="emoji" title=":bomb:" alt=":bomb:" src="/-/emojis/1/bomb.png" width="20" height="20" align="absmiddle"></gl-emoji>', `<gl-emoji data-name="bomb" data-unicode-version="6.0"><img class="emoji" title=":bomb:" alt=":bomb:" src="/-/emojis/${EMOJI_VERSION}/bomb.png" width="20" height="20" align="absmiddle"></gl-emoji>`,
], ],
[ [
'bomb emoji with sprite fallback', 'bomb emoji with sprite fallback',
...@@ -80,7 +80,7 @@ describe('gl_emoji', () => { ...@@ -80,7 +80,7 @@ describe('gl_emoji', () => {
'invalid emoji', 'invalid emoji',
'<gl-emoji data-name="invalid_emoji"></gl-emoji>', '<gl-emoji data-name="invalid_emoji"></gl-emoji>',
'<gl-emoji data-name="grey_question" data-unicode-version="6.0" title="white question mark ornament">❔</gl-emoji>', '<gl-emoji data-name="grey_question" data-unicode-version="6.0" title="white question mark ornament">❔</gl-emoji>',
'<gl-emoji data-name="grey_question" data-unicode-version="6.0" title="white question mark ornament"><img class="emoji" title=":grey_question:" alt=":grey_question:" src="/-/emojis/1/grey_question.png" width="20" height="20" align="absmiddle"></gl-emoji>', `<gl-emoji data-name="grey_question" data-unicode-version="6.0" title="white question mark ornament"><img class="emoji" title=":grey_question:" alt=":grey_question:" src="/-/emojis/${EMOJI_VERSION}/grey_question.png" width="20" height="20" align="absmiddle"></gl-emoji>`,
], ],
])('%s', (name, markup, withEmojiSupport, withoutEmojiSupport) => { ])('%s', (name, markup, withEmojiSupport, withoutEmojiSupport) => {
it(`renders correctly with emoji support`, async () => { it(`renders correctly with emoji support`, async () => {
......
...@@ -6,6 +6,7 @@ RSpec.describe EmojiHelper do ...@@ -6,6 +6,7 @@ RSpec.describe EmojiHelper do
describe '#emoji_icon' do describe '#emoji_icon' do
let(:options) { {} } let(:options) { {} }
let(:emoji_text) { 'rocket' } let(:emoji_text) { 'rocket' }
let(:unicode_version) { '6.0' }
let(:aria_hidden_option) { "aria-hidden=\"true\"" } let(:aria_hidden_option) { "aria-hidden=\"true\"" }
subject { helper.emoji_icon(emoji_text, options) } subject { helper.emoji_icon(emoji_text, options) }
...@@ -14,7 +15,7 @@ RSpec.describe EmojiHelper do ...@@ -14,7 +15,7 @@ RSpec.describe EmojiHelper do
is_expected.to include('<gl-emoji', is_expected.to include('<gl-emoji',
"title=\"#{emoji_text}\"", "title=\"#{emoji_text}\"",
"data-name=\"#{emoji_text}\"", "data-name=\"#{emoji_text}\"",
"data-unicode-version=\"#{::Gitlab::Emoji.emoji_unicode_version(emoji_text)}\"") "data-unicode-version=\"#{unicode_version}\"")
is_expected.not_to include(aria_hidden_option) is_expected.not_to include(aria_hidden_option)
end end
...@@ -25,7 +26,7 @@ RSpec.describe EmojiHelper do ...@@ -25,7 +26,7 @@ RSpec.describe EmojiHelper do
is_expected.to include('<gl-emoji', is_expected.to include('<gl-emoji',
"title=\"#{emoji_text}\"", "title=\"#{emoji_text}\"",
"data-name=\"#{emoji_text}\"", "data-name=\"#{emoji_text}\"",
"data-unicode-version=\"#{::Gitlab::Emoji.emoji_unicode_version(emoji_text)}\"", "data-unicode-version=\"#{unicode_version}\"",
aria_hidden_option) aria_hidden_option)
end end
end end
......
...@@ -28,9 +28,9 @@ RSpec.describe Banzai::Filter::EmojiFilter do ...@@ -28,9 +28,9 @@ RSpec.describe Banzai::Filter::EmojiFilter do
it 'replaces name versions of trademark, copyright, and registered trademark' do it 'replaces name versions of trademark, copyright, and registered trademark' do
doc = filter('<p>:tm: :copyright: :registered:</p>') doc = filter('<p>:tm: :copyright: :registered:</p>')
expect(doc.css('gl-emoji')[0].text).to eq '™' expect(doc.css('gl-emoji')[0].text).to eq '™'
expect(doc.css('gl-emoji')[1].text).to eq '©' expect(doc.css('gl-emoji')[1].text).to eq '
expect(doc.css('gl-emoji')[2].text).to eq '®' expect(doc.css('gl-emoji')[2].text).to eq '
end end
it 'correctly encodes the URL' do it 'correctly encodes the URL' do
......
...@@ -3,18 +3,20 @@ ...@@ -3,18 +3,20 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Banzai::Pipeline::EmojiPipeline do RSpec.describe Banzai::Pipeline::EmojiPipeline do
let(:emoji) { TanukiEmoji.find_by_alpha_code('100') }
def parse(text) def parse(text)
described_class.to_html(text, {}) described_class.to_html(text, {})
end end
it 'replaces emoji' do it 'replaces emoji' do
expected_result = "Hello world #{Gitlab::Emoji.gl_emoji_tag('100')}" expected_result = "Hello world #{Gitlab::Emoji.gl_emoji_tag(emoji)}"
expect(parse('Hello world :100:')).to eq(expected_result) expect(parse('Hello world :100:')).to eq(expected_result)
end end
it 'filters out HTML tags' do it 'filters out HTML tags' do
expected_result = "Hello &lt;b&gt;world&lt;/b&gt; #{Gitlab::Emoji.gl_emoji_tag('100')}" expected_result = "Hello &lt;b&gt;world&lt;/b&gt; #{Gitlab::Emoji.gl_emoji_tag(emoji)}"
expect(parse('Hello <b>world</b> :100:')).to eq(expected_result) expect(parse('Hello <b>world</b> :100:')).to eq(expected_result)
end end
......
...@@ -3,90 +3,6 @@ ...@@ -3,90 +3,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Emoji do RSpec.describe Gitlab::Emoji do
let_it_be(:emojis) { Gemojione.index.instance_variable_get(:@emoji_by_name) }
let_it_be(:emojis_by_moji) { Gemojione.index.instance_variable_get(:@emoji_by_moji) }
let_it_be(:emoji_unicode_versions_by_name) { Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'emoji-unicode-version-map.json'))) }
let_it_be(:emojis_aliases) { Gitlab::Json.parse(File.read(Rails.root.join('fixtures', 'emojis', 'aliases.json'))) }
describe '.emojis' do
it 'returns emojis' do
current_emojis = described_class.emojis
expect(current_emojis).to eq(emojis)
end
end
describe '.emojis_by_moji' do
it 'return emojis by moji' do
current_emojis_by_moji = described_class.emojis_by_moji
expect(current_emojis_by_moji).to eq(emojis_by_moji)
end
end
describe '.emojis_unicodes' do
it 'returns emoji unicodes' do
emoji_keys = described_class.emojis_unicodes
expect(emoji_keys).to eq(emojis_by_moji.keys)
end
end
describe '.emojis_names' do
it 'returns emoji names' do
emoji_names = described_class.emojis_names
expect(emoji_names).to eq(emojis.keys)
end
end
describe '.emojis_aliases' do
it 'returns emoji aliases' do
emoji_aliases = described_class.emojis_aliases
expect(emoji_aliases).to eq(emojis_aliases)
end
end
describe '.emoji_filename' do
it 'returns emoji filename' do
# "100" => {"unicode"=>"1F4AF"...}
emoji_filename = described_class.emoji_filename('100')
expect(emoji_filename).to eq(emojis['100']['unicode'])
end
end
describe '.emoji_unicode_filename' do
it 'returns emoji unicode filename' do
emoji_unicode_filename = described_class.emoji_unicode_filename('💯')
expect(emoji_unicode_filename).to eq(emojis_by_moji['💯']['unicode'])
end
end
describe '.emoji_unicode_version' do
it 'returns emoji unicode version by name' do
emoji_unicode_version = described_class.emoji_unicode_version('100')
expect(emoji_unicode_version).to eq(emoji_unicode_versions_by_name['100'])
end
end
describe '.normalize_emoji_name' do
it 'returns same name if not found in aliases' do
emoji_name = described_class.normalize_emoji_name('random')
expect(emoji_name).to eq('random')
end
it 'returns name if name found in aliases' do
emoji_name = described_class.normalize_emoji_name('small_airplane')
expect(emoji_name).to eq(emojis_aliases['small_airplane'])
end
end
describe '.emoji_image_tag' do describe '.emoji_image_tag' do
it 'returns emoji image tag' do it 'returns emoji image tag' do
emoji_image = described_class.emoji_image_tag('emoji_one', 'src_url') emoji_image = described_class.emoji_image_tag('emoji_one', 'src_url')
...@@ -104,29 +20,17 @@ RSpec.describe Gitlab::Emoji do ...@@ -104,29 +20,17 @@ RSpec.describe Gitlab::Emoji do
end end
end end
describe '.emoji_exists?' do
it 'returns true if the name exists' do
emoji_exists = described_class.emoji_exists?('100')
expect(emoji_exists).to be_truthy
end
it 'returns false if the name does not exist' do
emoji_exists = described_class.emoji_exists?('random')
expect(emoji_exists).to be_falsey
end
end
describe '.gl_emoji_tag' do describe '.gl_emoji_tag' do
it 'returns gl emoji tag if emoji is found' do it 'returns gl emoji tag if emoji is found' do
gl_tag = described_class.gl_emoji_tag('small_airplane') emoji = TanukiEmoji.find_by_alpha_code('small_airplane')
gl_tag = described_class.gl_emoji_tag(emoji)
expect(gl_tag).to eq('<gl-emoji title="small airplane" data-name="airplane_small" data-unicode-version="7.0">🛩</gl-emoji>') expect(gl_tag).to eq('<gl-emoji title="small airplane" data-name="airplane_small" data-unicode-version="7.0">🛩</gl-emoji>')
end end
it 'returns nil if emoji name is not found' do it 'returns nil if emoji is not found' do
gl_tag = described_class.gl_emoji_tag('random') emoji = TanukiEmoji.find_by_alpha_code('random')
gl_tag = described_class.gl_emoji_tag(emoji)
expect(gl_tag).to be_nil expect(gl_tag).to be_nil
end end
......
...@@ -14,7 +14,7 @@ RSpec.describe CustomEmoji do ...@@ -14,7 +14,7 @@ RSpec.describe CustomEmoji do
end end
describe 'exclusion of duplicated emoji' do describe 'exclusion of duplicated emoji' do
let(:emoji_name) { Gitlab::Emoji.emojis_names.sample } let(:emoji_name) { TanukiEmoji.index.all.sample.name }
let(:group) { create(:group, :private) } let(:group) { create(:group, :private) }
it 'disallows emoji names of built-in emoji' do it 'disallows emoji names of built-in emoji' do
......
...@@ -6,21 +6,22 @@ RSpec.describe AwardEmojiPresenter do ...@@ -6,21 +6,22 @@ RSpec.describe AwardEmojiPresenter do
let(:emoji_name) { 'thumbsup' } let(:emoji_name) { 'thumbsup' }
let(:award_emoji) { build(:award_emoji, name: emoji_name) } let(:award_emoji) { build(:award_emoji, name: emoji_name) }
let(:presenter) { described_class.new(award_emoji) } let(:presenter) { described_class.new(award_emoji) }
let(:emoji) { TanukiEmoji.find_by_alpha_code(emoji_name) }
describe '#description' do describe '#description' do
it { expect(presenter.description).to eq Gitlab::Emoji.emojis[emoji_name]['description'] } it { expect(presenter.description).to eq emoji.description }
end end
describe '#unicode' do describe '#unicode' do
it { expect(presenter.unicode).to eq Gitlab::Emoji.emojis[emoji_name]['unicode'] } it { expect(presenter.unicode).to eq emoji.hex }
end end
describe '#unicode_version' do describe '#unicode_version' do
it { expect(presenter.unicode_version).to eq Gitlab::Emoji.emoji_unicode_version(emoji_name) } it { expect(presenter.unicode_version).to eq('6.0') }
end end
describe '#emoji' do describe '#emoji' do
it { expect(presenter.emoji).to eq Gitlab::Emoji.emojis[emoji_name]['moji'] } it { expect(presenter.emoji).to eq emoji.codepoints }
end end
describe 'when presenting an award emoji with an invalid name' do describe 'when presenting an award emoji with an invalid name' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AwardEmojis::BaseService do
let(:awardable) { build(:note) }
let(:current_user) { build(:user) }
describe '.initialize' do
subject { described_class }
it 'uses same emoji name if not an alias' do
emoji_name = 'horse'
expect(subject.new(awardable, emoji_name, current_user).name).to eq(emoji_name)
end
it 'uses emoji original name if its an alias' do
emoji_alias = 'small_airplane'
emoji_name = 'airplane_small'
expect(subject.new(awardable, emoji_alias, current_user).name).to eq(emoji_name)
end
end
end
...@@ -53,7 +53,7 @@ RSpec.describe Users::UpdateService do ...@@ -53,7 +53,7 @@ RSpec.describe Users::UpdateService do
result = update_user(user, status: { emoji: "Moo!" }) result = update_user(user, status: { emoji: "Moo!" })
expect(result[:status]).to eq(:error) expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Emoji is not included in the list") expect(result[:message]).to eq("Emoji is not a valid emoji name")
end end
it 'updates user detail with provided attributes' do it 'updates user detail with provided attributes' do
......
...@@ -4810,11 +4810,6 @@ emoji-regex@^8.0.0: ...@@ -4810,11 +4810,6 @@ emoji-regex@^8.0.0:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==
emoji-unicode-version@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/emoji-unicode-version/-/emoji-unicode-version-0.2.1.tgz#0ebf3666b5414097971d34994e299fce75cdbafc"
integrity sha1-Dr82ZrVBQJeXHTSZTimfznXNuvw=
emojis-list@^3.0.0: emojis-list@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz#5570662046ad29e2e916e71aae260abdff4f6a78"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment