2020-06-23 00:09:42 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { getByRole } from '@testing-library/dom';
|
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 '~/behaviors/markdown/render_gfm';
|
|
|
|
import { createDraft } from '../mock_data';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const getList = () => getByRole(wrapper.element, 'list');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const createComponent = (propsData = { draft }, features = {}) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper = shallowMount(localVue.extend(DraftNote), {
|
|
|
|
store,
|
2020-10-24 23:57:45 +05:30
|
|
|
propsData,
|
2020-06-23 00:09:42 +05:30
|
|
|
localVue,
|
2020-10-24 23:57:45 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures: { multilineComments: true, ...features },
|
|
|
|
},
|
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();
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.find('.draft-pending-label').exists()).toBe(true);
|
|
|
|
|
|
|
|
const note = wrapper.find(NoteableNote);
|
|
|
|
|
|
|
|
expect(note.exists()).toBe(true);
|
|
|
|
expect(note.props().note).toEqual(draft);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('add comment now', () => {
|
|
|
|
it('dispatches publishSingleDraft when clicking', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2020-06-23 00:09:42 +05:30
|
|
|
const publishNowButton = wrapper.find({ ref: 'publishNowButton' });
|
|
|
|
publishNowButton.vm.$emit('click');
|
|
|
|
|
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
|
|
|
|
'batchComments/publishSingleDraft',
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets as loading when draft is publishing', done => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.$store.state.batchComments.currentlyPublishingDrafts.push(1);
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
const publishNowButton = wrapper.find({ ref: 'publishNowButton' });
|
|
|
|
|
|
|
|
expect(publishNowButton.props().loading).toBe(true);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('update', () => {
|
|
|
|
it('dispatches updateDraft', done => {
|
2020-10-24 23:57:45 +05:30
|
|
|
createComponent();
|
2020-06-23 00:09:42 +05:30
|
|
|
const note = wrapper.find(NoteableNote);
|
|
|
|
|
|
|
|
note.vm.$emit('handleEdit');
|
|
|
|
|
|
|
|
wrapper.vm
|
|
|
|
.$nextTick()
|
|
|
|
.then(() => {
|
|
|
|
const formData = {
|
|
|
|
note: draft,
|
|
|
|
noteText: 'a',
|
|
|
|
resolveDiscussion: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
note.vm.$emit('handleUpdateNote', formData);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(
|
|
|
|
'batchComments/updateDraft',
|
|
|
|
formData,
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const note = wrapper.find(NoteableNote);
|
|
|
|
|
|
|
|
note.vm.$emit('handleDeleteNote', draft);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('batchComments/deleteDraft', draft);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('quick actions', () => {
|
|
|
|
it('renders referenced commands', done => {
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.$nextTick(() => {
|
|
|
|
const referencedCommands = wrapper.find('.referenced-commands');
|
|
|
|
|
|
|
|
expect(referencedCommands.exists()).toBe(true);
|
|
|
|
expect(referencedCommands.text()).toContain('test command');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('multiline comments', () => {
|
|
|
|
describe.each`
|
|
|
|
desc | props | features | event | expectedCalls
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${{}} | ${'mouseenter'} | ${[['setSelectedCommentPositionHover', LINE_RANGE]]}
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${{}} | ${'mouseleave'} | ${[['setSelectedCommentPositionHover']]}
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${{ multilineComments: false }} | ${'mouseenter'} | ${[]}
|
|
|
|
${'with `draft.position`'} | ${draftWithLineRange} | ${{ multilineComments: false }} | ${'mouseleave'} | ${[]}
|
|
|
|
${'without `draft.position`'} | ${{}} | ${{}} | ${'mouseenter'} | ${[]}
|
|
|
|
${'without `draft.position`'} | ${{}} | ${{}} | ${'mouseleave'} | ${[]}
|
|
|
|
`('$desc and features $features', ({ props, event, features, expectedCalls }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ draft: { ...draft, ...props } }, features);
|
|
|
|
jest.spyOn(store, 'dispatch');
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`calls store ${expectedCalls.length} times on ${event}`, () => {
|
|
|
|
getList().dispatchEvent(new MouseEvent(event, { bubbles: true }));
|
|
|
|
expect(store.dispatch.mock.calls).toEqual(expectedCalls);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|