2021-03-08 18:12:59 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
|
|
|
import CommentFieldLayout from '~/notes/components/comment_field_layout.vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import AttachmentsWarning from '~/notes/components/attachments_warning.vue';
|
2021-03-08 18:12:59 +05:30
|
|
|
import EmailParticipantsWarning from '~/notes/components/email_participants_warning.vue';
|
|
|
|
import NoteableWarning from '~/vue_shared/components/notes/noteable_warning.vue';
|
|
|
|
|
|
|
|
describe('Comment Field Layout Component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const LOCKED_DISCUSSION_DOCS_PATH = 'docs/locked/path';
|
|
|
|
const CONFIDENTIAL_ISSUES_DOCS_PATH = 'docs/confidential/path';
|
|
|
|
|
|
|
|
const noteableDataMock = {
|
|
|
|
confidential: false,
|
|
|
|
discussion_locked: false,
|
|
|
|
locked_discussion_docs_path: LOCKED_DISCUSSION_DOCS_PATH,
|
|
|
|
confidential_issues_docs_path: CONFIDENTIAL_ISSUES_DOCS_PATH,
|
|
|
|
};
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const commentFieldWithAttachmentData = {
|
|
|
|
noteableData: {
|
|
|
|
...noteableDataMock,
|
|
|
|
issue_email_participants: [{ email: 'someone@gitlab.com' }, { email: 'another@gitlab.com' }],
|
|
|
|
},
|
|
|
|
containsLink: true,
|
|
|
|
};
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
const findIssuableNoteWarning = () => wrapper.findComponent(NoteableWarning);
|
|
|
|
const findEmailParticipantsWarning = () => wrapper.findComponent(EmailParticipantsWarning);
|
2023-04-23 21:23:45 +05:30
|
|
|
const findAttachmentsWarning = () => wrapper.findComponent(AttachmentsWarning);
|
2021-03-08 18:12:59 +05:30
|
|
|
const findErrorAlert = () => wrapper.findByTestId('comment-field-alert-container');
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const createWrapper = (props = {}, provide = {}) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper = extendedWrapper(
|
|
|
|
shallowMount(CommentFieldLayout, {
|
|
|
|
propsData: {
|
|
|
|
noteableData: noteableDataMock,
|
|
|
|
...props,
|
|
|
|
},
|
2023-04-23 21:23:45 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
serviceDeskNewNoteEmailNativeAttachments: true,
|
|
|
|
},
|
|
|
|
...provide,
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('.error-alert', () => {
|
|
|
|
it('does not exist by default', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
expect(findErrorAlert().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('exists when withAlertContainer is true', () => {
|
|
|
|
createWrapper({ withAlertContainer: true });
|
|
|
|
|
|
|
|
expect(findErrorAlert().isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issue is not confidential and not locked', () => {
|
|
|
|
it('does not show IssuableNoteWarning', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
expect(findIssuableNoteWarning().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issue is confidential', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper({
|
|
|
|
noteableData: { ...noteableDataMock, confidential: true },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows IssuableNoteWarning', () => {
|
|
|
|
expect(findIssuableNoteWarning().isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets IssuableNoteWarning props', () => {
|
|
|
|
expect(findIssuableNoteWarning().props()).toMatchObject({
|
|
|
|
isLocked: false,
|
|
|
|
isConfidential: true,
|
|
|
|
lockedNoteableDocsPath: LOCKED_DISCUSSION_DOCS_PATH,
|
|
|
|
confidentialNoteableDocsPath: CONFIDENTIAL_ISSUES_DOCS_PATH,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issue is locked', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper({
|
|
|
|
noteableData: { ...noteableDataMock, discussion_locked: true },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows IssuableNoteWarning', () => {
|
|
|
|
expect(findIssuableNoteWarning().isVisible()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets IssuableNoteWarning props', () => {
|
|
|
|
expect(findIssuableNoteWarning().props()).toMatchObject({
|
|
|
|
isConfidential: false,
|
|
|
|
isLocked: true,
|
|
|
|
lockedNoteableDocsPath: LOCKED_DISCUSSION_DOCS_PATH,
|
|
|
|
confidentialNoteableDocsPath: CONFIDENTIAL_ISSUES_DOCS_PATH,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issue has no email participants', () => {
|
|
|
|
it('does not show EmailParticipantsWarning', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
expect(findEmailParticipantsWarning().exists()).toBe(false);
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
it('does not show AttachmentWarning', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
expect(findAttachmentsWarning().exists()).toBe(false);
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('issue has email participants', () => {
|
|
|
|
beforeEach(() => {
|
2023-04-23 21:23:45 +05:30
|
|
|
createWrapper(commentFieldWithAttachmentData);
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows EmailParticipantsWarning', () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(findEmailParticipantsWarning().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows AttachmentsWarning', () => {
|
|
|
|
expect(findAttachmentsWarning().isVisible()).toBe(true);
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets EmailParticipantsWarning props', () => {
|
|
|
|
expect(findEmailParticipantsWarning().props('emails')).toEqual([
|
|
|
|
'someone@gitlab.com',
|
|
|
|
'another@gitlab.com',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2021-10-27 15:23:28 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe('issue has email participants, but note is internal', () => {
|
2021-10-27 15:23:28 +05:30
|
|
|
it('does not show EmailParticipantsWarning', () => {
|
|
|
|
createWrapper({
|
|
|
|
noteableData: {
|
|
|
|
...noteableDataMock,
|
|
|
|
issue_email_participants: [{ email: 'someone@gitlab.com' }],
|
|
|
|
},
|
2022-07-23 23:45:48 +05:30
|
|
|
isInternalNote: true,
|
2021-10-27 15:23:28 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(findEmailParticipantsWarning().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
describe('serviceDeskNewNoteEmailNativeAttachments flag', () => {
|
|
|
|
it('shows warning message when flag is enabled', () => {
|
|
|
|
createWrapper(commentFieldWithAttachmentData, {
|
|
|
|
glFeatures: { serviceDeskNewNoteEmailNativeAttachments: true },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findAttachmentsWarning().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows warning message when flag is disables', () => {
|
|
|
|
createWrapper(commentFieldWithAttachmentData, {
|
|
|
|
glFeatures: { serviceDeskNewNoteEmailNativeAttachments: false },
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findAttachmentsWarning().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|