summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-02 12:08:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-02 12:08:25 +0000
commitac2d27b008ced210e234910179234bc45f31b7e1 (patch)
treea2c6b7b081eb6e32f9e33d11c85eb76a9053d18c /spec
parenta84d2572e943a70fdf95ef4514499df7c5f9db67 (diff)
downloadgitlab-ce-ac2d27b008ced210e234910179234bc45f31b7e1.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/custom_emoji.rb3
-rw-r--r--spec/frontend/behaviors/gl_emoji_spec.js6
-rw-r--r--spec/lib/banzai/filter/custom_emoji_filter_spec.rb9
-rw-r--r--spec/models/award_emoji_spec.rb13
-rw-r--r--spec/models/custom_emoji_spec.rb2
-rw-r--r--spec/requests/api/award_emoji_spec.rb17
6 files changed, 42 insertions, 8 deletions
diff --git a/spec/factories/custom_emoji.rb b/spec/factories/custom_emoji.rb
index 88e50eafa7c..09ac4a79a85 100644
--- a/spec/factories/custom_emoji.rb
+++ b/spec/factories/custom_emoji.rb
@@ -3,9 +3,8 @@
FactoryBot.define do
factory :custom_emoji, class: 'CustomEmoji' do
sequence(:name) { |n| "custom_emoji#{n}" }
- namespace
group
file { 'https://gitlab.com/images/partyparrot.png' }
- creator { namespace.owner }
+ creator factory: :user
end
end
diff --git a/spec/frontend/behaviors/gl_emoji_spec.js b/spec/frontend/behaviors/gl_emoji_spec.js
index cac1ea67cf5..8842ad636ec 100644
--- a/spec/frontend/behaviors/gl_emoji_spec.js
+++ b/spec/frontend/behaviors/gl_emoji_spec.js
@@ -77,6 +77,12 @@ describe('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/${EMOJI_VERSION}/grey_question.png" width="20" height="20" align="absmiddle"></gl-emoji>`,
],
+ [
+ 'custom emoji with image fallback',
+ '<gl-emoji data-fallback-src="https://cultofthepartyparrot.com/parrots/hd/parrot.gif" data-name="party-parrot" data-unicode-version="custom"></gl-emoji>',
+ '<gl-emoji data-fallback-src="https://cultofthepartyparrot.com/parrots/hd/parrot.gif" data-name="party-parrot" data-unicode-version="custom"><img class="emoji" title=":party-parrot:" alt=":party-parrot:" src="https://cultofthepartyparrot.com/parrots/hd/parrot.gif" width="20" height="20" align="absmiddle"></gl-emoji>',
+ '<gl-emoji data-fallback-src="https://cultofthepartyparrot.com/parrots/hd/parrot.gif" data-name="party-parrot" data-unicode-version="custom"><img class="emoji" title=":party-parrot:" alt=":party-parrot:" src="https://cultofthepartyparrot.com/parrots/hd/parrot.gif" width="20" height="20" align="absmiddle"></gl-emoji>',
+ ],
])('%s', (name, markup, withEmojiSupport, withoutEmojiSupport) => {
it(`renders correctly with emoji support`, async () => {
jest.spyOn(EmojiUnicodeSupport, 'default').mockReturnValue(true);
diff --git a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
index 94e77663d0f..6e29b910a6c 100644
--- a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
+++ b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb
@@ -18,31 +18,30 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter do
doc = filter('<p>:tanuki:</p>', project: project)
expect(doc.css('gl-emoji').first.attributes['title'].value).to eq('tanuki')
- expect(doc.css('gl-emoji img').size).to eq 1
end
it 'correctly uses the custom emoji URL' do
doc = filter('<p>:tanuki:</p>')
- expect(doc.css('img').first.attributes['src'].value).to eq(custom_emoji.file)
+ expect(doc.css('gl-emoji').first.attributes['data-fallback-src'].value).to eq(custom_emoji.file)
end
it 'matches multiple same custom emoji' do
doc = filter(':tanuki: :tanuki:')
- expect(doc.css('img').size).to eq 2
+ expect(doc.css('gl-emoji').size).to eq 2
end
it 'matches multiple custom emoji' do
doc = filter(':tanuki: (:happy_tanuki:)')
- expect(doc.css('img').size).to eq 2
+ expect(doc.css('gl-emoji').size).to eq 2
end
it 'does not match enclosed colons' do
doc = filter('tanuki:tanuki:')
- expect(doc.css('img').size).to be 0
+ expect(doc.css('gl-emoji').size).to be 0
end
it 'does not do N+1 query' do
diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb
index ebd1441f901..54f1d842acc 100644
--- a/spec/models/award_emoji_spec.rb
+++ b/spec/models/award_emoji_spec.rb
@@ -58,6 +58,19 @@ RSpec.describe AwardEmoji do
end
end
end
+
+ it 'accepts custom emoji' do
+ user = create(:user)
+ group = create(:group)
+ group.add_maintainer(user)
+
+ project = create(:project, namespace: group)
+ issue = create(:issue, project: project)
+ emoji = create(:custom_emoji, name: 'partyparrot', namespace: group)
+ new_award = build(:award_emoji, user: user, awardable: issue, name: emoji.name)
+
+ expect(new_award).to be_valid
+ end
end
describe 'scopes' do
diff --git a/spec/models/custom_emoji_spec.rb b/spec/models/custom_emoji_spec.rb
index 01252a58681..15655d08556 100644
--- a/spec/models/custom_emoji_spec.rb
+++ b/spec/models/custom_emoji_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe CustomEmoji do
new_emoji = build(:custom_emoji, name: old_emoji.name, namespace: old_emoji.namespace, group: group)
expect(new_emoji).not_to be_valid
- expect(new_emoji.errors.messages).to eq(creator: ["can't be blank"], name: ["has already been taken"])
+ expect(new_emoji.errors.messages).to eq(name: ["has already been taken"])
end
it 'disallows non http and https file value' do
diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb
index 07a9f7dfd74..782e14593f7 100644
--- a/spec/requests/api/award_emoji_spec.rb
+++ b/spec/requests/api/award_emoji_spec.rb
@@ -26,6 +26,23 @@ RSpec.describe API::AwardEmoji do
expect(json_response.first['name']).to eq(award_emoji.name)
end
+ it "includes custom emoji attributes" do
+ group = create(:group)
+ group.add_maintainer(user)
+
+ project = create(:project, namespace: group)
+ custom_emoji = create(:custom_emoji, name: 'partyparrot', namespace: group)
+ issue = create(:issue, project: project)
+ create(:award_emoji, awardable: issue, user: user, name: custom_emoji.name)
+
+ get api("/projects/#{project.id}/issues/#{issue.iid}/award_emoji", user)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response).to be_an Array
+ expect(json_response.first['name']).to eq(custom_emoji.name)
+ expect(json_response.first['url']).to eq(custom_emoji.file)
+ end
+
it "returns a 404 error when issue id not found" do
get api("/projects/#{project.id}/issues/#{non_existing_record_iid}/award_emoji", user)