summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-03 12:06:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-03 12:06:34 +0000
commitcd4cb29b2c304f00d238ee72fe40c767cb3e2675 (patch)
tree4dba0f038795f8d8f43ed807a1b7f58af27b61a9 /spec
parent2b339d4e892045d1d7be117d1557a5394ebd6e72 (diff)
downloadgitlab-ce-cd4cb29b2c304f00d238ee72fe40c767cb3e2675.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/gfm_auto_complete_spec.js109
-rw-r--r--spec/lib/banzai/reference_parser/user_parser_spec.rb20
-rw-r--r--spec/lib/gitlab/project_template_spec.rb1
-rw-r--r--spec/lib/gitlab/tracking_spec.rb4
-rw-r--r--spec/services/issues/update_service_spec.rb5
-rw-r--r--spec/support/shared_examples/quick_actions/issue/duplicate_quick_action_shared_examples.rb36
6 files changed, 129 insertions, 46 deletions
diff --git a/spec/frontend/gfm_auto_complete_spec.js b/spec/frontend/gfm_auto_complete_spec.js
index 8af49fd47a2..28ab2f2d6c4 100644
--- a/spec/frontend/gfm_auto_complete_spec.js
+++ b/spec/frontend/gfm_auto_complete_spec.js
@@ -1,6 +1,7 @@
/* eslint no-param-reassign: "off" */
import $ from 'jquery';
+import { membersBeforeSave } from '~/gfm_auto_complete';
import GfmAutoComplete from 'ee_else_ce/gfm_auto_complete';
import 'jquery.caret';
@@ -262,6 +263,79 @@ describe('GfmAutoComplete', () => {
});
});
+ describe('membersBeforeSave', () => {
+ const mockGroup = {
+ username: 'my-group',
+ name: 'My Group',
+ count: 2,
+ avatar_url: './group.jpg',
+ type: 'Group',
+ mentionsDisabled: false,
+ };
+
+ it('should return the original object when username is null', () => {
+ expect(membersBeforeSave([{ ...mockGroup, username: null }])).toEqual([
+ { ...mockGroup, username: null },
+ ]);
+ });
+
+ it('should set the text avatar if avatar_url is null', () => {
+ expect(membersBeforeSave([{ ...mockGroup, avatar_url: null }])).toEqual([
+ {
+ username: 'my-group',
+ avatarTag: '<div class="avatar rect-avatar center avatar-inline s26">M</div>',
+ title: 'My Group (2)',
+ search: 'my-group My Group',
+ icon: '',
+ },
+ ]);
+ });
+
+ it('should set the image avatar if avatar_url is given', () => {
+ expect(membersBeforeSave([mockGroup])).toEqual([
+ {
+ username: 'my-group',
+ avatarTag:
+ '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
+ title: 'My Group (2)',
+ search: 'my-group My Group',
+ icon: '',
+ },
+ ]);
+ });
+
+ it('should set mentions disabled icon if mentionsDisabled is set', () => {
+ expect(membersBeforeSave([{ ...mockGroup, mentionsDisabled: true }])).toEqual([
+ {
+ username: 'my-group',
+ avatarTag:
+ '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
+ title: 'My Group',
+ search: 'my-group My Group',
+ icon:
+ '<svg class="s16 vertical-align-middle prepend-left-5"><use xlink:href="undefined#notifications-off" /></svg>',
+ },
+ ]);
+ });
+
+ it('should set the right image classes for User type members', () => {
+ expect(
+ membersBeforeSave([
+ { username: 'my-user', name: 'My User', avatar_url: './users.jpg', type: 'User' },
+ ]),
+ ).toEqual([
+ {
+ username: 'my-user',
+ avatarTag:
+ '<img src="./users.jpg" alt="my-user" class="avatar avatar-inline center s26"/>',
+ title: 'My User',
+ search: 'my-user My User',
+ icon: '',
+ },
+ ]);
+ });
+ });
+
describe('Issues.insertTemplateFunction', () => {
it('should return default template', () => {
expect(GfmAutoComplete.Issues.insertTemplateFunction({ id: 5, title: 'Some Issue' })).toBe(
@@ -298,6 +372,41 @@ describe('GfmAutoComplete', () => {
});
});
+ describe('Members.templateFunction', () => {
+ it('should return html with avatarTag and username', () => {
+ expect(
+ GfmAutoComplete.Members.templateFunction({
+ avatarTag: 'IMG',
+ username: 'my-group',
+ title: '',
+ icon: '',
+ }),
+ ).toBe('<li>IMG my-group <small></small> </li>');
+ });
+
+ it('should add icon if icon is set', () => {
+ expect(
+ GfmAutoComplete.Members.templateFunction({
+ avatarTag: 'IMG',
+ username: 'my-group',
+ title: '',
+ icon: '<i class="icon"/>',
+ }),
+ ).toBe('<li>IMG my-group <small></small> <i class="icon"/></li>');
+ });
+
+ it('should add escaped title if title is set', () => {
+ expect(
+ GfmAutoComplete.Members.templateFunction({
+ avatarTag: 'IMG',
+ username: 'my-group',
+ title: 'MyGroup+',
+ icon: '<i class="icon"/>',
+ }),
+ ).toBe('<li>IMG my-group <small>MyGroup+</small> <i class="icon"/></li>');
+ });
+ });
+
describe('labels', () => {
const dataSources = {
labels: `${TEST_HOST}/autocomplete_sources/labels`,
diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb
index 931fb1e3953..71d2e1de3b6 100644
--- a/spec/lib/banzai/reference_parser/user_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb
@@ -19,15 +19,23 @@ describe Banzai::ReferenceParser::UserParser do
link['data-group'] = project.group.id.to_s
end
- it 'returns the users of the group' do
- create(:group_member, group: group, user: user)
-
- expect(subject.referenced_by([link])).to eq([user])
- end
-
it 'returns an empty Array when the group has no users' do
expect(subject.referenced_by([link])).to eq([])
end
+
+ context 'when group has members' do
+ let!(:group_member) { create(:group_member, group: group, user: user) }
+
+ it 'returns the users of the group' do
+ expect(subject.referenced_by([link])).to eq([user])
+ end
+
+ it 'returns an empty Array when the group has mentions disabled' do
+ group.update!(mentions_disabled: true)
+
+ expect(subject.referenced_by([link])).to eq([])
+ end
+ end
end
context 'using a non-existing group ID' do
diff --git a/spec/lib/gitlab/project_template_spec.rb b/spec/lib/gitlab/project_template_spec.rb
index 5559b1e4291..a2e3e2146f3 100644
--- a/spec/lib/gitlab/project_template_spec.rb
+++ b/spec/lib/gitlab/project_template_spec.rb
@@ -23,6 +23,7 @@ describe Gitlab::ProjectTemplate do
described_class.new('nfplainhtml', 'Netlify/Plain HTML', _('A plain HTML site that uses Netlify for CI/CD instead of GitLab, but still with all the other great GitLab features.'), 'https://gitlab.com/pages/nfplain-html'),
described_class.new('nfgitbook', 'Netlify/GitBook', _('A GitBook site that uses Netlify for CI/CD instead of GitLab, but still with all the other great GitLab features.'), 'https://gitlab.com/pages/nfgitbook'),
described_class.new('nfhexo', 'Netlify/Hexo', _('A Hexo site that uses Netlify for CI/CD instead of GitLab, but still with all the other great GitLab features.'), 'https://gitlab.com/pages/nfhexo'),
+ described_class.new('salesforcedx', 'SalesforceDX', _('A project boilerplate for Salesforce App development with Salesforce Developer tools.'), 'https://gitlab.com/gitlab-org/project-templates/salesforcedx'),
described_class.new('serverless_framework', 'Serverless Framework/JS', _('A basic page and serverless function that uses AWS Lambda, AWS API Gateway, and GitLab Pages'), 'https://gitlab.com/gitlab-org/project-templates/serverless-framework', 'illustrations/logos/serverless_framework.svg')
]
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb
index dc877f20cae..efb07d9dc95 100644
--- a/spec/lib/gitlab/tracking_spec.rb
+++ b/spec/lib/gitlab/tracking_spec.rb
@@ -97,7 +97,7 @@ describe Gitlab::Tracking do
'_property_',
'_value_',
nil,
- timestamp.to_i
+ (timestamp.to_f * 1000).to_i
)
track_event
@@ -130,7 +130,7 @@ describe Gitlab::Tracking do
expect(tracker).to receive(:track_self_describing_event).with(
'_event_json_',
nil,
- timestamp.to_i
+ (timestamp.to_f * 1000).to_i
)
track_event
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 604befd7225..b8a0e118479 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -689,8 +689,9 @@ describe Issues::UpdateService, :mailer do
context 'valid canonical_issue_id' do
it 'calls the duplicate service with both issues' do
- expect_any_instance_of(Issues::DuplicateService)
- .to receive(:execute).with(issue, canonical_issue)
+ expect_next_instance_of(Issues::DuplicateService) do |service|
+ expect(service).to receive(:execute).with(issue, canonical_issue)
+ end
update_issue(canonical_issue_id: canonical_issue.id)
end
diff --git a/spec/support/shared_examples/quick_actions/issue/duplicate_quick_action_shared_examples.rb b/spec/support/shared_examples/quick_actions/issue/duplicate_quick_action_shared_examples.rb
deleted file mode 100644
index 3834b8b2b87..00000000000
--- a/spec/support/shared_examples/quick_actions/issue/duplicate_quick_action_shared_examples.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-shared_examples 'duplicate quick action' do
- context 'mark issue as duplicate' do
- let(:original_issue) { create(:issue, project: project) }
-
- context 'when the current user can update issues' do
- it 'does not create a note, and marks the issue as a duplicate' do
- add_note("/duplicate ##{original_issue.to_reference}")
-
- expect(page).not_to have_content "/duplicate #{original_issue.to_reference}"
- expect(page).to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"
-
- expect(issue.reload).to be_closed
- end
- end
-
- context 'when the current user cannot update the issue' do
- let(:guest) { create(:user) }
- before do
- project.add_guest(guest)
- gitlab_sign_out
- sign_in(guest)
- visit project_issue_path(project, issue)
- end
-
- it 'does not create a note, and does not mark the issue as a duplicate' do
- add_note("/duplicate ##{original_issue.to_reference}")
-
- expect(page).not_to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"
-
- expect(issue.reload).to be_open
- end
- end
- end
-end