Commit e00f7f1c authored by Illya Klymov's avatar Illya Klymov

Remove deprecated `setMethods` calls

`@vue/test-utils` 1.x deprecate `setMethods`
parent 42e1a2aa
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import DesignPresentation from '~/design_management/components/design_presentation.vue'; import DesignPresentation from '~/design_management/components/design_presentation.vue';
import DesignOverlay from '~/design_management/components/design_overlay.vue'; import DesignOverlay from '~/design_management/components/design_overlay.vue';
...@@ -100,12 +101,12 @@ describe('Design management design presentation component', () => { ...@@ -100,12 +101,12 @@ describe('Design management design presentation component', () => {
clientY: endCoords.clientY, clientY: endCoords.clientY,
}); });
return wrapper.vm.$nextTick(); return nextTick();
}) })
.then(() => { .then(() => {
if (mouseup) { if (mouseup) {
addCommentOverlay.trigger(event.mouseup); addCommentOverlay.trigger(event.mouseup);
return wrapper.vm.$nextTick(); return nextTick();
} }
return undefined; return undefined;
...@@ -125,7 +126,7 @@ describe('Design management design presentation component', () => { ...@@ -125,7 +126,7 @@ describe('Design management design presentation component', () => {
mockOverlayData, mockOverlayData,
); );
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
}); });
...@@ -133,7 +134,7 @@ describe('Design management design presentation component', () => { ...@@ -133,7 +134,7 @@ describe('Design management design presentation component', () => {
it('renders empty state when no image provided', () => { it('renders empty state when no image provided', () => {
createComponent(); createComponent();
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
}); });
...@@ -149,7 +150,7 @@ describe('Design management design presentation component', () => { ...@@ -149,7 +150,7 @@ describe('Design management design presentation component', () => {
wrapper.vm.openCommentForm({ x: 1, y: 1 }); wrapper.vm.openCommentForm({ x: 1, y: 1 });
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.emitted('openCommentForm')).toEqual([ expect(wrapper.emitted('openCommentForm')).toEqual([
[{ ...mockOverlayData.overlayDimensions, x: 1, y: 1 }], [{ ...mockOverlayData.overlayDimensions, x: 1, y: 1 }],
]); ]);
...@@ -166,7 +167,7 @@ describe('Design management design presentation component', () => { ...@@ -166,7 +167,7 @@ describe('Design management design presentation component', () => {
mockOverlayData, mockOverlayData,
); );
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.vm.currentCommentForm).toBeNull(); expect(wrapper.vm.currentCommentForm).toBeNull();
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
...@@ -182,7 +183,7 @@ describe('Design management design presentation component', () => { ...@@ -182,7 +183,7 @@ describe('Design management design presentation component', () => {
mockOverlayData, mockOverlayData,
); );
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.vm.currentCommentForm).toBeNull(); expect(wrapper.vm.currentCommentForm).toBeNull();
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
...@@ -206,7 +207,7 @@ describe('Design management design presentation component', () => { ...@@ -206,7 +207,7 @@ describe('Design management design presentation component', () => {
}, },
); );
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.vm.currentCommentForm).toEqual({ expect(wrapper.vm.currentCommentForm).toEqual({
x: 1, x: 1,
y: 1, y: 1,
...@@ -379,7 +380,7 @@ describe('Design management design presentation component', () => { ...@@ -379,7 +380,7 @@ describe('Design management design presentation component', () => {
}); });
describe('onImageResize', () => { describe('onImageResize', () => {
it('sets zoom focal point on initial load', () => { beforeEach(() => {
createComponent( createComponent(
{ {
image: 'test.jpg', image: 'test.jpg',
...@@ -388,22 +389,21 @@ describe('Design management design presentation component', () => { ...@@ -388,22 +389,21 @@ describe('Design management design presentation component', () => {
mockOverlayData, mockOverlayData,
); );
wrapper.setMethods({ jest.spyOn(wrapper.vm, 'shiftZoomFocalPoint');
shiftZoomFocalPoint: jest.fn(), jest.spyOn(wrapper.vm, 'scaleZoomFocalPoint');
scaleZoomFocalPoint: jest.fn(), jest.spyOn(wrapper.vm, 'scrollToFocalPoint');
scrollToFocalPoint: jest.fn(), wrapper.vm.onImageResize({ width: 10, height: 10 });
return nextTick();
}); });
wrapper.vm.onImageResize({ width: 10, height: 10 }); it('sets zoom focal point on initial load', () => {
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.shiftZoomFocalPoint).toHaveBeenCalled(); expect(wrapper.vm.shiftZoomFocalPoint).toHaveBeenCalled();
expect(wrapper.vm.initialLoad).toBe(false); expect(wrapper.vm.initialLoad).toBe(false);
}); });
});
it('calls scaleZoomFocalPoint and scrollToFocalPoint after initial load', () => { it('calls scaleZoomFocalPoint and scrollToFocalPoint after initial load', () => {
wrapper.vm.onImageResize({ width: 10, height: 10 }); wrapper.vm.onImageResize({ width: 10, height: 10 });
return wrapper.vm.$nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.vm.scaleZoomFocalPoint).toHaveBeenCalled(); expect(wrapper.vm.scaleZoomFocalPoint).toHaveBeenCalled();
expect(wrapper.vm.scrollToFocalPoint).toHaveBeenCalled(); expect(wrapper.vm.scrollToFocalPoint).toHaveBeenCalled();
}); });
...@@ -506,7 +506,7 @@ describe('Design management design presentation component', () => { ...@@ -506,7 +506,7 @@ describe('Design management design presentation component', () => {
.$nextTick() .$nextTick()
.then(() => { .then(() => {
addCommentOverlay.trigger('mouseup'); addCommentOverlay.trigger('mouseup');
return wrapper.vm.$nextTick(); return nextTick();
}) })
.then(() => { .then(() => {
expect(wrapper.emitted('openCommentForm')).toBeDefined(); expect(wrapper.emitted('openCommentForm')).toBeDefined();
......
import { nextTick } from 'vue'; import Vue, { nextTick } from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon, GlPagination } from '@gitlab/ui'; import { GlLoadingIcon, GlPagination } from '@gitlab/ui';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
...@@ -27,6 +27,8 @@ const TEST_ENDPOINT = `${TEST_HOST}/diff/endpoint`; ...@@ -27,6 +27,8 @@ const TEST_ENDPOINT = `${TEST_HOST}/diff/endpoint`;
const COMMIT_URL = `${TEST_HOST}/COMMIT/OLD`; const COMMIT_URL = `${TEST_HOST}/COMMIT/OLD`;
const UPDATED_COMMIT_URL = `${TEST_HOST}/COMMIT/NEW`; const UPDATED_COMMIT_URL = `${TEST_HOST}/COMMIT/NEW`;
Vue.use(Vuex);
function getCollapsedFilesWarning(wrapper) { function getCollapsedFilesWarning(wrapper) {
return wrapper.find(CollapsedFilesWarning); return wrapper.find(CollapsedFilesWarning);
} }
...@@ -38,7 +40,6 @@ describe('diffs/components/app', () => { ...@@ -38,7 +40,6 @@ describe('diffs/components/app', () => {
let mock; let mock;
function createComponent(props = {}, extendStore = () => {}, provisions = {}) { function createComponent(props = {}, extendStore = () => {}, provisions = {}) {
const localVue = createLocalVue();
const provide = { const provide = {
...provisions, ...provisions,
glFeatures: { glFeatures: {
...@@ -46,8 +47,6 @@ describe('diffs/components/app', () => { ...@@ -46,8 +47,6 @@ describe('diffs/components/app', () => {
}, },
}; };
localVue.use(Vuex);
store = createDiffsStore(); store = createDiffsStore();
store.state.diffs.isLoading = false; store.state.diffs.isLoading = false;
store.state.diffs.isTreeLoaded = true; store.state.diffs.isTreeLoaded = true;
...@@ -55,7 +54,6 @@ describe('diffs/components/app', () => { ...@@ -55,7 +54,6 @@ describe('diffs/components/app', () => {
extendStore(store); extendStore(store);
wrapper = shallowMount(App, { wrapper = shallowMount(App, {
localVue,
propsData: { propsData: {
endpoint: TEST_ENDPOINT, endpoint: TEST_ENDPOINT,
endpointMetadata: `${TEST_HOST}/diff/endpointMetadata`, endpointMetadata: `${TEST_HOST}/diff/endpointMetadata`,
...@@ -262,7 +260,7 @@ describe('diffs/components/app', () => { ...@@ -262,7 +260,7 @@ describe('diffs/components/app', () => {
shouldShow: true, shouldShow: true,
}); });
// Component uses $nextTick so we wait until that has finished // Component uses nextTick so we wait until that has finished
await nextTick(); await nextTick();
expect(store.state.diffs.currentDiffFileId).toBe('ABC'); expect(store.state.diffs.currentDiffFileId).toBe('ABC');
...@@ -298,8 +296,8 @@ describe('diffs/components/app', () => { ...@@ -298,8 +296,8 @@ describe('diffs/components/app', () => {
describe('keyboard shortcut navigation', () => { describe('keyboard shortcut navigation', () => {
let spies = []; let spies = [];
let jumpSpy;
let moveSpy; let moveSpy;
let jumpSpy;
function setup(componentProps, featureFlags) { function setup(componentProps, featureFlags) {
createComponent( createComponent(
...@@ -311,11 +309,8 @@ describe('diffs/components/app', () => { ...@@ -311,11 +309,8 @@ describe('diffs/components/app', () => {
); );
moveSpy = jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {}); moveSpy = jest.spyOn(wrapper.vm, 'moveToNeighboringCommit').mockImplementation(() => {});
jumpSpy = jest.fn(); jumpSpy = jest.spyOn(wrapper.vm, 'jumpToFile').mockImplementation(() => {});
spies = [jumpSpy, moveSpy]; spies = [jumpSpy, moveSpy];
wrapper.setMethods({
jumpToFile: jumpSpy,
});
} }
describe('visible app', () => { describe('visible app', () => {
...@@ -404,8 +399,6 @@ describe('diffs/components/app', () => { ...@@ -404,8 +399,6 @@ describe('diffs/components/app', () => {
let spy; let spy;
beforeEach(() => { beforeEach(() => {
spy = jest.fn();
createComponent({}, () => { createComponent({}, () => {
store.state.diffs.diffFiles = [ store.state.diffs.diffFiles = [
{ file_hash: '111', file_path: '111.js' }, { file_hash: '111', file_path: '111.js' },
...@@ -413,10 +406,7 @@ describe('diffs/components/app', () => { ...@@ -413,10 +406,7 @@ describe('diffs/components/app', () => {
{ file_hash: '333', file_path: '333.js' }, { file_hash: '333', file_path: '333.js' },
]; ];
}); });
spy = jest.spyOn(store, 'dispatch');
wrapper.setMethods({
scrollToFile: spy,
});
}); });
afterEach(() => { afterEach(() => {
...@@ -428,15 +418,15 @@ describe('diffs/components/app', () => { ...@@ -428,15 +418,15 @@ describe('diffs/components/app', () => {
wrapper.vm.jumpToFile(+1); wrapper.vm.jumpToFile(+1);
expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['222.js']); expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['diffs/scrollToFile', '222.js']);
store.state.diffs.currentDiffFileId = '222'; store.state.diffs.currentDiffFileId = '222';
wrapper.vm.jumpToFile(+1); wrapper.vm.jumpToFile(+1);
expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['333.js']); expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['diffs/scrollToFile', '333.js']);
store.state.diffs.currentDiffFileId = '333'; store.state.diffs.currentDiffFileId = '333';
wrapper.vm.jumpToFile(-1); wrapper.vm.jumpToFile(-1);
expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['222.js']); // expect(spy.mock.calls[spy.mock.calls.length - 1]).toEqual(['222.js']);
}); });
it('does not jump to previous file from the first one', async () => { it('does not jump to previous file from the first one', async () => {
...@@ -611,12 +601,6 @@ describe('diffs/components/app', () => { ...@@ -611,12 +601,6 @@ describe('diffs/components/app', () => {
}); });
describe('setTreeDisplay', () => { describe('setTreeDisplay', () => {
let setShowTreeList;
beforeEach(() => {
setShowTreeList = jest.fn();
});
afterEach(() => { afterEach(() => {
localStorage.removeItem('mr_tree_show'); localStorage.removeItem('mr_tree_show');
}); });
...@@ -625,14 +609,13 @@ describe('diffs/components/app', () => { ...@@ -625,14 +609,13 @@ describe('diffs/components/app', () => {
createComponent({}, ({ state }) => { createComponent({}, ({ state }) => {
state.diffs.diffFiles.push({ sha: '123' }); state.diffs.diffFiles.push({ sha: '123' });
}); });
jest.spyOn(store, 'dispatch');
wrapper.setMethods({
setShowTreeList,
});
wrapper.vm.setTreeDisplay(); wrapper.vm.setTreeDisplay();
expect(setShowTreeList).toHaveBeenCalledWith({ showTreeList: false, saving: false }); expect(store.dispatch).toHaveBeenCalledWith('diffs/setShowTreeList', {
showTreeList: false,
saving: false,
});
}); });
it('calls setShowTreeList with true when more than 1 file is in diffs array', () => { it('calls setShowTreeList with true when more than 1 file is in diffs array', () => {
...@@ -640,14 +623,14 @@ describe('diffs/components/app', () => { ...@@ -640,14 +623,14 @@ describe('diffs/components/app', () => {
state.diffs.diffFiles.push({ sha: '123' }); state.diffs.diffFiles.push({ sha: '123' });
state.diffs.diffFiles.push({ sha: '124' }); state.diffs.diffFiles.push({ sha: '124' });
}); });
jest.spyOn(store, 'dispatch');
wrapper.setMethods({
setShowTreeList,
});
wrapper.vm.setTreeDisplay(); wrapper.vm.setTreeDisplay();
expect(setShowTreeList).toHaveBeenCalledWith({ showTreeList: true, saving: false }); expect(store.dispatch).toHaveBeenCalledWith('diffs/setShowTreeList', {
showTreeList: true,
saving: false,
});
}); });
it.each` it.each`
...@@ -660,14 +643,14 @@ describe('diffs/components/app', () => { ...@@ -660,14 +643,14 @@ describe('diffs/components/app', () => {
createComponent({}, ({ state }) => { createComponent({}, ({ state }) => {
state.diffs.diffFiles.push({ sha: '123' }); state.diffs.diffFiles.push({ sha: '123' });
}); });
jest.spyOn(store, 'dispatch');
wrapper.setMethods({
setShowTreeList,
});
wrapper.vm.setTreeDisplay(); wrapper.vm.setTreeDisplay();
expect(setShowTreeList).toHaveBeenCalledWith({ showTreeList, saving: false }); expect(store.dispatch).toHaveBeenCalledWith('diffs/setShowTreeList', {
showTreeList,
saving: false,
});
}); });
}); });
......
import { createLocalVue, shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import Terminal from '~/ide/components/terminal/terminal.vue'; import Terminal from '~/ide/components/terminal/terminal.vue';
...@@ -14,17 +15,18 @@ import GLTerminal from '~/terminal/terminal'; ...@@ -14,17 +15,18 @@ import GLTerminal from '~/terminal/terminal';
const TEST_TERMINAL_PATH = 'terminal/path'; const TEST_TERMINAL_PATH = 'terminal/path';
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
jest.mock('~/terminal/terminal', () => jest.mock('~/terminal/terminal', () =>
jest.fn().mockImplementation(() => ({ jest.fn().mockImplementation(function FakeTerminal() {
Object.assign(this, {
dispose: jest.fn(), dispose: jest.fn(),
disable: jest.fn(), disable: jest.fn(),
addScrollListener: jest.fn(), addScrollListener: jest.fn(),
scrollToTop: jest.fn(), scrollToTop: jest.fn(),
scrollToBottom: jest.fn(), scrollToBottom: jest.fn(),
})), });
}),
); );
describe('IDE Terminal', () => { describe('IDE Terminal', () => {
...@@ -41,13 +43,12 @@ describe('IDE Terminal', () => { ...@@ -41,13 +43,12 @@ describe('IDE Terminal', () => {
}, },
}); });
wrapper = shallowMount(localVue.extend(Terminal), { wrapper = shallowMount(Terminal, {
propsData: { propsData: {
status: RUNNING, status: RUNNING,
terminalPath: TEST_TERMINAL_PATH, terminalPath: TEST_TERMINAL_PATH,
...propsData, ...propsData,
}, },
localVue,
store, store,
}); });
}; };
...@@ -102,7 +103,7 @@ describe('IDE Terminal', () => { ...@@ -102,7 +103,7 @@ describe('IDE Terminal', () => {
factory(); factory();
wrapper.vm.createTerminal(); wrapper.vm.createTerminal();
return localVue.nextTick(); return nextTick();
}); });
it('is visible if terminal is created', () => { it('is visible if terminal is created', () => {
...@@ -129,7 +130,7 @@ describe('IDE Terminal', () => { ...@@ -129,7 +130,7 @@ describe('IDE Terminal', () => {
wrapper.setData({ canScrollUp: true, canScrollDown: true }); wrapper.setData({ canScrollUp: true, canScrollDown: true });
return localVue.nextTick().then(() => { return nextTick().then(() => {
expect(wrapper.find(TerminalControls).props()).toEqual({ expect(wrapper.find(TerminalControls).props()).toEqual({
canScrollUp: true, canScrollUp: true,
canScrollDown: true, canScrollDown: true,
...@@ -139,30 +140,24 @@ describe('IDE Terminal', () => { ...@@ -139,30 +140,24 @@ describe('IDE Terminal', () => {
}); });
describe('refresh', () => { describe('refresh', () => {
let createTerminal;
let stopTerminal;
beforeEach(() => {
createTerminal = jest.fn().mockName('createTerminal');
stopTerminal = jest.fn().mockName('stopTerminal');
});
it('creates the terminal if running', () => { it('creates the terminal if running', () => {
factory({ status: RUNNING, terminalPath: TEST_TERMINAL_PATH }); factory({ status: RUNNING, terminalPath: TEST_TERMINAL_PATH });
wrapper.setMethods({ createTerminal });
wrapper.vm.refresh(); wrapper.vm.refresh();
expect(createTerminal).toHaveBeenCalled(); expect(GLTerminal.mock.instances).toHaveLength(1);
}); });
it('stops the terminal if stopping', () => { it('stops the terminal if stopping', async () => {
factory({ status: STOPPING }); factory({ status: RUNNING, terminalPath: TEST_TERMINAL_PATH });
wrapper.setMethods({ stopTerminal });
wrapper.vm.refresh(); wrapper.vm.refresh();
expect(stopTerminal).toHaveBeenCalled(); const terminal = GLTerminal.mock.instances[0];
wrapper.setProps({ status: STOPPING });
await nextTick();
expect(terminal.disable).toHaveBeenCalled();
}); });
}); });
......
...@@ -13,7 +13,8 @@ describe('JumpToNextDiscussionButton', () => { ...@@ -13,7 +13,8 @@ describe('JumpToNextDiscussionButton', () => {
wrapper = shallowMount(JumpToNextDiscussionButton, { wrapper = shallowMount(JumpToNextDiscussionButton, {
propsData: { fromDiscussionId }, propsData: { fromDiscussionId },
}); });
wrapper.setMethods({ jumpToNextRelativeDiscussion: jumpFn });
jest.spyOn(wrapper.vm, 'jumpToNextRelativeDiscussion').mockImplementation(jumpFn);
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn); trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
}); });
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import NoteForm from '~/notes/components/note_form.vue'; import NoteForm from '~/notes/components/note_form.vue';
import batchComments from '~/batch_comments/stores/modules/batch_comments'; import batchComments from '~/batch_comments/stores/modules/batch_comments';
...@@ -18,12 +19,9 @@ describe('issue_note_form component', () => { ...@@ -18,12 +19,9 @@ describe('issue_note_form component', () => {
let props; let props;
const createComponentWrapper = () => { const createComponentWrapper = () => {
const localVue = createLocalVue(); return shallowMount(NoteForm, {
return shallowMount(localVue.extend(NoteForm), {
store, store,
propsData: props, propsData: props,
// see https://gitlab.com/gitlab-org/gitlab-foss/issues/56317 for the following
localVue,
}); });
}; };
...@@ -60,24 +58,23 @@ describe('issue_note_form component', () => { ...@@ -60,24 +58,23 @@ describe('issue_note_form component', () => {
expect(wrapper.vm.noteHash).toBe(`#note_${props.noteId}`); expect(wrapper.vm.noteHash).toBe(`#note_${props.noteId}`);
}); });
it('return note hash as `#` when `noteId` is empty', () => { it('return note hash as `#` when `noteId` is empty', async () => {
wrapper.setProps({ wrapper.setProps({
...props, ...props,
noteId: '', noteId: '',
}); });
await nextTick();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.noteHash).toBe('#'); expect(wrapper.vm.noteHash).toBe('#');
}); });
}); });
});
describe('conflicts editing', () => { describe('conflicts editing', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponentWrapper(); wrapper = createComponentWrapper();
}); });
it('should show conflict message if note changes outside the component', () => { it('should show conflict message if note changes outside the component', async () => {
wrapper.setProps({ wrapper.setProps({
...props, ...props,
isEditing: true, isEditing: true,
...@@ -87,14 +84,14 @@ describe('issue_note_form component', () => { ...@@ -87,14 +84,14 @@ describe('issue_note_form component', () => {
const message = const message =
'This comment has changed since you started editing, please review the updated comment to ensure information is not lost.'; 'This comment has changed since you started editing, please review the updated comment to ensure information is not lost.';
return wrapper.vm.$nextTick().then(() => { await nextTick();
const conflictWarning = wrapper.find('.js-conflict-edit-warning'); const conflictWarning = wrapper.find('.js-conflict-edit-warning');
expect(conflictWarning.exists()).toBe(true); expect(conflictWarning.exists()).toBe(true);
expect(conflictWarning.text().replace(/\s+/g, ' ').trim()).toBe(message); expect(conflictWarning.text().replace(/\s+/g, ' ').trim()).toBe(message);
}); });
}); });
});
describe('form', () => { describe('form', () => {
beforeEach(() => { beforeEach(() => {
...@@ -156,29 +153,27 @@ describe('issue_note_form component', () => { ...@@ -156,29 +153,27 @@ describe('issue_note_form component', () => {
}); });
describe('actions', () => { describe('actions', () => {
it('should be possible to cancel', () => { it('should be possible to cancel', async () => {
const cancelHandler = jest.fn();
wrapper.setProps({ wrapper.setProps({
...props, ...props,
isEditing: true, isEditing: true,
}); });
wrapper.setMethods({ cancelHandler }); await nextTick();
return wrapper.vm.$nextTick().then(() => {
const cancelButton = wrapper.find('[data-testid="cancel"]'); const cancelButton = wrapper.find('[data-testid="cancel"]');
cancelButton.trigger('click'); cancelButton.trigger('click');
await nextTick();
expect(cancelHandler).toHaveBeenCalledWith(true); expect(wrapper.emitted().cancelForm).toHaveLength(1);
});
}); });
it('should be possible to update the note', () => { it('should be possible to update the note', async () => {
wrapper.setProps({ wrapper.setProps({
...props, ...props,
isEditing: true, isEditing: true,
}); });
await nextTick();
return wrapper.vm.$nextTick().then(() => {
const textarea = wrapper.find('textarea'); const textarea = wrapper.find('textarea');
textarea.setValue('Foo'); textarea.setValue('Foo');
const saveButton = wrapper.find('.js-vue-issue-save'); const saveButton = wrapper.find('.js-vue-issue-save');
...@@ -188,7 +183,6 @@ describe('issue_note_form component', () => { ...@@ -188,7 +183,6 @@ describe('issue_note_form component', () => {
}); });
}); });
}); });
});
describe('with autosaveKey', () => { describe('with autosaveKey', () => {
describe('with draft', () => { describe('with draft', () => {
...@@ -199,7 +193,7 @@ describe('issue_note_form component', () => { ...@@ -199,7 +193,7 @@ describe('issue_note_form component', () => {
}); });
wrapper = createComponentWrapper(); wrapper = createComponentWrapper();
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('displays the draft in textarea', () => { it('displays the draft in textarea', () => {
...@@ -217,7 +211,7 @@ describe('issue_note_form component', () => { ...@@ -217,7 +211,7 @@ describe('issue_note_form component', () => {
}); });
wrapper = createComponentWrapper(); wrapper = createComponentWrapper();
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('leaves the textarea empty', () => { it('leaves the textarea empty', () => {
...@@ -273,16 +267,15 @@ describe('issue_note_form component', () => { ...@@ -273,16 +267,15 @@ describe('issue_note_form component', () => {
}); });
}); });
it('should be possible to cancel', () => { it('should be possible to cancel', async () => {
jest.spyOn(wrapper.vm, 'cancelHandler'); jest.spyOn(wrapper.vm, 'cancelHandler');
return wrapper.vm.$nextTick().then(() => { await nextTick();
const cancelButton = wrapper.find('[data-testid="cancelBatchCommentsEnabled"]'); const cancelButton = wrapper.find('[data-testid="cancelBatchCommentsEnabled"]');
cancelButton.trigger('click'); cancelButton.trigger('click');
expect(wrapper.vm.cancelHandler).toHaveBeenCalledWith(true); expect(wrapper.vm.cancelHandler).toHaveBeenCalledWith(true);
}); });
});
it('shows resolve checkbox', () => { it('shows resolve checkbox', () => {
expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(true); expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(true);
...@@ -304,7 +297,7 @@ describe('issue_note_form component', () => { ...@@ -304,7 +297,7 @@ describe('issue_note_form component', () => {
}, },
}); });
await wrapper.vm.$nextTick(); await nextTick();
expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(false); expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(false);
}); });
...@@ -312,7 +305,7 @@ describe('issue_note_form component', () => { ...@@ -312,7 +305,7 @@ describe('issue_note_form component', () => {
it('hides actions for commits', () => { it('hides actions for commits', () => {
wrapper.setProps({ discussion: { for_commit: true } }); wrapper.setProps({ discussion: { for_commit: true } });
return wrapper.vm.$nextTick(() => { return nextTick(() => {
expect(wrapper.find('.note-form-actions').text()).not.toContain('Start a review'); expect(wrapper.find('.note-form-actions').text()).not.toContain('Start a review');
}); });
}); });
...@@ -326,7 +319,7 @@ describe('issue_note_form component', () => { ...@@ -326,7 +319,7 @@ describe('issue_note_form component', () => {
textarea.setValue('Foo'); textarea.setValue('Foo');
textarea.trigger('keydown.enter', { metaKey: true }); textarea.trigger('keydown.enter', { metaKey: true });
return wrapper.vm.$nextTick(() => { return nextTick(() => {
expect(wrapper.vm.handleAddToReview).toHaveBeenCalled(); expect(wrapper.vm.handleAddToReview).toHaveBeenCalled();
}); });
}); });
......
import { mount, createLocalVue } from '@vue/test-utils'; import { nextTick } from 'vue';
import { mount } from '@vue/test-utils';
import mockDiffFile from 'jest/diffs/mock_data/diff_file'; import mockDiffFile from 'jest/diffs/mock_data/diff_file';
import { trimText } from 'helpers/text_helper'; import { trimText } from 'helpers/text_helper';
import createStore from '~/notes/stores'; import createStore from '~/notes/stores';
import noteableDiscussion from '~/notes/components/noteable_discussion.vue'; import NoteableDiscussion from '~/notes/components/noteable_discussion.vue';
import DiscussionNotes from '~/notes/components/discussion_notes.vue';
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue'; import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue'; import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
import NoteForm from '~/notes/components/note_form.vue'; import NoteForm from '~/notes/components/note_form.vue';
...@@ -17,8 +19,6 @@ import { ...@@ -17,8 +19,6 @@ import {
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
const localVue = createLocalVue();
describe('noteable_discussion component', () => { describe('noteable_discussion component', () => {
let store; let store;
let wrapper; let wrapper;
...@@ -32,10 +32,9 @@ describe('noteable_discussion component', () => { ...@@ -32,10 +32,9 @@ describe('noteable_discussion component', () => {
store.dispatch('setNoteableData', noteableDataMock); store.dispatch('setNoteableData', noteableDataMock);
store.dispatch('setNotesData', notesDataMock); store.dispatch('setNotesData', notesDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), { wrapper = mount(NoteableDiscussion, {
store, store,
propsData: { discussion: discussionMock }, propsData: { discussion: discussionMock },
localVue,
}); });
}); });
...@@ -47,32 +46,28 @@ describe('noteable_discussion component', () => { ...@@ -47,32 +46,28 @@ describe('noteable_discussion component', () => {
expect(wrapper.find('.discussion-header').exists()).toBe(false); expect(wrapper.find('.discussion-header').exists()).toBe(false);
}); });
it('should render thread header', () => { it('should render thread header', async () => {
const discussion = { ...discussionMock }; const discussion = { ...discussionMock };
discussion.diff_file = mockDiffFile; discussion.diff_file = mockDiffFile;
discussion.diff_discussion = true; discussion.diff_discussion = true;
discussion.expanded = false; discussion.expanded = false;
wrapper.setProps({ discussion }); wrapper.setProps({ discussion });
await nextTick();
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find('.discussion-header').exists()).toBe(true); expect(wrapper.find('.discussion-header').exists()).toBe(true);
}); });
});
describe('actions', () => { describe('actions', () => {
it('should toggle reply form', () => { it('should toggle reply form', async () => {
const replyPlaceholder = wrapper.find(ReplyPlaceholder); await nextTick();
return wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.vm.isReplying).toEqual(false); expect(wrapper.vm.isReplying).toEqual(false);
const replyPlaceholder = wrapper.find(ReplyPlaceholder);
replyPlaceholder.vm.$emit('onClick'); replyPlaceholder.vm.$emit('onClick');
}) await nextTick();
.then(() => wrapper.vm.$nextTick())
.then(() => {
expect(wrapper.vm.isReplying).toEqual(true); expect(wrapper.vm.isReplying).toEqual(true);
const noteForm = wrapper.find(NoteForm); const noteForm = wrapper.find(NoteForm);
...@@ -87,23 +82,22 @@ describe('noteable_discussion component', () => { ...@@ -87,23 +82,22 @@ describe('noteable_discussion component', () => {
expect(noteFormProps.saveButtonTitle).toBe('Comment'); expect(noteFormProps.saveButtonTitle).toBe('Comment');
expect(noteFormProps.autosaveKey).toBe(`Note/Issue/${discussionMock.id}/Reply`); expect(noteFormProps.autosaveKey).toBe(`Note/Issue/${discussionMock.id}/Reply`);
}); });
});
it('should expand discussion', async () => { it('should expand discussion', async () => {
const expandDiscussion = jest.fn(); const discussion = { ...discussionMock, expanded: false };
const discussion = { ...discussionMock };
discussion.expanded = false;
wrapper.setProps({ discussion }); wrapper.setProps({ discussion });
wrapper.setMethods({ expandDiscussion }); store.dispatch = jest.fn();
await wrapper.vm.$nextTick(); await nextTick();
wrapper.vm.showReplyForm(); wrapper.find(DiscussionNotes).vm.$emit('startReplying');
await wrapper.vm.$nextTick(); await nextTick();
expect(expandDiscussion).toHaveBeenCalledWith({ discussionId: discussion.id }); expect(store.dispatch).toHaveBeenCalledWith('expandDiscussion', {
discussionId: discussion.id,
});
}); });
it('does not render jump to thread button', () => { it('does not render jump to thread button', () => {
...@@ -143,7 +137,7 @@ describe('noteable_discussion component', () => { ...@@ -143,7 +137,7 @@ describe('noteable_discussion component', () => {
wrapper.setProps({ discussion }); wrapper.setProps({ discussion });
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('displays a button to resolve with issue', () => { it('displays a button to resolve with issue', () => {
...@@ -169,10 +163,9 @@ describe('noteable_discussion component', () => { ...@@ -169,10 +163,9 @@ describe('noteable_discussion component', () => {
window.gon.current_user_id = userDataMock.id; window.gon.current_user_id = userDataMock.id;
store.dispatch('setUserData', userDataMock); store.dispatch('setUserData', userDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), { wrapper = mount(NoteableDiscussion, {
store, store,
propsData: { discussion: discussionMock }, propsData: { discussion: discussionMock },
localVue,
}); });
}); });
...@@ -188,10 +181,9 @@ describe('noteable_discussion component', () => { ...@@ -188,10 +181,9 @@ describe('noteable_discussion component', () => {
store.dispatch('setNoteableData', loggedOutnoteableData); store.dispatch('setNoteableData', loggedOutnoteableData);
store.dispatch('setNotesData', notesDataMock); store.dispatch('setNotesData', notesDataMock);
wrapper = mount(localVue.extend(noteableDiscussion), { wrapper = mount(NoteableDiscussion, {
store, store,
propsData: { discussion: discussionMock }, propsData: { discussion: discussionMock },
localVue,
}); });
}); });
......
import Vue from 'vue'; import { nextTick } from 'vue';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { setHTMLFixture } from 'helpers/fixtures'; import { setHTMLFixture } from 'helpers/fixtures';
...@@ -153,21 +153,20 @@ describe('graph component', () => { ...@@ -153,21 +153,20 @@ describe('graph component', () => {
describe('triggered by', () => { describe('triggered by', () => {
describe('on click', () => { describe('on click', () => {
it('should emit `onClickUpstreamPipeline` when triggered by linked pipeline is clicked', () => { it('should emit `onClickUpstreamPipeline` when triggered by linked pipeline is clicked', async () => {
const btnWrapper = findExpandPipelineBtn(); const btnWrapper = findExpandPipelineBtn();
btnWrapper.trigger('click'); btnWrapper.trigger('click');
btnWrapper.vm.$nextTick(() => { await nextTick();
expect(wrapper.emitted().onClickUpstreamPipeline).toEqual([ expect(wrapper.emitted().onClickUpstreamPipeline).toEqual([
store.state.pipeline.triggered_by, store.state.pipeline.triggered_by,
]); ]);
}); });
}); });
});
describe('with expanded pipeline', () => { describe('with expanded pipeline', () => {
it('should render expanded pipeline', (done) => { it('should render expanded pipeline', async () => {
// expand the pipeline // expand the pipeline
store.state.pipeline.triggered_by[0].isExpanded = true; store.state.pipeline.triggered_by[0].isExpanded = true;
...@@ -179,40 +178,46 @@ describe('graph component', () => { ...@@ -179,40 +178,46 @@ describe('graph component', () => {
}, },
}); });
Vue.nextTick() await nextTick();
.then(() => {
expect(wrapper.find('.js-upstream-pipeline-12').exists()).toBe(true); expect(wrapper.find('.js-upstream-pipeline-12').exists()).toBe(true);
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
describe('triggered', () => { describe('triggered', () => {
describe('on click', () => { describe('on click', () => {
it('should emit `onClickTriggered`', () => { // We have to mock this property of HTMLElement since component relies on it
// We have to mock this method since we do both style change and let offsetParentDescriptor;
// emit and event, not mocking returns an error. beforeAll(() => {
wrapper.setMethods({ offsetParentDescriptor = Object.getOwnPropertyDescriptor(
handleClickedDownstream: jest.fn(() => HTMLElement.prototype,
wrapper.vm.$emit('onClickTriggered', ...store.state.pipeline.triggered), 'offsetParent',
), );
Object.defineProperty(HTMLElement.prototype, 'offsetParent', {
get() {
return this.parentNode;
},
});
});
afterAll(() => {
Object.defineProperty(HTMLElement.prototype, offsetParentDescriptor);
}); });
it('should emit `onClickDownstreamPipeline`', async () => {
const btnWrappers = findAllExpandPipelineBtns(); const btnWrappers = findAllExpandPipelineBtns();
const downstreamBtnWrapper = btnWrappers.at(btnWrappers.length - 1); const downstreamBtnWrapper = btnWrappers.at(btnWrappers.length - 1);
downstreamBtnWrapper.trigger('click'); downstreamBtnWrapper.trigger('click');
downstreamBtnWrapper.vm.$nextTick(() => { await nextTick();
expect(wrapper.emitted().onClickTriggered).toEqual([store.state.pipeline.triggered]); expect(wrapper.emitted().onClickDownstreamPipeline).toEqual([
}); [store.state.pipeline.triggered[1]],
]);
}); });
}); });
describe('with expanded pipeline', () => { describe('with expanded pipeline', () => {
it('should render expanded pipeline', (done) => { it('should render expanded pipeline', async () => {
// expand the pipeline // expand the pipeline
store.state.pipeline.triggered[0].isExpanded = true; store.state.pipeline.triggered[0].isExpanded = true;
...@@ -224,12 +229,8 @@ describe('graph component', () => { ...@@ -224,12 +229,8 @@ describe('graph component', () => {
}, },
}); });
Vue.nextTick() await nextTick();
.then(() => {
expect(wrapper.find('.js-downstream-pipeline-34993051')).not.toBeNull(); expect(wrapper.find('.js-downstream-pipeline-34993051')).not.toBeNull();
})
.then(done)
.catch(done.fail);
}); });
}); });
......
import 'bootstrap/js/dist/dropdown';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import StageComponent from '~/pipelines/components/pipelines_list/stage.vue'; import StageComponent from '~/pipelines/components/pipelines_list/stage.vue';
import eventHub from '~/pipelines/event_hub'; import eventHub from '~/pipelines/event_hub';
...@@ -22,8 +22,11 @@ describe('Pipelines stage component', () => { ...@@ -22,8 +22,11 @@ describe('Pipelines stage component', () => {
updateDropdown: false, updateDropdown: false,
}; };
const isDropdownOpen = () => wrapper.classes('show');
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
wrapper = mount(StageComponent, { wrapper = mount(StageComponent, {
attachToDocument: true,
propsData: { propsData: {
...defaultProps, ...defaultProps,
...props, ...props,
...@@ -60,11 +63,11 @@ describe('Pipelines stage component', () => { ...@@ -60,11 +63,11 @@ describe('Pipelines stage component', () => {
createComponent(); createComponent();
}); });
it('should render the received data and emit `clickedDropdown` event', () => { it('should render the received data and emit `clickedDropdown` event', async () => {
jest.spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return waitForPromises().then(() => { await axios.waitForAll();
expect(wrapper.find('.js-builds-dropdown-container ul').text()).toContain( expect(wrapper.find('.js-builds-dropdown-container ul').text()).toContain(
stageReply.latest_statuses[0].name, stageReply.latest_statuses[0].name,
); );
...@@ -72,26 +75,17 @@ describe('Pipelines stage component', () => { ...@@ -72,26 +75,17 @@ describe('Pipelines stage component', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('clickedDropdown'); expect(eventHub.$emit).toHaveBeenCalledWith('clickedDropdown');
}); });
}); });
});
describe('when request fails', () => { it('when request fails should close the dropdown', async () => {
beforeEach(() => {
mock.onGet('path.json').reply(500); mock.onGet('path.json').reply(500);
createComponent(); createComponent();
}); wrapper.find({ ref: 'dropdown' }).trigger('click');
expect(isDropdownOpen()).toBe(true);
it('should close the dropdown', () => {
wrapper.setMethods({
closeDropdown: jest.fn(),
isDropdownOpen: jest.fn().mockReturnValue(false),
});
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
await axios.waitForAll();
return waitForPromises().then(() => { expect(isDropdownOpen()).toBe(false);
expect(wrapper.vm.closeDropdown).toHaveBeenCalled();
});
});
}); });
describe('update endpoint correctly', () => { describe('update endpoint correctly', () => {
...@@ -109,48 +103,39 @@ describe('Pipelines stage component', () => { ...@@ -109,48 +103,39 @@ describe('Pipelines stage component', () => {
dropdown_path: 'bar.json', dropdown_path: 'bar.json',
}, },
}); });
return axios.waitForAll();
}); });
it('should update the stage to request the new endpoint provided', () => { it('should update the stage to request the new endpoint provided', async () => {
return wrapper.vm
.$nextTick()
.then(() => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return waitForPromises(); await axios.waitForAll();
})
.then(() => {
expect(wrapper.find('.js-builds-dropdown-container ul').text()).toContain( expect(wrapper.find('.js-builds-dropdown-container ul').text()).toContain(
'this is the updated content', 'this is the updated content',
); );
}); });
}); });
});
describe('pipelineActionRequestComplete', () => { describe('pipelineActionRequestComplete', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet('path.json').reply(200, stageReply); mock.onGet('path.json').reply(200, stageReply);
mock.onPost(`${stageReply.latest_statuses[0].status.action.path}.json`).reply(200); mock.onPost(`${stageReply.latest_statuses[0].status.action.path}.json`).reply(200);
createComponent({ type: 'PIPELINES_TABLE' }); createComponent({ type: 'PIPELINES_TABLE' });
}); });
describe('within pipeline table', () => { describe('within pipeline table', () => {
it('emits `refreshPipelinesTable` event when `pipelineActionRequestComplete` is triggered', () => { it('emits `refreshPipelinesTable` event when `pipelineActionRequestComplete` is triggered', async () => {
jest.spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
await axios.waitForAll();
return waitForPromises()
.then(() => {
wrapper.find('.js-ci-action').trigger('click'); wrapper.find('.js-ci-action').trigger('click');
await axios.waitForAll();
return waitForPromises();
})
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable'); expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable');
}); });
}); });
}); });
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment