2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { GlBadge } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
2020-06-23 00:09:42 +05:30
|
|
|
import DraftNote from '~/batch_comments/components/draft_note.vue';
|
|
|
|
import { createStore } from '~/batch_comments/stores';
|
|
|
|
import NoteableNote from '~/notes/components/noteable_note.vue';
|
|
|
|
import { createDraft } from '../mock_data';
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
jest.mock('~/behaviors/markdown/render_gfm');
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
const NoteableNoteStub = stubComponent(NoteableNote, {
|
|
|
|
template: `
|
|
|
|
<div>
|
|
|
|
<slot name="note-header-info">Test</slot>
|
2023-03-04 22:38:38 +05:30
|
|
|
<slot name="after-note-body">Test</slot>
|
2021-09-30 23:02:18 +05:30
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('Batch comments draft note component', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
let store;
|
2020-06-23 00:09:42 +05:30
|
|
|
let wrapper;
|
|
|
|
let draft;
|
2020-10-24 23:57:45 +05:30
|
|
|
const LINE_RANGE = {};
|
|
|
|
const draftWithLineRange = {
|
|
|
|
position: {
|
|
|
|
line_range: LINE_RANGE,
|
|
|
|
},
|
|
|
|
};
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
const createComponent = (propsData = { draft }, glFeatures = {}) => {
|
2022-04-04 11:22:00 +05:30
|
|
|
wrapper = shallowMount(DraftNote, {
|
2020-06-23 00:09:42 +05:30
|
|
|
store,
|
2020-10-24 23:57:45 +05:30
|
|
|
propsData,
|
2021-09-30 23:02:18 +05:30
|
|
|
stubs: {
|
|
|
|
NoteableNote: NoteableNoteStub,
|
|
|
|
},
|
2022-08-13 15:12:31 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures,
|
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
jest.spyOn(wrapper.vm.$store, 'dispatch').mockImplementation();
|
2020-10-24 23:57:45 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
draft = createDraft();
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders template', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(wrapper.findComponent(GlBadge).exists()).toBe(true);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const note = wrapper.findComponent(NoteableNote);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
expect(note.exists()).toBe(true);
|
|
|
|
expect(note.props().note).toEqual(draft);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('update', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('dispatches updateDraft', async () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2022-10-11 01:57:18 +05:30
|
|
|
const note = wrapper.findComponent(NoteableNote);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
note.vm.$emit('handleEdit');
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
const formData = {
|
|
|
|
note: draft,
|
|
|
|
noteText: 'a',
|
|
|
|
resolveDiscussion: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
note.vm.$emit('handleUpdateNote', formData);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
|
|
|
|
'batchComments/updateDraft',
|
|
|
|
formData,
|
|
|
|
);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteDraft', () => {
|
|
|
|
it('dispatches deleteDraft', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(window, 'confirm').mockImplementation(() => true);
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const note = wrapper.findComponent(NoteableNote);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
note.vm.$emit('handleDeleteNote', draft);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('batchComments/deleteDraft', draft);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('quick actions', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders referenced commands', async () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.setProps({
|
|
|
|
draft: {
|
|
|
|
...draft,
|
|
|
|
references: {
|
|
|
|
commands: 'test command',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
const referencedCommands = wrapper.find('.referenced-commands');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(referencedCommands.exists()).toBe(true);
|
|
|
|
expect(referencedCommands.text()).toContain('test command');
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('multiline comments', () => {
|
|
|
|
describe.each`
|
2021-03-11 19:13:27 +05:30
|
|
|
desc | props | event | expectedCalls
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${'mouseenter'} | ${[['setSelectedCommentPositionHover', LINE_RANGE]]}
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${'mouseleave'} | ${[['setSelectedCommentPositionHover']]}
|
|
|
|
${'without `draft.position`'} | ${{}} | ${'mouseenter'} | ${[]}
|
|
|
|
${'without `draft.position`'} | ${{}} | ${'mouseleave'} | ${[]}
|
|
|
|
`('$desc', ({ props, event, expectedCalls }) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
beforeEach(() => {
|
2021-03-11 19:13:27 +05:30
|
|
|
createComponent({ draft: { ...draft, ...props } });
|
2020-10-24 23:57:45 +05:30
|
|
|
jest.spyOn(store, 'dispatch');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`calls store ${expectedCalls.length} times on ${event}`, () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
wrapper.element.dispatchEvent(new MouseEvent(event, { bubbles: true }));
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(store.dispatch.mock.calls).toEqual(expectedCalls);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|