Commit 0affa6c6 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'vs/remove-jest-test-callback-part-four' into 'master'

Remove jest test callbacks from specs (3/3)

See merge request gitlab-org/gitlab!84481
parents 301d965e 2713ddb6
...@@ -70,29 +70,17 @@ describe('Commits List', () => { ...@@ -70,29 +70,17 @@ describe('Commits List', () => {
mock.restore(); mock.restore();
}); });
it('should save the last search string', (done) => { it('should save the last search string', async () => {
commitsList.searchField.val('GitLab'); commitsList.searchField.val('GitLab');
commitsList await commitsList.filterResults();
.filterResults()
.then(() => {
expect(ajaxSpy).toHaveBeenCalled(); expect(ajaxSpy).toHaveBeenCalled();
expect(commitsList.lastSearch).toEqual('GitLab'); expect(commitsList.lastSearch).toEqual('GitLab');
done();
})
.catch(done.fail);
}); });
it('should not make ajax call if the input does not change', (done) => { it('should not make ajax call if the input does not change', async () => {
commitsList await commitsList.filterResults();
.filterResults()
.then(() => {
expect(ajaxSpy).not.toHaveBeenCalled(); expect(ajaxSpy).not.toHaveBeenCalled();
expect(commitsList.lastSearch).toEqual(''); expect(commitsList.lastSearch).toEqual('');
done();
})
.catch(done.fail);
}); });
}); });
}); });
...@@ -40,30 +40,22 @@ describe('GpgBadges', () => { ...@@ -40,30 +40,22 @@ describe('GpgBadges', () => {
mock.restore(); mock.restore();
}); });
it('does not make a request if there is no container element', (done) => { it('does not make a request if there is no container element', async () => {
setFixtures(''); setFixtures('');
jest.spyOn(axios, 'get').mockImplementation(() => {}); jest.spyOn(axios, 'get').mockImplementation(() => {});
GpgBadges.fetch() await GpgBadges.fetch();
.then(() => {
expect(axios.get).not.toHaveBeenCalled(); expect(axios.get).not.toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
it('throws an error if the endpoint is missing', (done) => { it('throws an error if the endpoint is missing', async () => {
setFixtures('<div class="js-signature-container"></div>'); setFixtures('<div class="js-signature-container"></div>');
jest.spyOn(axios, 'get').mockImplementation(() => {}); jest.spyOn(axios, 'get').mockImplementation(() => {});
GpgBadges.fetch() await expect(GpgBadges.fetch()).rejects.toEqual(
.then(() => done.fail('Expected error to be thrown')) new Error('Missing commit signatures endpoint!'),
.catch((error) => { );
expect(error.message).toBe('Missing commit signatures endpoint!');
expect(axios.get).not.toHaveBeenCalled(); expect(axios.get).not.toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
it('fetches commit signatures', async () => { it('fetches commit signatures', async () => {
...@@ -104,31 +96,23 @@ describe('GpgBadges', () => { ...@@ -104,31 +96,23 @@ describe('GpgBadges', () => {
}); });
}); });
it('displays a loading spinner', (done) => { it('displays a loading spinner', async () => {
mock.onGet(dummyUrl).replyOnce(200); mock.onGet(dummyUrl).replyOnce(200);
GpgBadges.fetch() await GpgBadges.fetch();
.then(() => {
expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null); expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null);
const spinners = document.querySelectorAll('.js-loading-gpg-badge span.gl-spinner'); const spinners = document.querySelectorAll('.js-loading-gpg-badge span.gl-spinner');
expect(spinners.length).toBe(1); expect(spinners.length).toBe(1);
done();
})
.catch(done.fail);
}); });
it('replaces the loading spinner', (done) => { it('replaces the loading spinner', async () => {
mock.onGet(dummyUrl).replyOnce(200, dummyResponse); mock.onGet(dummyUrl).replyOnce(200, dummyResponse);
GpgBadges.fetch() await GpgBadges.fetch();
.then(() => {
expect(document.querySelector('.js-loading-gpg-badge')).toBe(null); expect(document.querySelector('.js-loading-gpg-badge')).toBe(null);
const parentContainer = document.querySelector('.parent-container'); const parentContainer = document.querySelector('.parent-container');
expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml); expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -23,13 +23,12 @@ describe('AccountAndLimits', () => { ...@@ -23,13 +23,12 @@ describe('AccountAndLimits', () => {
expect($userInternalRegex.readOnly).toBeTruthy(); expect($userInternalRegex.readOnly).toBeTruthy();
}); });
it('is checked', (done) => { it('is checked', () => {
if (!$userDefaultExternal.prop('checked')) $userDefaultExternal.click(); if (!$userDefaultExternal.prop('checked')) $userDefaultExternal.click();
expect($userDefaultExternal.prop('checked')).toBeTruthy(); expect($userDefaultExternal.prop('checked')).toBeTruthy();
expect($userInternalRegex.placeholder).toEqual(PLACEHOLDER_USER_EXTERNAL_DEFAULT_TRUE); expect($userInternalRegex.placeholder).toEqual(PLACEHOLDER_USER_EXTERNAL_DEFAULT_TRUE);
expect($userInternalRegex.readOnly).toBeFalsy(); expect($userInternalRegex.readOnly).toBeFalsy();
done();
}); });
}); });
}); });
...@@ -26,7 +26,7 @@ describe('stop_jobs_modal.vue', () => { ...@@ -26,7 +26,7 @@ describe('stop_jobs_modal.vue', () => {
}); });
describe('onSubmit', () => { describe('onSubmit', () => {
it('stops jobs and redirects to overview page', (done) => { it('stops jobs and redirects to overview page', async () => {
const responseURL = `${TEST_HOST}/stop_jobs_modal.vue/jobs`; const responseURL = `${TEST_HOST}/stop_jobs_modal.vue/jobs`;
jest.spyOn(axios, 'post').mockImplementation((url) => { jest.spyOn(axios, 'post').mockImplementation((url) => {
expect(url).toBe(props.url); expect(url).toBe(props.url);
...@@ -37,29 +37,19 @@ describe('stop_jobs_modal.vue', () => { ...@@ -37,29 +37,19 @@ describe('stop_jobs_modal.vue', () => {
}); });
}); });
vm.onSubmit() await vm.onSubmit();
.then(() => {
expect(redirectTo).toHaveBeenCalledWith(responseURL); expect(redirectTo).toHaveBeenCalledWith(responseURL);
})
.then(done)
.catch(done.fail);
}); });
it('displays error if stopping jobs failed', (done) => { it('displays error if stopping jobs failed', async () => {
const dummyError = new Error('stopping jobs failed'); const dummyError = new Error('stopping jobs failed');
jest.spyOn(axios, 'post').mockImplementation((url) => { jest.spyOn(axios, 'post').mockImplementation((url) => {
expect(url).toBe(props.url); expect(url).toBe(props.url);
return Promise.reject(dummyError); return Promise.reject(dummyError);
}); });
vm.onSubmit() await expect(vm.onSubmit()).rejects.toEqual(dummyError);
.then(done.fail)
.catch((error) => {
expect(error).toBe(dummyError);
expect(redirectTo).not.toHaveBeenCalled(); expect(redirectTo).not.toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -31,15 +31,17 @@ describe('Todos', () => { ...@@ -31,15 +31,17 @@ describe('Todos', () => {
}); });
describe('goToTodoUrl', () => { describe('goToTodoUrl', () => {
it('opens the todo url', (done) => { it('opens the todo url', () => {
const todoLink = todoItem.dataset.url; const todoLink = todoItem.dataset.url;
let expectedUrl = null;
visitUrl.mockImplementation((url) => { visitUrl.mockImplementation((url) => {
expect(url).toEqual(todoLink); expectedUrl = url;
done();
}); });
todoItem.click(); todoItem.click();
expect(expectedUrl).toEqual(todoLink);
}); });
describe('meta click', () => { describe('meta click', () => {
......
...@@ -46,22 +46,18 @@ describe('EmojiMenu', () => { ...@@ -46,22 +46,18 @@ describe('EmojiMenu', () => {
const dummyEmoji = 'tropical_fish'; const dummyEmoji = 'tropical_fish';
const dummyVotesBlock = () => $('<div />'); const dummyVotesBlock = () => $('<div />');
it('calls selectEmojiCallback', (done) => { it('calls selectEmojiCallback', async () => {
expect(dummySelectEmojiCallback).not.toHaveBeenCalled(); expect(dummySelectEmojiCallback).not.toHaveBeenCalled();
emojiMenu.addAward(dummyVotesBlock(), dummyAwardUrl, dummyEmoji, false, () => { await emojiMenu.addAward(dummyVotesBlock(), dummyAwardUrl, dummyEmoji, false);
expect(dummySelectEmojiCallback).toHaveBeenCalledWith(dummyEmoji, dummyEmojiTag); expect(dummySelectEmojiCallback).toHaveBeenCalledWith(dummyEmoji, dummyEmojiTag);
done();
});
}); });
it('does not make an axios request', (done) => { it('does not make an axios request', async () => {
jest.spyOn(axios, 'request').mockReturnValue(); jest.spyOn(axios, 'request').mockReturnValue();
emojiMenu.addAward(dummyVotesBlock(), dummyAwardUrl, dummyEmoji, false, () => { await emojiMenu.addAward(dummyVotesBlock(), dummyAwardUrl, dummyEmoji, false);
expect(axios.request).not.toHaveBeenCalled(); expect(axios.request).not.toHaveBeenCalled();
done();
});
}); });
}); });
......
import Vue from 'vue'; import Vue, { nextTick } from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper'; import mountComponent from 'helpers/vue_mount_component_helper';
import PageComponent from '~/pdf/page/index.vue'; import PageComponent from '~/pdf/page/index.vue';
...@@ -14,8 +14,7 @@ describe('Page component', () => { ...@@ -14,8 +14,7 @@ describe('Page component', () => {
vm.$destroy(); vm.$destroy();
}); });
it('renders the page when mounting', (done) => { it('renders the page when mounting', async () => {
const promise = Promise.resolve();
const testPage = { const testPage = {
render: jest.fn().mockReturnValue({ promise: Promise.resolve() }), render: jest.fn().mockReturnValue({ promise: Promise.resolve() }),
getViewport: jest.fn().mockReturnValue({}), getViewport: jest.fn().mockReturnValue({}),
...@@ -28,12 +27,9 @@ describe('Page component', () => { ...@@ -28,12 +27,9 @@ describe('Page component', () => {
expect(vm.rendering).toBe(true); expect(vm.rendering).toBe(true);
promise await nextTick();
.then(() => {
expect(testPage.render).toHaveBeenCalledWith(vm.renderContext); expect(testPage.render).toHaveBeenCalledWith(vm.renderContext);
expect(vm.rendering).toBe(false); expect(vm.rendering).toBe(false);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -48,17 +48,14 @@ describe('pipeline graph action component', () => { ...@@ -48,17 +48,14 @@ describe('pipeline graph action component', () => {
}); });
describe('on click', () => { describe('on click', () => {
it('emits `pipelineActionRequestComplete` after a successful request', (done) => { it('emits `pipelineActionRequestComplete` after a successful request', async () => {
jest.spyOn(wrapper.vm, '$emit'); jest.spyOn(wrapper.vm, '$emit');
findButton().trigger('click'); findButton().trigger('click');
waitForPromises() await waitForPromises();
.then(() => {
expect(wrapper.vm.$emit).toHaveBeenCalledWith('pipelineActionRequestComplete'); expect(wrapper.vm.$emit).toHaveBeenCalledWith('pipelineActionRequestComplete');
done();
})
.catch(done.fail);
}); });
it('renders a loading icon while waiting for request', async () => { it('renders a loading icon while waiting for request', async () => {
......
...@@ -38,29 +38,25 @@ describe('Actions TestReports Store', () => { ...@@ -38,29 +38,25 @@ describe('Actions TestReports Store', () => {
mock.onGet(summaryEndpoint).replyOnce(200, summary, {}); mock.onGet(summaryEndpoint).replyOnce(200, summary, {});
}); });
it('sets testReports and shows tests', (done) => { it('sets testReports and shows tests', () => {
testAction( return testAction(
actions.fetchSummary, actions.fetchSummary,
null, null,
state, state,
[{ type: types.SET_SUMMARY, payload: summary }], [{ type: types.SET_SUMMARY, payload: summary }],
[{ type: 'toggleLoading' }, { type: 'toggleLoading' }], [{ type: 'toggleLoading' }, { type: 'toggleLoading' }],
done,
); );
}); });
it('should create flash on API error', (done) => { it('should create flash on API error', async () => {
testAction( await testAction(
actions.fetchSummary, actions.fetchSummary,
null, null,
{ summaryEndpoint: null }, { summaryEndpoint: null },
[], [],
[{ type: 'toggleLoading' }, { type: 'toggleLoading' }], [{ type: 'toggleLoading' }, { type: 'toggleLoading' }],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
); );
expect(createFlash).toHaveBeenCalled();
}); });
}); });
...@@ -73,87 +69,80 @@ describe('Actions TestReports Store', () => { ...@@ -73,87 +69,80 @@ describe('Actions TestReports Store', () => {
.replyOnce(200, testReports.test_suites[0], {}); .replyOnce(200, testReports.test_suites[0], {});
}); });
it('sets test suite and shows tests', (done) => { it('sets test suite and shows tests', () => {
const suite = testReports.test_suites[0]; const suite = testReports.test_suites[0];
const index = 0; const index = 0;
testAction( return testAction(
actions.fetchTestSuite, actions.fetchTestSuite,
index, index,
{ ...state, testReports }, { ...state, testReports },
[{ type: types.SET_SUITE, payload: { suite, index } }], [{ type: types.SET_SUITE, payload: { suite, index } }],
[{ type: 'toggleLoading' }, { type: 'toggleLoading' }], [{ type: 'toggleLoading' }, { type: 'toggleLoading' }],
done,
); );
}); });
it('should create flash on API error', (done) => { it('should create flash on API error', async () => {
const index = 0; const index = 0;
testAction( await testAction(
actions.fetchTestSuite, actions.fetchTestSuite,
index, index,
{ ...state, testReports, suiteEndpoint: null }, { ...state, testReports, suiteEndpoint: null },
[], [],
[{ type: 'toggleLoading' }, { type: 'toggleLoading' }], [{ type: 'toggleLoading' }, { type: 'toggleLoading' }],
() => {
expect(createFlash).toHaveBeenCalled();
done();
},
); );
expect(createFlash).toHaveBeenCalled();
}); });
describe('when we already have the suite data', () => { describe('when we already have the suite data', () => {
it('should not fetch suite', (done) => { it('should not fetch suite', () => {
const index = 0; const index = 0;
testReports.test_suites[0].hasFullSuite = true; testReports.test_suites[0].hasFullSuite = true;
testAction(actions.fetchTestSuite, index, { ...state, testReports }, [], [], done); return testAction(actions.fetchTestSuite, index, { ...state, testReports }, [], []);
}); });
}); });
}); });
describe('set selected suite index', () => { describe('set selected suite index', () => {
it('sets selectedSuiteIndex', (done) => { it('sets selectedSuiteIndex', () => {
const selectedSuiteIndex = 0; const selectedSuiteIndex = 0;
testAction( return testAction(
actions.setSelectedSuiteIndex, actions.setSelectedSuiteIndex,
selectedSuiteIndex, selectedSuiteIndex,
{ ...state, hasFullReport: true }, { ...state, hasFullReport: true },
[{ type: types.SET_SELECTED_SUITE_INDEX, payload: selectedSuiteIndex }], [{ type: types.SET_SELECTED_SUITE_INDEX, payload: selectedSuiteIndex }],
[], [],
done,
); );
}); });
}); });
describe('remove selected suite index', () => { describe('remove selected suite index', () => {
it('sets selectedSuiteIndex to null', (done) => { it('sets selectedSuiteIndex to null', () => {
testAction( return testAction(
actions.removeSelectedSuiteIndex, actions.removeSelectedSuiteIndex,
{}, {},
state, state,
[{ type: types.SET_SELECTED_SUITE_INDEX, payload: null }], [{ type: types.SET_SELECTED_SUITE_INDEX, payload: null }],
[], [],
done,
); );
}); });
}); });
describe('toggles loading', () => { describe('toggles loading', () => {
it('sets isLoading to true', (done) => { it('sets isLoading to true', () => {
testAction(actions.toggleLoading, {}, state, [{ type: types.TOGGLE_LOADING }], [], done); return testAction(actions.toggleLoading, {}, state, [{ type: types.TOGGLE_LOADING }], []);
}); });
it('toggles isLoading to false', (done) => { it('toggles isLoading to false', () => {
testAction( return testAction(
actions.toggleLoading, actions.toggleLoading,
{}, {},
{ ...state, isLoading: true }, { ...state, isLoading: true },
[{ type: types.TOGGLE_LOADING }], [{ type: types.TOGGLE_LOADING }],
[], [],
done,
); );
}); });
}); });
......
...@@ -44,12 +44,12 @@ describe('Commit form modal store actions', () => { ...@@ -44,12 +44,12 @@ describe('Commit form modal store actions', () => {
}); });
describe('fetchBranches', () => { describe('fetchBranches', () => {
it('dispatch correct actions on fetchBranches', (done) => { it('dispatch correct actions on fetchBranches', () => {
jest jest
.spyOn(axios, 'get') .spyOn(axios, 'get')
.mockImplementation(() => Promise.resolve({ data: { Branches: mockData.mockBranches } })); .mockImplementation(() => Promise.resolve({ data: { Branches: mockData.mockBranches } }));
testAction( return testAction(
actions.fetchBranches, actions.fetchBranches,
{}, {},
state, state,
...@@ -60,19 +60,15 @@ describe('Commit form modal store actions', () => { ...@@ -60,19 +60,15 @@ describe('Commit form modal store actions', () => {
}, },
], ],
[{ type: 'requestBranches' }], [{ type: 'requestBranches' }],
() => {
done();
},
); );
}); });
it('should show flash error and set error in state on fetchBranches failure', (done) => { it('should show flash error and set error in state on fetchBranches failure', async () => {
jest.spyOn(axios, 'get').mockRejectedValue(); jest.spyOn(axios, 'get').mockRejectedValue();
testAction(actions.fetchBranches, {}, state, [], [{ type: 'requestBranches' }], () => { await testAction(actions.fetchBranches, {}, state, [], [{ type: 'requestBranches' }]);
expect(createFlash).toHaveBeenCalledWith({ message: PROJECT_BRANCHES_ERROR }); expect(createFlash).toHaveBeenCalledWith({ message: PROJECT_BRANCHES_ERROR });
done();
});
}); });
}); });
......
...@@ -17,16 +17,15 @@ describe('Accessibility Reports actions', () => { ...@@ -17,16 +17,15 @@ describe('Accessibility Reports actions', () => {
}); });
describe('setEndpoints', () => { describe('setEndpoints', () => {
it('should commit SET_ENDPOINTS mutation', (done) => { it('should commit SET_ENDPOINTS mutation', () => {
const endpoint = 'endpoint.json'; const endpoint = 'endpoint.json';
testAction( return testAction(
actions.setEndpoint, actions.setEndpoint,
endpoint, endpoint,
localState, localState,
[{ type: types.SET_ENDPOINT, payload: endpoint }], [{ type: types.SET_ENDPOINT, payload: endpoint }],
[], [],
done,
); );
}); });
}); });
...@@ -46,11 +45,11 @@ describe('Accessibility Reports actions', () => { ...@@ -46,11 +45,11 @@ describe('Accessibility Reports actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('should commit REQUEST_REPORT mutation and dispatch receiveReportSuccess', (done) => { it('should commit REQUEST_REPORT mutation and dispatch receiveReportSuccess', () => {
const data = { report: { summary: {} } }; const data = { report: { summary: {} } };
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(200, data); mock.onGet(`${TEST_HOST}/endpoint.json`).reply(200, data);
testAction( return testAction(
actions.fetchReport, actions.fetchReport,
null, null,
localState, localState,
...@@ -61,60 +60,55 @@ describe('Accessibility Reports actions', () => { ...@@ -61,60 +60,55 @@ describe('Accessibility Reports actions', () => {
type: 'receiveReportSuccess', type: 'receiveReportSuccess',
}, },
], ],
done,
); );
}); });
}); });
describe('error', () => { describe('error', () => {
it('should commit REQUEST_REPORT and RECEIVE_REPORT_ERROR mutations', (done) => { it('should commit REQUEST_REPORT and RECEIVE_REPORT_ERROR mutations', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500);
testAction( return testAction(
actions.fetchReport, actions.fetchReport,
null, null,
localState, localState,
[{ type: types.REQUEST_REPORT }], [{ type: types.REQUEST_REPORT }],
[{ type: 'receiveReportError' }], [{ type: 'receiveReportError' }],
done,
); );
}); });
}); });
}); });
describe('receiveReportSuccess', () => { describe('receiveReportSuccess', () => {
it('should commit RECEIVE_REPORT_SUCCESS mutation with 200', (done) => { it('should commit RECEIVE_REPORT_SUCCESS mutation with 200', () => {
testAction( return testAction(
actions.receiveReportSuccess, actions.receiveReportSuccess,
{ status: 200, data: mockReport }, { status: 200, data: mockReport },
localState, localState,
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: mockReport }], [{ type: types.RECEIVE_REPORT_SUCCESS, payload: mockReport }],
[{ type: 'stopPolling' }], [{ type: 'stopPolling' }],
done,
); );
}); });
it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', (done) => { it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', () => {
testAction( return testAction(
actions.receiveReportSuccess, actions.receiveReportSuccess,
{ status: 204, data: mockReport }, { status: 204, data: mockReport },
localState, localState,
[], [],
[], [],
done,
); );
}); });
}); });
describe('receiveReportError', () => { describe('receiveReportError', () => {
it('should commit RECEIVE_REPORT_ERROR mutation', (done) => { it('should commit RECEIVE_REPORT_ERROR mutation', () => {
testAction( return testAction(
actions.receiveReportError, actions.receiveReportError,
null, null,
localState, localState,
[{ type: types.RECEIVE_REPORT_ERROR }], [{ type: types.RECEIVE_REPORT_ERROR }],
[{ type: 'stopPolling' }], [{ type: 'stopPolling' }],
done,
); );
}); });
}); });
......
...@@ -23,7 +23,7 @@ describe('Codequality Reports actions', () => { ...@@ -23,7 +23,7 @@ describe('Codequality Reports actions', () => {
}); });
describe('setPaths', () => { describe('setPaths', () => {
it('should commit SET_PATHS mutation', (done) => { it('should commit SET_PATHS mutation', () => {
const paths = { const paths = {
baseBlobPath: 'baseBlobPath', baseBlobPath: 'baseBlobPath',
headBlobPath: 'headBlobPath', headBlobPath: 'headBlobPath',
...@@ -31,13 +31,12 @@ describe('Codequality Reports actions', () => { ...@@ -31,13 +31,12 @@ describe('Codequality Reports actions', () => {
helpPath: 'codequalityHelpPath', helpPath: 'codequalityHelpPath',
}; };
testAction( return testAction(
actions.setPaths, actions.setPaths,
paths, paths,
localState, localState,
[{ type: types.SET_PATHS, payload: paths }], [{ type: types.SET_PATHS, payload: paths }],
[], [],
done,
); );
}); });
}); });
...@@ -56,10 +55,10 @@ describe('Codequality Reports actions', () => { ...@@ -56,10 +55,10 @@ describe('Codequality Reports actions', () => {
}); });
describe('on success', () => { describe('on success', () => {
it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', () => {
mock.onGet(endpoint).reply(200, reportIssues); mock.onGet(endpoint).reply(200, reportIssues);
testAction( return testAction(
actions.fetchReports, actions.fetchReports,
null, null,
localState, localState,
...@@ -70,51 +69,48 @@ describe('Codequality Reports actions', () => { ...@@ -70,51 +69,48 @@ describe('Codequality Reports actions', () => {
type: 'receiveReportsSuccess', type: 'receiveReportsSuccess',
}, },
], ],
done,
); );
}); });
}); });
describe('on error', () => { describe('on error', () => {
it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { it('commits REQUEST_REPORTS and dispatches receiveReportsError', () => {
mock.onGet(endpoint).reply(500); mock.onGet(endpoint).reply(500);
testAction( return testAction(
actions.fetchReports, actions.fetchReports,
null, null,
localState, localState,
[{ type: types.REQUEST_REPORTS }], [{ type: types.REQUEST_REPORTS }],
[{ type: 'receiveReportsError', payload: expect.any(Error) }], [{ type: 'receiveReportsError', payload: expect.any(Error) }],
done,
); );
}); });
}); });
describe('when base report is not found', () => { describe('when base report is not found', () => {
it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { it('commits REQUEST_REPORTS and dispatches receiveReportsError', () => {
const data = { status: STATUS_NOT_FOUND }; const data = { status: STATUS_NOT_FOUND };
mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, data); mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, data);
testAction( return testAction(
actions.fetchReports, actions.fetchReports,
null, null,
localState, localState,
[{ type: types.REQUEST_REPORTS }], [{ type: types.REQUEST_REPORTS }],
[{ type: 'receiveReportsError', payload: data }], [{ type: 'receiveReportsError', payload: data }],
done,
); );
}); });
}); });
describe('while waiting for report results', () => { describe('while waiting for report results', () => {
it('continues polling until it receives data', (done) => { it('continues polling until it receives data', () => {
mock mock
.onGet(endpoint) .onGet(endpoint)
.replyOnce(204, undefined, pollIntervalHeader) .replyOnce(204, undefined, pollIntervalHeader)
.onGet(endpoint) .onGet(endpoint)
.reply(200, reportIssues); .reply(200, reportIssues);
Promise.all([ return Promise.all([
testAction( testAction(
actions.fetchReports, actions.fetchReports,
null, null,
...@@ -126,7 +122,6 @@ describe('Codequality Reports actions', () => { ...@@ -126,7 +122,6 @@ describe('Codequality Reports actions', () => {
type: 'receiveReportsSuccess', type: 'receiveReportsSuccess',
}, },
], ],
done,
), ),
axios axios
// wait for initial NO_CONTENT response to be fulfilled // wait for initial NO_CONTENT response to be fulfilled
...@@ -134,24 +129,23 @@ describe('Codequality Reports actions', () => { ...@@ -134,24 +129,23 @@ describe('Codequality Reports actions', () => {
.then(() => { .then(() => {
jest.advanceTimersByTime(pollInterval); jest.advanceTimersByTime(pollInterval);
}), }),
]).catch(done.fail); ]);
}); });
it('continues polling until it receives an error', (done) => { it('continues polling until it receives an error', () => {
mock mock
.onGet(endpoint) .onGet(endpoint)
.replyOnce(204, undefined, pollIntervalHeader) .replyOnce(204, undefined, pollIntervalHeader)
.onGet(endpoint) .onGet(endpoint)
.reply(500); .reply(500);
Promise.all([ return Promise.all([
testAction( testAction(
actions.fetchReports, actions.fetchReports,
null, null,
localState, localState,
[{ type: types.REQUEST_REPORTS }], [{ type: types.REQUEST_REPORTS }],
[{ type: 'receiveReportsError', payload: expect.any(Error) }], [{ type: 'receiveReportsError', payload: expect.any(Error) }],
done,
), ),
axios axios
// wait for initial NO_CONTENT response to be fulfilled // wait for initial NO_CONTENT response to be fulfilled
...@@ -159,35 +153,33 @@ describe('Codequality Reports actions', () => { ...@@ -159,35 +153,33 @@ describe('Codequality Reports actions', () => {
.then(() => { .then(() => {
jest.advanceTimersByTime(pollInterval); jest.advanceTimersByTime(pollInterval);
}), }),
]).catch(done.fail); ]);
}); });
}); });
}); });
describe('receiveReportsSuccess', () => { describe('receiveReportsSuccess', () => {
it('commits RECEIVE_REPORTS_SUCCESS', (done) => { it('commits RECEIVE_REPORTS_SUCCESS', () => {
const data = { issues: [] }; const data = { issues: [] };
testAction( return testAction(
actions.receiveReportsSuccess, actions.receiveReportsSuccess,
data, data,
localState, localState,
[{ type: types.RECEIVE_REPORTS_SUCCESS, payload: data }], [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: data }],
[], [],
done,
); );
}); });
}); });
describe('receiveReportsError', () => { describe('receiveReportsError', () => {
it('commits RECEIVE_REPORTS_ERROR', (done) => { it('commits RECEIVE_REPORTS_ERROR', () => {
testAction( return testAction(
actions.receiveReportsError, actions.receiveReportsError,
null, null,
localState, localState,
[{ type: types.RECEIVE_REPORTS_ERROR, payload: null }], [{ type: types.RECEIVE_REPORTS_ERROR, payload: null }],
[], [],
done,
); );
}); });
}); });
......
...@@ -24,8 +24,8 @@ describe('Reports Store Actions', () => { ...@@ -24,8 +24,8 @@ describe('Reports Store Actions', () => {
}); });
describe('setPaths', () => { describe('setPaths', () => {
it('should commit SET_PATHS mutation', (done) => { it('should commit SET_PATHS mutation', () => {
testAction( return testAction(
setPaths, setPaths,
{ endpoint: 'endpoint.json', headBlobPath: '/blob/path' }, { endpoint: 'endpoint.json', headBlobPath: '/blob/path' },
mockedState, mockedState,
...@@ -36,14 +36,13 @@ describe('Reports Store Actions', () => { ...@@ -36,14 +36,13 @@ describe('Reports Store Actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('requestReports', () => { describe('requestReports', () => {
it('should commit REQUEST_REPORTS mutation', (done) => { it('should commit REQUEST_REPORTS mutation', () => {
testAction(requestReports, null, mockedState, [{ type: types.REQUEST_REPORTS }], [], done); return testAction(requestReports, null, mockedState, [{ type: types.REQUEST_REPORTS }], []);
}); });
}); });
...@@ -62,12 +61,12 @@ describe('Reports Store Actions', () => { ...@@ -62,12 +61,12 @@ describe('Reports Store Actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestReports and receiveReportsSuccess ', (done) => { it('dispatches requestReports and receiveReportsSuccess ', () => {
mock mock
.onGet(`${TEST_HOST}/endpoint.json`) .onGet(`${TEST_HOST}/endpoint.json`)
.replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] }); .replyOnce(200, { summary: {}, suites: [{ name: 'rspec' }] });
testAction( return testAction(
fetchReports, fetchReports,
null, null,
mockedState, mockedState,
...@@ -81,7 +80,6 @@ describe('Reports Store Actions', () => { ...@@ -81,7 +80,6 @@ describe('Reports Store Actions', () => {
type: 'receiveReportsSuccess', type: 'receiveReportsSuccess',
}, },
], ],
done,
); );
}); });
}); });
...@@ -91,8 +89,8 @@ describe('Reports Store Actions', () => { ...@@ -91,8 +89,8 @@ describe('Reports Store Actions', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500);
}); });
it('dispatches requestReports and receiveReportsError ', (done) => { it('dispatches requestReports and receiveReportsError ', () => {
testAction( return testAction(
fetchReports, fetchReports,
null, null,
mockedState, mockedState,
...@@ -105,71 +103,65 @@ describe('Reports Store Actions', () => { ...@@ -105,71 +103,65 @@ describe('Reports Store Actions', () => {
type: 'receiveReportsError', type: 'receiveReportsError',
}, },
], ],
done,
); );
}); });
}); });
}); });
describe('receiveReportsSuccess', () => { describe('receiveReportsSuccess', () => {
it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', (done) => { it('should commit RECEIVE_REPORTS_SUCCESS mutation with 200', () => {
testAction( return testAction(
receiveReportsSuccess, receiveReportsSuccess,
{ data: { summary: {} }, status: 200 }, { data: { summary: {} }, status: 200 },
mockedState, mockedState,
[{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }], [{ type: types.RECEIVE_REPORTS_SUCCESS, payload: { summary: {} } }],
[], [],
done,
); );
}); });
it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', (done) => { it('should not commit RECEIVE_REPORTS_SUCCESS mutation with 204', () => {
testAction( return testAction(
receiveReportsSuccess, receiveReportsSuccess,
{ data: { summary: {} }, status: 204 }, { data: { summary: {} }, status: 204 },
mockedState, mockedState,
[], [],
[], [],
done,
); );
}); });
}); });
describe('receiveReportsError', () => { describe('receiveReportsError', () => {
it('should commit RECEIVE_REPORTS_ERROR mutation', (done) => { it('should commit RECEIVE_REPORTS_ERROR mutation', () => {
testAction( return testAction(
receiveReportsError, receiveReportsError,
null, null,
mockedState, mockedState,
[{ type: types.RECEIVE_REPORTS_ERROR }], [{ type: types.RECEIVE_REPORTS_ERROR }],
[], [],
done,
); );
}); });
}); });
describe('openModal', () => { describe('openModal', () => {
it('should commit SET_ISSUE_MODAL_DATA', (done) => { it('should commit SET_ISSUE_MODAL_DATA', () => {
testAction( return testAction(
openModal, openModal,
{ name: 'foo' }, { name: 'foo' },
mockedState, mockedState,
[{ type: types.SET_ISSUE_MODAL_DATA, payload: { name: 'foo' } }], [{ type: types.SET_ISSUE_MODAL_DATA, payload: { name: 'foo' } }],
[], [],
done,
); );
}); });
}); });
describe('closeModal', () => { describe('closeModal', () => {
it('should commit RESET_ISSUE_MODAL_DATA', (done) => { it('should commit RESET_ISSUE_MODAL_DATA', () => {
testAction( return testAction(
closeModal, closeModal,
{}, {},
mockedState, mockedState,
[{ type: types.RESET_ISSUE_MODAL_DATA, payload: {} }], [{ type: types.RESET_ISSUE_MODAL_DATA, payload: {} }],
[], [],
done,
); );
}); });
}); });
......
...@@ -223,34 +223,22 @@ describe('Search autocomplete dropdown', () => { ...@@ -223,34 +223,22 @@ describe('Search autocomplete dropdown', () => {
}); });
} }
it('suggest Projects', (done) => { it('suggest Projects', async () => {
// eslint-disable-next-line promise/catch-or-return await triggerAutocomplete();
triggerAutocomplete().finally(() => {
const list = widget.wrap.find('.dropdown-menu').find('ul'); const list = widget.wrap.find('.dropdown-menu').find('ul');
const link = "a[href$='/gitlab-org/gitlab-test']"; const link = "a[href$='/gitlab-org/gitlab-test']";
expect(list.find(link).length).toBe(1); expect(list.find(link).length).toBe(1);
done();
}); });
// Make sure jest properly acknowledge the `done` invocation it('suggest Groups', async () => {
jest.runOnlyPendingTimers(); await triggerAutocomplete();
});
it('suggest Groups', (done) => {
// eslint-disable-next-line promise/catch-or-return
triggerAutocomplete().finally(() => {
const list = widget.wrap.find('.dropdown-menu').find('ul'); const list = widget.wrap.find('.dropdown-menu').find('ul');
const link = "a[href$='/gitlab-org']"; const link = "a[href$='/gitlab-org']";
expect(list.find(link).length).toBe(1); expect(list.find(link).length).toBe(1);
done();
});
// Make sure jest properly acknowledge the `done` invocation
jest.runOnlyPendingTimers();
}); });
}); });
......
...@@ -16,27 +16,25 @@ describe('self monitor actions', () => { ...@@ -16,27 +16,25 @@ describe('self monitor actions', () => {
}); });
describe('setSelfMonitor', () => { describe('setSelfMonitor', () => {
it('commits the SET_ENABLED mutation', (done) => { it('commits the SET_ENABLED mutation', () => {
testAction( return testAction(
actions.setSelfMonitor, actions.setSelfMonitor,
null, null,
state, state,
[{ type: types.SET_ENABLED, payload: null }], [{ type: types.SET_ENABLED, payload: null }],
[], [],
done,
); );
}); });
}); });
describe('resetAlert', () => { describe('resetAlert', () => {
it('commits the SET_ENABLED mutation', (done) => { it('commits the SET_ENABLED mutation', () => {
testAction( return testAction(
actions.resetAlert, actions.resetAlert,
null, null,
state, state,
[{ type: types.SET_SHOW_ALERT, payload: false }], [{ type: types.SET_SHOW_ALERT, payload: false }],
[], [],
done,
); );
}); });
}); });
...@@ -54,8 +52,8 @@ describe('self monitor actions', () => { ...@@ -54,8 +52,8 @@ describe('self monitor actions', () => {
}); });
}); });
it('dispatches status request with job data', (done) => { it('dispatches status request with job data', () => {
testAction( return testAction(
actions.requestCreateProject, actions.requestCreateProject,
null, null,
state, state,
...@@ -71,12 +69,11 @@ describe('self monitor actions', () => { ...@@ -71,12 +69,11 @@ describe('self monitor actions', () => {
payload: '123', payload: '123',
}, },
], ],
done,
); );
}); });
it('dispatches success with project path', (done) => { it('dispatches success with project path', () => {
testAction( return testAction(
actions.requestCreateProjectStatus, actions.requestCreateProjectStatus,
null, null,
state, state,
...@@ -87,7 +84,6 @@ describe('self monitor actions', () => { ...@@ -87,7 +84,6 @@ describe('self monitor actions', () => {
payload: { project_full_path: '/self-monitor-url' }, payload: { project_full_path: '/self-monitor-url' },
}, },
], ],
done,
); );
}); });
}); });
...@@ -98,8 +94,8 @@ describe('self monitor actions', () => { ...@@ -98,8 +94,8 @@ describe('self monitor actions', () => {
mock.onPost(state.createProjectEndpoint).reply(500); mock.onPost(state.createProjectEndpoint).reply(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
actions.requestCreateProject, actions.requestCreateProject,
null, null,
state, state,
...@@ -115,14 +111,13 @@ describe('self monitor actions', () => { ...@@ -115,14 +111,13 @@ describe('self monitor actions', () => {
payload: new Error('Request failed with status code 500'), payload: new Error('Request failed with status code 500'),
}, },
], ],
done,
); );
}); });
}); });
describe('requestCreateProjectSuccess', () => { describe('requestCreateProjectSuccess', () => {
it('should commit the received data', (done) => { it('should commit the received data', () => {
testAction( return testAction(
actions.requestCreateProjectSuccess, actions.requestCreateProjectSuccess,
{ project_full_path: '/self-monitor-url' }, { project_full_path: '/self-monitor-url' },
state, state,
...@@ -146,7 +141,6 @@ describe('self monitor actions', () => { ...@@ -146,7 +141,6 @@ describe('self monitor actions', () => {
type: 'setSelfMonitor', type: 'setSelfMonitor',
}, },
], ],
done,
); );
}); });
}); });
...@@ -165,8 +159,8 @@ describe('self monitor actions', () => { ...@@ -165,8 +159,8 @@ describe('self monitor actions', () => {
}); });
}); });
it('dispatches status request with job data', (done) => { it('dispatches status request with job data', () => {
testAction( return testAction(
actions.requestDeleteProject, actions.requestDeleteProject,
null, null,
state, state,
...@@ -182,12 +176,11 @@ describe('self monitor actions', () => { ...@@ -182,12 +176,11 @@ describe('self monitor actions', () => {
payload: '456', payload: '456',
}, },
], ],
done,
); );
}); });
it('dispatches success with status', (done) => { it('dispatches success with status', () => {
testAction( return testAction(
actions.requestDeleteProjectStatus, actions.requestDeleteProjectStatus,
null, null,
state, state,
...@@ -198,7 +191,6 @@ describe('self monitor actions', () => { ...@@ -198,7 +191,6 @@ describe('self monitor actions', () => {
payload: { status: 'success' }, payload: { status: 'success' },
}, },
], ],
done,
); );
}); });
}); });
...@@ -209,8 +201,8 @@ describe('self monitor actions', () => { ...@@ -209,8 +201,8 @@ describe('self monitor actions', () => {
mock.onDelete(state.deleteProjectEndpoint).reply(500); mock.onDelete(state.deleteProjectEndpoint).reply(500);
}); });
it('dispatches error', (done) => { it('dispatches error', () => {
testAction( return testAction(
actions.requestDeleteProject, actions.requestDeleteProject,
null, null,
state, state,
...@@ -226,14 +218,13 @@ describe('self monitor actions', () => { ...@@ -226,14 +218,13 @@ describe('self monitor actions', () => {
payload: new Error('Request failed with status code 500'), payload: new Error('Request failed with status code 500'),
}, },
], ],
done,
); );
}); });
}); });
describe('requestDeleteProjectSuccess', () => { describe('requestDeleteProjectSuccess', () => {
it('should commit mutations to remove previously set data', (done) => { it('should commit mutations to remove previously set data', () => {
testAction( return testAction(
actions.requestDeleteProjectSuccess, actions.requestDeleteProjectSuccess,
null, null,
state, state,
...@@ -252,7 +243,6 @@ describe('self monitor actions', () => { ...@@ -252,7 +243,6 @@ describe('self monitor actions', () => {
{ type: types.SET_LOADING, payload: false }, { type: types.SET_LOADING, payload: false },
], ],
[], [],
done,
); );
}); });
}); });
......
...@@ -7,13 +7,22 @@ import { mockServerlessFunctions, mockMetrics } from '../mock_data'; ...@@ -7,13 +7,22 @@ import { mockServerlessFunctions, mockMetrics } from '../mock_data';
import { adjustMetricQuery } from '../utils'; import { adjustMetricQuery } from '../utils';
describe('ServerlessActions', () => { describe('ServerlessActions', () => {
let mock;
beforeEach(() => {
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('fetchFunctions', () => { describe('fetchFunctions', () => {
it('should successfully fetch functions', (done) => { it('should successfully fetch functions', () => {
const endpoint = '/functions'; const endpoint = '/functions';
const mock = new MockAdapter(axios);
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockServerlessFunctions)); mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockServerlessFunctions));
testAction( return testAction(
fetchFunctions, fetchFunctions,
{ functionsPath: endpoint }, { functionsPath: endpoint },
{}, {},
...@@ -22,68 +31,49 @@ describe('ServerlessActions', () => { ...@@ -22,68 +31,49 @@ describe('ServerlessActions', () => {
{ type: 'requestFunctionsLoading' }, { type: 'requestFunctionsLoading' },
{ type: 'receiveFunctionsSuccess', payload: mockServerlessFunctions }, { type: 'receiveFunctionsSuccess', payload: mockServerlessFunctions },
], ],
() => {
mock.restore();
done();
},
); );
}); });
it('should successfully retry', (done) => { it('should successfully retry', () => {
const endpoint = '/functions'; const endpoint = '/functions';
const mock = new MockAdapter(axios);
mock mock
.onGet(endpoint) .onGet(endpoint)
.reply(() => new Promise((resolve) => setTimeout(() => resolve(200), Infinity))); .reply(() => new Promise((resolve) => setTimeout(() => resolve(200), Infinity)));
testAction( return testAction(
fetchFunctions, fetchFunctions,
{ functionsPath: endpoint }, { functionsPath: endpoint },
{}, {},
[], [],
[{ type: 'requestFunctionsLoading' }], [{ type: 'requestFunctionsLoading' }],
() => {
mock.restore();
done();
},
); );
}); });
}); });
describe('fetchMetrics', () => { describe('fetchMetrics', () => {
it('should return no prometheus', (done) => { it('should return no prometheus', () => {
const endpoint = '/metrics'; const endpoint = '/metrics';
const mock = new MockAdapter(axios);
mock.onGet(endpoint).reply(statusCodes.NO_CONTENT); mock.onGet(endpoint).reply(statusCodes.NO_CONTENT);
testAction( return testAction(
fetchMetrics, fetchMetrics,
{ metricsPath: endpoint, hasPrometheus: false }, { metricsPath: endpoint, hasPrometheus: false },
{}, {},
[], [],
[{ type: 'receiveMetricsNoPrometheus' }], [{ type: 'receiveMetricsNoPrometheus' }],
() => {
mock.restore();
done();
},
); );
}); });
it('should successfully fetch metrics', (done) => { it('should successfully fetch metrics', () => {
const endpoint = '/metrics'; const endpoint = '/metrics';
const mock = new MockAdapter(axios);
mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockMetrics)); mock.onGet(endpoint).reply(statusCodes.OK, JSON.stringify(mockMetrics));
testAction( return testAction(
fetchMetrics, fetchMetrics,
{ metricsPath: endpoint, hasPrometheus: true }, { metricsPath: endpoint, hasPrometheus: true },
{}, {},
[], [],
[{ type: 'receiveMetricsSuccess', payload: adjustMetricQuery(mockMetrics) }], [{ type: 'receiveMetricsSuccess', payload: adjustMetricQuery(mockMetrics) }],
() => {
mock.restore();
done();
},
); );
}); });
}); });
......
...@@ -121,7 +121,7 @@ describe('TaskList', () => { ...@@ -121,7 +121,7 @@ describe('TaskList', () => {
}); });
describe('update', () => { describe('update', () => {
it('should disable task list items and make a patch request then enable them again', (done) => { it('should disable task list items and make a patch request then enable them again', () => {
const response = { data: { lock_version: 3 } }; const response = { data: { lock_version: 3 } };
jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {}); jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'disableTaskListItems').mockImplementation(() => {}); jest.spyOn(taskList, 'disableTaskListItems').mockImplementation(() => {});
...@@ -156,20 +156,17 @@ describe('TaskList', () => { ...@@ -156,20 +156,17 @@ describe('TaskList', () => {
expect(taskList.onUpdate).toHaveBeenCalled(); expect(taskList.onUpdate).toHaveBeenCalled();
update return update.then(() => {
.then(() => {
expect(taskList.disableTaskListItems).toHaveBeenCalledWith(event); expect(taskList.disableTaskListItems).toHaveBeenCalledWith(event);
expect(axios.patch).toHaveBeenCalledWith(endpoint, patchData); expect(axios.patch).toHaveBeenCalledWith(endpoint, patchData);
expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event); expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event);
expect(taskList.onSuccess).toHaveBeenCalledWith(response.data); expect(taskList.onSuccess).toHaveBeenCalledWith(response.data);
expect(taskList.lockVersion).toEqual(response.data.lock_version); expect(taskList.lockVersion).toEqual(response.data.lock_version);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
it('should handle request error and enable task list items', (done) => { it('should handle request error and enable task list items', () => {
const response = { data: { error: 1 } }; const response = { data: { error: 1 } };
jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {}); jest.spyOn(taskList, 'enableTaskListItems').mockImplementation(() => {});
jest.spyOn(taskList, 'onUpdate').mockImplementation(() => {}); jest.spyOn(taskList, 'onUpdate').mockImplementation(() => {});
...@@ -182,12 +179,9 @@ describe('TaskList', () => { ...@@ -182,12 +179,9 @@ describe('TaskList', () => {
expect(taskList.onUpdate).toHaveBeenCalled(); expect(taskList.onUpdate).toHaveBeenCalled();
update return update.then(() => {
.then(() => {
expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event); expect(taskList.enableTaskListItems).toHaveBeenCalledWith(event);
expect(taskList.onError).toHaveBeenCalledWith(response.data); expect(taskList.onError).toHaveBeenCalledWith(response.data);
}) });
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -24,14 +24,13 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -24,14 +24,13 @@ describe('~/user_lists/store/index/actions', () => {
}); });
describe('setUserListsOptions', () => { describe('setUserListsOptions', () => {
it('should commit SET_USER_LISTS_OPTIONS mutation', (done) => { it('should commit SET_USER_LISTS_OPTIONS mutation', () => {
testAction( return testAction(
setUserListsOptions, setUserListsOptions,
{ page: '1', scope: 'all' }, { page: '1', scope: 'all' },
state, state,
[{ type: types.SET_USER_LISTS_OPTIONS, payload: { page: '1', scope: 'all' } }], [{ type: types.SET_USER_LISTS_OPTIONS, payload: { page: '1', scope: 'all' } }],
[], [],
done,
); );
}); });
}); });
...@@ -42,8 +41,8 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -42,8 +41,8 @@ describe('~/user_lists/store/index/actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestUserLists and receiveUserListsSuccess ', (done) => { it('dispatches requestUserLists and receiveUserListsSuccess ', () => {
testAction( return testAction(
fetchUserLists, fetchUserLists,
null, null,
state, state,
...@@ -57,16 +56,15 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -57,16 +56,15 @@ describe('~/user_lists/store/index/actions', () => {
type: 'receiveUserListsSuccess', type: 'receiveUserListsSuccess',
}, },
], ],
done,
); );
}); });
}); });
describe('error', () => { describe('error', () => {
it('dispatches requestUserLists and receiveUserListsError ', (done) => { it('dispatches requestUserLists and receiveUserListsError ', () => {
Api.fetchFeatureFlagUserLists.mockRejectedValue(); Api.fetchFeatureFlagUserLists.mockRejectedValue();
testAction( return testAction(
fetchUserLists, fetchUserLists,
null, null,
state, state,
...@@ -79,21 +77,20 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -79,21 +77,20 @@ describe('~/user_lists/store/index/actions', () => {
type: 'receiveUserListsError', type: 'receiveUserListsError',
}, },
], ],
done,
); );
}); });
}); });
}); });
describe('requestUserLists', () => { describe('requestUserLists', () => {
it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', (done) => { it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', () => {
testAction(requestUserLists, null, state, [{ type: types.REQUEST_USER_LISTS }], [], done); return testAction(requestUserLists, null, state, [{ type: types.REQUEST_USER_LISTS }], []);
}); });
}); });
describe('receiveUserListsSuccess', () => { describe('receiveUserListsSuccess', () => {
it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', (done) => { it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', () => {
testAction( return testAction(
receiveUserListsSuccess, receiveUserListsSuccess,
{ data: [userList], headers: {} }, { data: [userList], headers: {} },
state, state,
...@@ -104,20 +101,18 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -104,20 +101,18 @@ describe('~/user_lists/store/index/actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('receiveUserListsError', () => { describe('receiveUserListsError', () => {
it('should commit RECEIVE_USER_LISTS_ERROR mutation', (done) => { it('should commit RECEIVE_USER_LISTS_ERROR mutation', () => {
testAction( return testAction(
receiveUserListsError, receiveUserListsError,
null, null,
state, state,
[{ type: types.RECEIVE_USER_LISTS_ERROR }], [{ type: types.RECEIVE_USER_LISTS_ERROR }],
[], [],
done,
); );
}); });
}); });
...@@ -132,14 +127,13 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -132,14 +127,13 @@ describe('~/user_lists/store/index/actions', () => {
Api.deleteFeatureFlagUserList.mockResolvedValue(); Api.deleteFeatureFlagUserList.mockResolvedValue();
}); });
it('should refresh the user lists', (done) => { it('should refresh the user lists', () => {
testAction( return testAction(
deleteUserList, deleteUserList,
userList, userList,
state, state,
[], [],
[{ type: 'requestDeleteUserList', payload: userList }, { type: 'fetchUserLists' }], [{ type: 'requestDeleteUserList', payload: userList }, { type: 'fetchUserLists' }],
done,
); );
}); });
}); });
...@@ -149,8 +143,8 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -149,8 +143,8 @@ describe('~/user_lists/store/index/actions', () => {
Api.deleteFeatureFlagUserList.mockRejectedValue({ response: { data: 'some error' } }); Api.deleteFeatureFlagUserList.mockRejectedValue({ response: { data: 'some error' } });
}); });
it('should dispatch receiveDeleteUserListError', (done) => { it('should dispatch receiveDeleteUserListError', () => {
testAction( return testAction(
deleteUserList, deleteUserList,
userList, userList,
state, state,
...@@ -162,15 +156,14 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -162,15 +156,14 @@ describe('~/user_lists/store/index/actions', () => {
payload: { list: userList, error: 'some error' }, payload: { list: userList, error: 'some error' },
}, },
], ],
done,
); );
}); });
}); });
}); });
describe('receiveDeleteUserListError', () => { describe('receiveDeleteUserListError', () => {
it('should commit RECEIVE_DELETE_USER_LIST_ERROR with the given list', (done) => { it('should commit RECEIVE_DELETE_USER_LIST_ERROR with the given list', () => {
testAction( return testAction(
receiveDeleteUserListError, receiveDeleteUserListError,
{ list: userList, error: 'mock error' }, { list: userList, error: 'mock error' },
state, state,
...@@ -181,22 +174,20 @@ describe('~/user_lists/store/index/actions', () => { ...@@ -181,22 +174,20 @@ describe('~/user_lists/store/index/actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('clearAlert', () => { describe('clearAlert', () => {
it('should commit RECEIVE_CLEAR_ALERT', (done) => { it('should commit RECEIVE_CLEAR_ALERT', () => {
const alertIndex = 3; const alertIndex = 3;
testAction( return testAction(
clearAlert, clearAlert,
alertIndex, alertIndex,
state, state,
[{ type: 'RECEIVE_CLEAR_ALERT', payload: alertIndex }], [{ type: 'RECEIVE_CLEAR_ALERT', payload: alertIndex }],
[], [],
done,
); );
}); });
}); });
......
import { nextTick } from 'vue';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -28,11 +29,6 @@ const testApprovals = () => ({ ...@@ -28,11 +29,6 @@ const testApprovals = () => ({
}); });
const testApprovalRulesResponse = () => ({ rules: [{ id: 2 }] }); const testApprovalRulesResponse = () => ({ rules: [{ id: 2 }] });
// For some reason, the `Promise.resolve()` needs to be deferred
// or the timing doesn't work.
const tick = () => Promise.resolve();
const waitForTick = (done) => tick().then(done).catch(done.fail);
describe('MRWidget approvals', () => { describe('MRWidget approvals', () => {
let wrapper; let wrapper;
let service; let service;
...@@ -105,7 +101,7 @@ describe('MRWidget approvals', () => { ...@@ -105,7 +101,7 @@ describe('MRWidget approvals', () => {
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
wrapper.setData({ fetchingApprovals: true }); wrapper.setData({ fetchingApprovals: true });
return tick().then(() => { return nextTick().then(() => {
expect(wrapper.text()).toContain(FETCH_LOADING); expect(wrapper.text()).toContain(FETCH_LOADING);
}); });
}); });
...@@ -116,10 +112,10 @@ describe('MRWidget approvals', () => { ...@@ -116,10 +112,10 @@ describe('MRWidget approvals', () => {
}); });
describe('when fetch approvals error', () => { describe('when fetch approvals error', () => {
beforeEach((done) => { beforeEach(() => {
jest.spyOn(service, 'fetchApprovals').mockReturnValue(Promise.reject()); jest.spyOn(service, 'fetchApprovals').mockReturnValue(Promise.reject());
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('still shows loading message', () => { it('still shows loading message', () => {
...@@ -133,13 +129,13 @@ describe('MRWidget approvals', () => { ...@@ -133,13 +129,13 @@ describe('MRWidget approvals', () => {
describe('action button', () => { describe('action button', () => {
describe('when mr is closed', () => { describe('when mr is closed', () => {
beforeEach((done) => { beforeEach(() => {
mr.isOpen = false; mr.isOpen = false;
mr.approvals.user_has_approved = false; mr.approvals.user_has_approved = false;
mr.approvals.user_can_approve = true; mr.approvals.user_can_approve = true;
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('action is not rendered', () => { it('action is not rendered', () => {
...@@ -148,12 +144,12 @@ describe('MRWidget approvals', () => { ...@@ -148,12 +144,12 @@ describe('MRWidget approvals', () => {
}); });
describe('when user cannot approve', () => { describe('when user cannot approve', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.user_has_approved = false; mr.approvals.user_has_approved = false;
mr.approvals.user_can_approve = false; mr.approvals.user_can_approve = false;
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('action is not rendered', () => { it('action is not rendered', () => {
...@@ -168,9 +164,9 @@ describe('MRWidget approvals', () => { ...@@ -168,9 +164,9 @@ describe('MRWidget approvals', () => {
}); });
describe('and MR is unapproved', () => { describe('and MR is unapproved', () => {
beforeEach((done) => { beforeEach(() => {
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('approve action is rendered', () => { it('approve action is rendered', () => {
...@@ -188,10 +184,10 @@ describe('MRWidget approvals', () => { ...@@ -188,10 +184,10 @@ describe('MRWidget approvals', () => {
}); });
describe('with no approvers', () => { describe('with no approvers', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.approved_by = []; mr.approvals.approved_by = [];
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('approve action (with inverted style) is rendered', () => { it('approve action (with inverted style) is rendered', () => {
...@@ -204,10 +200,10 @@ describe('MRWidget approvals', () => { ...@@ -204,10 +200,10 @@ describe('MRWidget approvals', () => {
}); });
describe('with approvers', () => { describe('with approvers', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.approved_by = [{ user: { id: 7 } }]; mr.approvals.approved_by = [{ user: { id: 7 } }];
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('approve additionally action is rendered', () => { it('approve additionally action is rendered', () => {
...@@ -221,9 +217,9 @@ describe('MRWidget approvals', () => { ...@@ -221,9 +217,9 @@ describe('MRWidget approvals', () => {
}); });
describe('when approve action is clicked', () => { describe('when approve action is clicked', () => {
beforeEach((done) => { beforeEach(() => {
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('shows loading icon', () => { it('shows loading icon', () => {
...@@ -234,15 +230,15 @@ describe('MRWidget approvals', () => { ...@@ -234,15 +230,15 @@ describe('MRWidget approvals', () => {
action.vm.$emit('click'); action.vm.$emit('click');
return tick().then(() => { return nextTick().then(() => {
expect(action.props('loading')).toBe(true); expect(action.props('loading')).toBe(true);
}); });
}); });
describe('and after loading', () => { describe('and after loading', () => {
beforeEach((done) => { beforeEach(() => {
findAction().vm.$emit('click'); findAction().vm.$emit('click');
waitForTick(done); return nextTick();
}); });
it('calls service approve', () => { it('calls service approve', () => {
...@@ -259,10 +255,10 @@ describe('MRWidget approvals', () => { ...@@ -259,10 +255,10 @@ describe('MRWidget approvals', () => {
}); });
describe('and error', () => { describe('and error', () => {
beforeEach((done) => { beforeEach(() => {
jest.spyOn(service, 'approveMergeRequest').mockReturnValue(Promise.reject()); jest.spyOn(service, 'approveMergeRequest').mockReturnValue(Promise.reject());
findAction().vm.$emit('click'); findAction().vm.$emit('click');
waitForTick(done); return nextTick();
}); });
it('flashes error message', () => { it('flashes error message', () => {
...@@ -273,12 +269,12 @@ describe('MRWidget approvals', () => { ...@@ -273,12 +269,12 @@ describe('MRWidget approvals', () => {
}); });
describe('when user has approved', () => { describe('when user has approved', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.user_has_approved = true; mr.approvals.user_has_approved = true;
mr.approvals.user_can_approve = false; mr.approvals.user_can_approve = false;
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('revoke action is rendered', () => { it('revoke action is rendered', () => {
...@@ -291,9 +287,9 @@ describe('MRWidget approvals', () => { ...@@ -291,9 +287,9 @@ describe('MRWidget approvals', () => {
describe('when revoke action is clicked', () => { describe('when revoke action is clicked', () => {
describe('and successful', () => { describe('and successful', () => {
beforeEach((done) => { beforeEach(() => {
findAction().vm.$emit('click'); findAction().vm.$emit('click');
waitForTick(done); return nextTick();
}); });
it('calls service unapprove', () => { it('calls service unapprove', () => {
...@@ -310,10 +306,10 @@ describe('MRWidget approvals', () => { ...@@ -310,10 +306,10 @@ describe('MRWidget approvals', () => {
}); });
describe('and error', () => { describe('and error', () => {
beforeEach((done) => { beforeEach(() => {
jest.spyOn(service, 'unapproveMergeRequest').mockReturnValue(Promise.reject()); jest.spyOn(service, 'unapproveMergeRequest').mockReturnValue(Promise.reject());
findAction().vm.$emit('click'); findAction().vm.$emit('click');
waitForTick(done); return nextTick();
}); });
it('flashes error message', () => { it('flashes error message', () => {
...@@ -333,11 +329,11 @@ describe('MRWidget approvals', () => { ...@@ -333,11 +329,11 @@ describe('MRWidget approvals', () => {
}); });
describe('and can approve', () => { describe('and can approve', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.user_can_approve = true; mr.approvals.user_can_approve = true;
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('is shown', () => { it('is shown', () => {
...@@ -350,11 +346,11 @@ describe('MRWidget approvals', () => { ...@@ -350,11 +346,11 @@ describe('MRWidget approvals', () => {
}); });
describe('and cannot approve', () => { describe('and cannot approve', () => {
beforeEach((done) => { beforeEach(() => {
mr.approvals.user_can_approve = false; mr.approvals.user_can_approve = false;
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('is shown', () => { it('is shown', () => {
...@@ -369,9 +365,9 @@ describe('MRWidget approvals', () => { ...@@ -369,9 +365,9 @@ describe('MRWidget approvals', () => {
}); });
describe('approvals summary', () => { describe('approvals summary', () => {
beforeEach((done) => { beforeEach(() => {
createComponent(); createComponent();
waitForTick(done); return nextTick();
}); });
it('is rendered with props', () => { it('is rendered with props', () => {
......
...@@ -175,22 +175,19 @@ describe('MemoryUsage', () => { ...@@ -175,22 +175,19 @@ describe('MemoryUsage', () => {
expect(el.querySelector('.js-usage-info')).toBeDefined(); expect(el.querySelector('.js-usage-info')).toBeDefined();
}); });
it('should show loading metrics message while metrics are being loaded', (done) => { it('should show loading metrics message while metrics are being loaded', async () => {
vm.loadingMetrics = true; vm.loadingMetrics = true;
vm.hasMetrics = false; vm.hasMetrics = false;
vm.loadFailed = false; vm.loadFailed = false;
nextTick(() => { await nextTick();
expect(el.querySelector('.js-usage-info.usage-info-loading')).toBeDefined();
expect(el.querySelector('.js-usage-info.usage-info-loading')).toBeDefined();
expect(el.querySelector('.js-usage-info .usage-info-load-spinner')).toBeDefined(); expect(el.querySelector('.js-usage-info .usage-info-load-spinner')).toBeDefined();
expect(el.querySelector('.js-usage-info').innerText).toContain(messages.loadingMetrics); expect(el.querySelector('.js-usage-info').innerText).toContain(messages.loadingMetrics);
done();
});
}); });
it('should show deployment memory usage when metrics are loaded', (done) => { it('should show deployment memory usage when metrics are loaded', async () => {
// ignore BoostrapVue warnings // ignore BoostrapVue warnings
jest.spyOn(console, 'warn').mockImplementation(); jest.spyOn(console, 'warn').mockImplementation();
...@@ -199,37 +196,32 @@ describe('MemoryUsage', () => { ...@@ -199,37 +196,32 @@ describe('MemoryUsage', () => {
vm.loadFailed = false; vm.loadFailed = false;
vm.memoryMetrics = metricsMockData.metrics.memory_values[0].values; vm.memoryMetrics = metricsMockData.metrics.memory_values[0].values;
nextTick(() => { await nextTick();
expect(el.querySelector('.memory-graph-container')).toBeDefined(); expect(el.querySelector('.memory-graph-container')).toBeDefined();
expect(el.querySelector('.js-usage-info').innerText).toContain(messages.hasMetrics); expect(el.querySelector('.js-usage-info').innerText).toContain(messages.hasMetrics);
done();
});
}); });
it('should show failure message when metrics loading failed', (done) => { it('should show failure message when metrics loading failed', async () => {
vm.loadingMetrics = false; vm.loadingMetrics = false;
vm.hasMetrics = false; vm.hasMetrics = false;
vm.loadFailed = true; vm.loadFailed = true;
nextTick(() => { await nextTick();
expect(el.querySelector('.js-usage-info.usage-info-failed')).toBeDefined();
expect(el.querySelector('.js-usage-info.usage-info-failed')).toBeDefined();
expect(el.querySelector('.js-usage-info').innerText).toContain(messages.loadFailed); expect(el.querySelector('.js-usage-info').innerText).toContain(messages.loadFailed);
done();
});
}); });
it('should show metrics unavailable message when metrics loading failed', (done) => { it('should show metrics unavailable message when metrics loading failed', async () => {
vm.loadingMetrics = false; vm.loadingMetrics = false;
vm.hasMetrics = false; vm.hasMetrics = false;
vm.loadFailed = false; vm.loadFailed = false;
nextTick(() => { await nextTick();
expect(el.querySelector('.js-usage-info.usage-info-unavailable')).toBeDefined();
expect(el.querySelector('.js-usage-info.usage-info-unavailable')).toBeDefined();
expect(el.querySelector('.js-usage-info').innerText).toContain(messages.metricsUnavailable); expect(el.querySelector('.js-usage-info').innerText).toContain(messages.metricsUnavailable);
done();
});
}); });
}); });
}); });
...@@ -198,14 +198,13 @@ describe('MRWidgetMerged', () => { ...@@ -198,14 +198,13 @@ describe('MRWidgetMerged', () => {
); );
}); });
it('hides button to copy commit SHA if SHA does not exist', (done) => { it('hides button to copy commit SHA if SHA does not exist', async () => {
vm.mr.mergeCommitSha = null; vm.mr.mergeCommitSha = null;
nextTick(() => { await nextTick();
expect(selectors.copyMergeShaButton).toBe(null); expect(selectors.copyMergeShaButton).toBe(null);
expect(vm.$el.querySelector('.mr-info-list').innerText).not.toContain('with'); expect(vm.$el.querySelector('.mr-info-list').innerText).not.toContain('with');
done();
});
}); });
it('shows merge commit SHA link', () => { it('shows merge commit SHA link', () => {
...@@ -214,24 +213,22 @@ describe('MRWidgetMerged', () => { ...@@ -214,24 +213,22 @@ describe('MRWidgetMerged', () => {
expect(selectors.mergeCommitShaLink.href).toBe(vm.mr.mergeCommitPath); expect(selectors.mergeCommitShaLink.href).toBe(vm.mr.mergeCommitPath);
}); });
it('should not show source branch deleted text', (done) => { it('should not show source branch deleted text', async () => {
vm.mr.sourceBranchRemoved = false; vm.mr.sourceBranchRemoved = false;
nextTick(() => { await nextTick();
expect(vm.$el.innerText).not.toContain('The source branch has been deleted'); expect(vm.$el.innerText).not.toContain('The source branch has been deleted');
done();
});
}); });
it('should show source branch deleting text', (done) => { it('should show source branch deleting text', async () => {
vm.mr.isRemovingSourceBranch = true; vm.mr.isRemovingSourceBranch = true;
vm.mr.sourceBranchRemoved = false; vm.mr.sourceBranchRemoved = false;
nextTick(() => { await nextTick();
expect(vm.$el.innerText).toContain('The source branch is being deleted'); expect(vm.$el.innerText).toContain('The source branch is being deleted');
expect(vm.$el.innerText).not.toContain('The source branch has been deleted'); expect(vm.$el.innerText).not.toContain('The source branch has been deleted');
done();
});
}); });
it('should use mergedEvent mergedAt as tooltip title', () => { it('should use mergedEvent mergedAt as tooltip title', () => {
......
...@@ -189,9 +189,9 @@ describe('MrWidgetOptions', () => { ...@@ -189,9 +189,9 @@ describe('MrWidgetOptions', () => {
}); });
describe('when merge request is opened', () => { describe('when merge request is opened', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.isOpen = true; wrapper.vm.mr.isOpen = true;
nextTick(done); return nextTick();
}); });
it('should render collaboration status', () => { it('should render collaboration status', () => {
...@@ -200,9 +200,9 @@ describe('MrWidgetOptions', () => { ...@@ -200,9 +200,9 @@ describe('MrWidgetOptions', () => {
}); });
describe('when merge request is not opened', () => { describe('when merge request is not opened', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.isOpen = false; wrapper.vm.mr.isOpen = false;
nextTick(done); return nextTick();
}); });
it('should not render collaboration status', () => { it('should not render collaboration status', () => {
...@@ -217,9 +217,9 @@ describe('MrWidgetOptions', () => { ...@@ -217,9 +217,9 @@ describe('MrWidgetOptions', () => {
}); });
describe('when merge request is opened', () => { describe('when merge request is opened', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.isOpen = true; wrapper.vm.mr.isOpen = true;
nextTick(done); return nextTick();
}); });
it('should not render collaboration status', () => { it('should not render collaboration status', () => {
...@@ -231,11 +231,11 @@ describe('MrWidgetOptions', () => { ...@@ -231,11 +231,11 @@ describe('MrWidgetOptions', () => {
describe('showMergePipelineForkWarning', () => { describe('showMergePipelineForkWarning', () => {
describe('when the source project and target project are the same', () => { describe('when the source project and target project are the same', () => {
beforeEach((done) => { beforeEach(() => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true); Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1); Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 1); Vue.set(wrapper.vm.mr, 'targetProjectId', 1);
nextTick(done); return nextTick();
}); });
it('should be false', () => { it('should be false', () => {
...@@ -244,11 +244,11 @@ describe('MrWidgetOptions', () => { ...@@ -244,11 +244,11 @@ describe('MrWidgetOptions', () => {
}); });
describe('when merge pipelines are not enabled', () => { describe('when merge pipelines are not enabled', () => {
beforeEach((done) => { beforeEach(() => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', false); Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', false);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1); Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 2); Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
nextTick(done); return nextTick();
}); });
it('should be false', () => { it('should be false', () => {
...@@ -257,11 +257,11 @@ describe('MrWidgetOptions', () => { ...@@ -257,11 +257,11 @@ describe('MrWidgetOptions', () => {
}); });
describe('when merge pipelines are enabled _and_ the source project and target project are different', () => { describe('when merge pipelines are enabled _and_ the source project and target project are different', () => {
beforeEach((done) => { beforeEach(() => {
Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true); Vue.set(wrapper.vm.mr, 'mergePipelinesEnabled', true);
Vue.set(wrapper.vm.mr, 'sourceProjectId', 1); Vue.set(wrapper.vm.mr, 'sourceProjectId', 1);
Vue.set(wrapper.vm.mr, 'targetProjectId', 2); Vue.set(wrapper.vm.mr, 'targetProjectId', 2);
nextTick(done); return nextTick();
}); });
it('should be true', () => { it('should be true', () => {
...@@ -441,15 +441,10 @@ describe('MrWidgetOptions', () => { ...@@ -441,15 +441,10 @@ describe('MrWidgetOptions', () => {
expect(setFaviconOverlay).toHaveBeenCalledWith(overlayDataUrl); expect(setFaviconOverlay).toHaveBeenCalledWith(overlayDataUrl);
}); });
it('should not call setFavicon when there is no ciStatusFaviconPath', (done) => { it('should not call setFavicon when there is no ciStatusFaviconPath', async () => {
wrapper.vm.mr.ciStatusFaviconPath = null; wrapper.vm.mr.ciStatusFaviconPath = null;
wrapper.vm await wrapper.vm.setFaviconHelper();
.setFaviconHelper()
.then(() => {
expect(faviconElement.getAttribute('href')).toEqual(null); expect(faviconElement.getAttribute('href')).toEqual(null);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -536,44 +531,36 @@ describe('MrWidgetOptions', () => { ...@@ -536,44 +531,36 @@ describe('MrWidgetOptions', () => {
expect(wrapper.find('.close-related-link').exists()).toBe(true); expect(wrapper.find('.close-related-link').exists()).toBe(true);
}); });
it('does not render if state is nothingToMerge', (done) => { it('does not render if state is nothingToMerge', async () => {
wrapper.vm.mr.state = stateKey.nothingToMerge; wrapper.vm.mr.state = stateKey.nothingToMerge;
nextTick(() => { await nextTick();
expect(wrapper.find('.close-related-link').exists()).toBe(false); expect(wrapper.find('.close-related-link').exists()).toBe(false);
done();
});
}); });
}); });
describe('rendering source branch removal status', () => { describe('rendering source branch removal status', () => {
it('renders when user cannot remove branch and branch should be removed', (done) => { it('renders when user cannot remove branch and branch should be removed', async () => {
wrapper.vm.mr.canRemoveSourceBranch = false; wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true; wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'readyToMerge'; wrapper.vm.mr.state = 'readyToMerge';
nextTick(() => { await nextTick();
const tooltip = wrapper.find('[data-testid="question-o-icon"]'); const tooltip = wrapper.find('[data-testid="question-o-icon"]');
expect(wrapper.text()).toContain('Deletes the source branch'); expect(wrapper.text()).toContain('Deletes the source branch');
expect(tooltip.attributes('title')).toBe( expect(tooltip.attributes('title')).toBe(
'A user with write access to the source branch selected this option', 'A user with write access to the source branch selected this option',
); );
done();
});
}); });
it('does not render in merged state', (done) => { it('does not render in merged state', async () => {
wrapper.vm.mr.canRemoveSourceBranch = false; wrapper.vm.mr.canRemoveSourceBranch = false;
wrapper.vm.mr.shouldRemoveSourceBranch = true; wrapper.vm.mr.shouldRemoveSourceBranch = true;
wrapper.vm.mr.state = 'merged'; wrapper.vm.mr.state = 'merged';
nextTick(() => { await nextTick();
expect(wrapper.text()).toContain('The source branch has been deleted'); expect(wrapper.text()).toContain('The source branch has been deleted');
expect(wrapper.text()).not.toContain('Deletes the source branch'); expect(wrapper.text()).not.toContain('Deletes the source branch');
done();
});
}); });
}); });
...@@ -607,7 +594,7 @@ describe('MrWidgetOptions', () => { ...@@ -607,7 +594,7 @@ describe('MrWidgetOptions', () => {
status: SUCCESS, status: SUCCESS,
}; };
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.deployments.push( wrapper.vm.mr.deployments.push(
{ {
...deploymentMockData, ...deploymentMockData,
...@@ -618,7 +605,7 @@ describe('MrWidgetOptions', () => { ...@@ -618,7 +605,7 @@ describe('MrWidgetOptions', () => {
}, },
); );
nextTick(done); return nextTick();
}); });
it('renders multiple deployments', () => { it('renders multiple deployments', () => {
...@@ -641,7 +628,7 @@ describe('MrWidgetOptions', () => { ...@@ -641,7 +628,7 @@ describe('MrWidgetOptions', () => {
describe('pipeline for target branch after merge', () => { describe('pipeline for target branch after merge', () => {
describe('with information for target branch pipeline', () => { describe('with information for target branch pipeline', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.state = 'merged'; wrapper.vm.mr.state = 'merged';
wrapper.vm.mr.mergePipeline = { wrapper.vm.mr.mergePipeline = {
id: 127, id: 127,
...@@ -749,7 +736,7 @@ describe('MrWidgetOptions', () => { ...@@ -749,7 +736,7 @@ describe('MrWidgetOptions', () => {
}, },
cancel_path: '/root/ci-web-terminal/pipelines/127/cancel', cancel_path: '/root/ci-web-terminal/pipelines/127/cancel',
}; };
nextTick(done); return nextTick();
}); });
it('renders pipeline block', () => { it('renders pipeline block', () => {
...@@ -757,7 +744,7 @@ describe('MrWidgetOptions', () => { ...@@ -757,7 +744,7 @@ describe('MrWidgetOptions', () => {
}); });
describe('with post merge deployments', () => { describe('with post merge deployments', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.postMergeDeployments = [ wrapper.vm.mr.postMergeDeployments = [
{ {
id: 15, id: 15,
...@@ -789,7 +776,7 @@ describe('MrWidgetOptions', () => { ...@@ -789,7 +776,7 @@ describe('MrWidgetOptions', () => {
}, },
]; ];
nextTick(done); return nextTick();
}); });
it('renders post deployment information', () => { it('renders post deployment information', () => {
...@@ -799,10 +786,10 @@ describe('MrWidgetOptions', () => { ...@@ -799,10 +786,10 @@ describe('MrWidgetOptions', () => {
}); });
describe('without information for target branch pipeline', () => { describe('without information for target branch pipeline', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.state = 'merged'; wrapper.vm.mr.state = 'merged';
nextTick(done); return nextTick();
}); });
it('does not render pipeline block', () => { it('does not render pipeline block', () => {
...@@ -811,10 +798,10 @@ describe('MrWidgetOptions', () => { ...@@ -811,10 +798,10 @@ describe('MrWidgetOptions', () => {
}); });
describe('when state is not merged', () => { describe('when state is not merged', () => {
beforeEach((done) => { beforeEach(() => {
wrapper.vm.mr.state = 'archived'; wrapper.vm.mr.state = 'archived';
nextTick(done); return nextTick();
}); });
it('does not render pipeline block', () => { it('does not render pipeline block', () => {
......
...@@ -22,27 +22,25 @@ describe('Artifacts App Store Actions', () => { ...@@ -22,27 +22,25 @@ describe('Artifacts App Store Actions', () => {
}); });
describe('setEndpoint', () => { describe('setEndpoint', () => {
it('should commit SET_ENDPOINT mutation', (done) => { it('should commit SET_ENDPOINT mutation', () => {
testAction( return testAction(
setEndpoint, setEndpoint,
'endpoint.json', 'endpoint.json',
mockedState, mockedState,
[{ type: types.SET_ENDPOINT, payload: 'endpoint.json' }], [{ type: types.SET_ENDPOINT, payload: 'endpoint.json' }],
[], [],
done,
); );
}); });
}); });
describe('requestArtifacts', () => { describe('requestArtifacts', () => {
it('should commit REQUEST_ARTIFACTS mutation', (done) => { it('should commit REQUEST_ARTIFACTS mutation', () => {
testAction( return testAction(
requestArtifacts, requestArtifacts,
null, null,
mockedState, mockedState,
[{ type: types.REQUEST_ARTIFACTS }], [{ type: types.REQUEST_ARTIFACTS }],
[], [],
done,
); );
}); });
}); });
...@@ -62,7 +60,7 @@ describe('Artifacts App Store Actions', () => { ...@@ -62,7 +60,7 @@ describe('Artifacts App Store Actions', () => {
}); });
describe('success', () => { describe('success', () => {
it('dispatches requestArtifacts and receiveArtifactsSuccess ', (done) => { it('dispatches requestArtifacts and receiveArtifactsSuccess ', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, [ mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, [
{ {
text: 'result.txt', text: 'result.txt',
...@@ -72,7 +70,7 @@ describe('Artifacts App Store Actions', () => { ...@@ -72,7 +70,7 @@ describe('Artifacts App Store Actions', () => {
}, },
]); ]);
testAction( return testAction(
fetchArtifacts, fetchArtifacts,
null, null,
mockedState, mockedState,
...@@ -96,7 +94,6 @@ describe('Artifacts App Store Actions', () => { ...@@ -96,7 +94,6 @@ describe('Artifacts App Store Actions', () => {
type: 'receiveArtifactsSuccess', type: 'receiveArtifactsSuccess',
}, },
], ],
done,
); );
}); });
}); });
...@@ -106,8 +103,8 @@ describe('Artifacts App Store Actions', () => { ...@@ -106,8 +103,8 @@ describe('Artifacts App Store Actions', () => {
mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500);
}); });
it('dispatches requestArtifacts and receiveArtifactsError ', (done) => { it('dispatches requestArtifacts and receiveArtifactsError ', () => {
testAction( return testAction(
fetchArtifacts, fetchArtifacts,
null, null,
mockedState, mockedState,
...@@ -120,45 +117,41 @@ describe('Artifacts App Store Actions', () => { ...@@ -120,45 +117,41 @@ describe('Artifacts App Store Actions', () => {
type: 'receiveArtifactsError', type: 'receiveArtifactsError',
}, },
], ],
done,
); );
}); });
}); });
}); });
describe('receiveArtifactsSuccess', () => { describe('receiveArtifactsSuccess', () => {
it('should commit RECEIVE_ARTIFACTS_SUCCESS mutation with 200', (done) => { it('should commit RECEIVE_ARTIFACTS_SUCCESS mutation with 200', () => {
testAction( return testAction(
receiveArtifactsSuccess, receiveArtifactsSuccess,
{ data: { summary: {} }, status: 200 }, { data: { summary: {} }, status: 200 },
mockedState, mockedState,
[{ type: types.RECEIVE_ARTIFACTS_SUCCESS, payload: { summary: {} } }], [{ type: types.RECEIVE_ARTIFACTS_SUCCESS, payload: { summary: {} } }],
[], [],
done,
); );
}); });
it('should not commit RECEIVE_ARTIFACTS_SUCCESS mutation with 204', (done) => { it('should not commit RECEIVE_ARTIFACTS_SUCCESS mutation with 204', () => {
testAction( return testAction(
receiveArtifactsSuccess, receiveArtifactsSuccess,
{ data: { summary: {} }, status: 204 }, { data: { summary: {} }, status: 204 },
mockedState, mockedState,
[], [],
[], [],
done,
); );
}); });
}); });
describe('receiveArtifactsError', () => { describe('receiveArtifactsError', () => {
it('should commit RECEIVE_ARTIFACTS_ERROR mutation', (done) => { it('should commit RECEIVE_ARTIFACTS_ERROR mutation', () => {
testAction( return testAction(
receiveArtifactsError, receiveArtifactsError,
null, null,
mockedState, mockedState,
[{ type: types.RECEIVE_ARTIFACTS_ERROR }], [{ type: types.RECEIVE_ARTIFACTS_ERROR }],
[], [],
done,
); );
}); });
}); });
......
...@@ -21,87 +21,81 @@ describe('LabelsSelect Actions', () => { ...@@ -21,87 +21,81 @@ describe('LabelsSelect Actions', () => {
}); });
describe('setInitialState', () => { describe('setInitialState', () => {
it('sets initial store state', (done) => { it('sets initial store state', () => {
testAction( return testAction(
actions.setInitialState, actions.setInitialState,
mockInitialState, mockInitialState,
state, state,
[{ type: types.SET_INITIAL_STATE, payload: mockInitialState }], [{ type: types.SET_INITIAL_STATE, payload: mockInitialState }],
[], [],
done,
); );
}); });
}); });
describe('toggleDropdownButton', () => { describe('toggleDropdownButton', () => {
it('toggles dropdown button', (done) => { it('toggles dropdown button', () => {
testAction( return testAction(
actions.toggleDropdownButton, actions.toggleDropdownButton,
{}, {},
state, state,
[{ type: types.TOGGLE_DROPDOWN_BUTTON }], [{ type: types.TOGGLE_DROPDOWN_BUTTON }],
[], [],
done,
); );
}); });
}); });
describe('toggleDropdownContents', () => { describe('toggleDropdownContents', () => {
it('toggles dropdown contents', (done) => { it('toggles dropdown contents', () => {
testAction( return testAction(
actions.toggleDropdownContents, actions.toggleDropdownContents,
{}, {},
state, state,
[{ type: types.TOGGLE_DROPDOWN_CONTENTS }], [{ type: types.TOGGLE_DROPDOWN_CONTENTS }],
[], [],
done,
); );
}); });
}); });
describe('toggleDropdownContentsCreateView', () => { describe('toggleDropdownContentsCreateView', () => {
it('toggles dropdown create view', (done) => { it('toggles dropdown create view', () => {
testAction( return testAction(
actions.toggleDropdownContentsCreateView, actions.toggleDropdownContentsCreateView,
{}, {},
state, state,
[{ type: types.TOGGLE_DROPDOWN_CONTENTS_CREATE_VIEW }], [{ type: types.TOGGLE_DROPDOWN_CONTENTS_CREATE_VIEW }],
[], [],
done,
); );
}); });
}); });
describe('requestLabels', () => { describe('requestLabels', () => {
it('sets value of `state.labelsFetchInProgress` to `true`', (done) => { it('sets value of `state.labelsFetchInProgress` to `true`', () => {
testAction(actions.requestLabels, {}, state, [{ type: types.REQUEST_LABELS }], [], done); return testAction(actions.requestLabels, {}, state, [{ type: types.REQUEST_LABELS }], []);
}); });
}); });
describe('receiveLabelsSuccess', () => { describe('receiveLabelsSuccess', () => {
it('sets provided labels to `state.labels`', (done) => { it('sets provided labels to `state.labels`', () => {
const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]; const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
testAction( return testAction(
actions.receiveLabelsSuccess, actions.receiveLabelsSuccess,
labels, labels,
state, state,
[{ type: types.RECEIVE_SET_LABELS_SUCCESS, payload: labels }], [{ type: types.RECEIVE_SET_LABELS_SUCCESS, payload: labels }],
[], [],
done,
); );
}); });
}); });
describe('receiveLabelsFailure', () => { describe('receiveLabelsFailure', () => {
it('sets value `state.labelsFetchInProgress` to `false`', (done) => { it('sets value `state.labelsFetchInProgress` to `false`', () => {
testAction( return testAction(
actions.receiveLabelsFailure, actions.receiveLabelsFailure,
{}, {},
state, state,
[{ type: types.RECEIVE_SET_LABELS_FAILURE }], [{ type: types.RECEIVE_SET_LABELS_FAILURE }],
[], [],
done,
); );
}); });
...@@ -125,72 +119,67 @@ describe('LabelsSelect Actions', () => { ...@@ -125,72 +119,67 @@ describe('LabelsSelect Actions', () => {
}); });
describe('on success', () => { describe('on success', () => {
it('dispatches `requestLabels` & `receiveLabelsSuccess` actions', (done) => { it('dispatches `requestLabels` & `receiveLabelsSuccess` actions', () => {
const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]; const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
mock.onGet(/labels.json/).replyOnce(200, labels); mock.onGet(/labels.json/).replyOnce(200, labels);
testAction( return testAction(
actions.fetchLabels, actions.fetchLabels,
{}, {},
state, state,
[], [],
[{ type: 'requestLabels' }, { type: 'receiveLabelsSuccess', payload: labels }], [{ type: 'requestLabels' }, { type: 'receiveLabelsSuccess', payload: labels }],
done,
); );
}); });
}); });
describe('on failure', () => { describe('on failure', () => {
it('dispatches `requestLabels` & `receiveLabelsFailure` actions', (done) => { it('dispatches `requestLabels` & `receiveLabelsFailure` actions', () => {
mock.onGet(/labels.json/).replyOnce(500, {}); mock.onGet(/labels.json/).replyOnce(500, {});
testAction( return testAction(
actions.fetchLabels, actions.fetchLabels,
{}, {},
state, state,
[], [],
[{ type: 'requestLabels' }, { type: 'receiveLabelsFailure' }], [{ type: 'requestLabels' }, { type: 'receiveLabelsFailure' }],
done,
); );
}); });
}); });
}); });
describe('requestCreateLabel', () => { describe('requestCreateLabel', () => {
it('sets value `state.labelCreateInProgress` to `true`', (done) => { it('sets value `state.labelCreateInProgress` to `true`', () => {
testAction( return testAction(
actions.requestCreateLabel, actions.requestCreateLabel,
{}, {},
state, state,
[{ type: types.REQUEST_CREATE_LABEL }], [{ type: types.REQUEST_CREATE_LABEL }],
[], [],
done,
); );
}); });
}); });
describe('receiveCreateLabelSuccess', () => { describe('receiveCreateLabelSuccess', () => {
it('sets value `state.labelCreateInProgress` to `false`', (done) => { it('sets value `state.labelCreateInProgress` to `false`', () => {
testAction( return testAction(
actions.receiveCreateLabelSuccess, actions.receiveCreateLabelSuccess,
{}, {},
state, state,
[{ type: types.RECEIVE_CREATE_LABEL_SUCCESS }], [{ type: types.RECEIVE_CREATE_LABEL_SUCCESS }],
[], [],
done,
); );
}); });
}); });
describe('receiveCreateLabelFailure', () => { describe('receiveCreateLabelFailure', () => {
it('sets value `state.labelCreateInProgress` to `false`', (done) => { it('sets value `state.labelCreateInProgress` to `false`', () => {
testAction( return testAction(
actions.receiveCreateLabelFailure, actions.receiveCreateLabelFailure,
{}, {},
state, state,
[{ type: types.RECEIVE_CREATE_LABEL_FAILURE }], [{ type: types.RECEIVE_CREATE_LABEL_FAILURE }],
[], [],
done,
); );
}); });
...@@ -214,11 +203,11 @@ describe('LabelsSelect Actions', () => { ...@@ -214,11 +203,11 @@ describe('LabelsSelect Actions', () => {
}); });
describe('on success', () => { describe('on success', () => {
it('dispatches `requestCreateLabel`, `fetchLabels` & `receiveCreateLabelSuccess` & `toggleDropdownContentsCreateView` actions', (done) => { it('dispatches `requestCreateLabel`, `fetchLabels` & `receiveCreateLabelSuccess` & `toggleDropdownContentsCreateView` actions', () => {
const label = { id: 1 }; const label = { id: 1 };
mock.onPost(/labels.json/).replyOnce(200, label); mock.onPost(/labels.json/).replyOnce(200, label);
testAction( return testAction(
actions.createLabel, actions.createLabel,
{}, {},
state, state,
...@@ -229,38 +218,35 @@ describe('LabelsSelect Actions', () => { ...@@ -229,38 +218,35 @@ describe('LabelsSelect Actions', () => {
{ type: 'receiveCreateLabelSuccess' }, { type: 'receiveCreateLabelSuccess' },
{ type: 'toggleDropdownContentsCreateView' }, { type: 'toggleDropdownContentsCreateView' },
], ],
done,
); );
}); });
}); });
describe('on failure', () => { describe('on failure', () => {
it('dispatches `requestCreateLabel` & `receiveCreateLabelFailure` actions', (done) => { it('dispatches `requestCreateLabel` & `receiveCreateLabelFailure` actions', () => {
mock.onPost(/labels.json/).replyOnce(500, {}); mock.onPost(/labels.json/).replyOnce(500, {});
testAction( return testAction(
actions.createLabel, actions.createLabel,
{}, {},
state, state,
[], [],
[{ type: 'requestCreateLabel' }, { type: 'receiveCreateLabelFailure' }], [{ type: 'requestCreateLabel' }, { type: 'receiveCreateLabelFailure' }],
done,
); );
}); });
}); });
}); });
describe('updateSelectedLabels', () => { describe('updateSelectedLabels', () => {
it('updates `state.labels` based on provided `labels` param', (done) => { it('updates `state.labels` based on provided `labels` param', () => {
const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]; const labels = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }];
testAction( return testAction(
actions.updateSelectedLabels, actions.updateSelectedLabels,
labels, labels,
state, state,
[{ type: types.UPDATE_SELECTED_LABELS, payload: { labels } }], [{ type: types.UPDATE_SELECTED_LABELS, payload: { labels } }],
[], [],
done,
); );
}); });
}); });
......
...@@ -26,8 +26,8 @@ describe('sast report actions', () => { ...@@ -26,8 +26,8 @@ describe('sast report actions', () => {
}); });
describe('setDiffEndpoint', () => { describe('setDiffEndpoint', () => {
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, (done) => { it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, () => {
testAction( return testAction(
actions.setDiffEndpoint, actions.setDiffEndpoint,
diffEndpoint, diffEndpoint,
state, state,
...@@ -38,20 +38,19 @@ describe('sast report actions', () => { ...@@ -38,20 +38,19 @@ describe('sast report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('requestDiff', () => { describe('requestDiff', () => {
it(`should commit ${types.REQUEST_DIFF}`, (done) => { it(`should commit ${types.REQUEST_DIFF}`, () => {
testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], [], done); return testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], []);
}); });
}); });
describe('receiveDiffSuccess', () => { describe('receiveDiffSuccess', () => {
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, (done) => { it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, () => {
testAction( return testAction(
actions.receiveDiffSuccess, actions.receiveDiffSuccess,
reports, reports,
state, state,
...@@ -62,14 +61,13 @@ describe('sast report actions', () => { ...@@ -62,14 +61,13 @@ describe('sast report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('receiveDiffError', () => { describe('receiveDiffError', () => {
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, (done) => { it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, () => {
testAction( return testAction(
actions.receiveDiffError, actions.receiveDiffError,
error, error,
state, state,
...@@ -80,7 +78,6 @@ describe('sast report actions', () => { ...@@ -80,7 +78,6 @@ describe('sast report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
...@@ -107,9 +104,9 @@ describe('sast report actions', () => { ...@@ -107,9 +104,9 @@ describe('sast report actions', () => {
.replyOnce(200, reports.enrichData); .replyOnce(200, reports.enrichData);
}); });
it('should dispatch the `receiveDiffSuccess` action', (done) => { it('should dispatch the `receiveDiffSuccess` action', () => {
const { diff, enrichData } = reports; const { diff, enrichData } = reports;
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
...@@ -124,7 +121,6 @@ describe('sast report actions', () => { ...@@ -124,7 +121,6 @@ describe('sast report actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -135,10 +131,10 @@ describe('sast report actions', () => { ...@@ -135,10 +131,10 @@ describe('sast report actions', () => {
mock.onGet(diffEndpoint).replyOnce(200, reports.diff); mock.onGet(diffEndpoint).replyOnce(200, reports.diff);
}); });
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', (done) => { it('should dispatch the `receiveDiffSuccess` action with empty enrich data', () => {
const { diff } = reports; const { diff } = reports;
const enrichData = []; const enrichData = [];
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
...@@ -153,7 +149,6 @@ describe('sast report actions', () => { ...@@ -153,7 +149,6 @@ describe('sast report actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -167,14 +162,13 @@ describe('sast report actions', () => { ...@@ -167,14 +162,13 @@ describe('sast report actions', () => {
.replyOnce(404); .replyOnce(404);
}); });
it('should dispatch the `receiveError` action', (done) => { it('should dispatch the `receiveError` action', () => {
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
[], [],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }], [{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
); );
}); });
}); });
...@@ -188,14 +182,13 @@ describe('sast report actions', () => { ...@@ -188,14 +182,13 @@ describe('sast report actions', () => {
.replyOnce(200, reports.enrichData); .replyOnce(200, reports.enrichData);
}); });
it('should dispatch the `receiveDiffError` action', (done) => { it('should dispatch the `receiveDiffError` action', () => {
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
[], [],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }], [{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
); );
}); });
}); });
......
...@@ -26,8 +26,8 @@ describe('secret detection report actions', () => { ...@@ -26,8 +26,8 @@ describe('secret detection report actions', () => {
}); });
describe('setDiffEndpoint', () => { describe('setDiffEndpoint', () => {
it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, (done) => { it(`should commit ${types.SET_DIFF_ENDPOINT} with the correct path`, () => {
testAction( return testAction(
actions.setDiffEndpoint, actions.setDiffEndpoint,
diffEndpoint, diffEndpoint,
state, state,
...@@ -38,20 +38,19 @@ describe('secret detection report actions', () => { ...@@ -38,20 +38,19 @@ describe('secret detection report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('requestDiff', () => { describe('requestDiff', () => {
it(`should commit ${types.REQUEST_DIFF}`, (done) => { it(`should commit ${types.REQUEST_DIFF}`, () => {
testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], [], done); return testAction(actions.requestDiff, {}, state, [{ type: types.REQUEST_DIFF }], []);
}); });
}); });
describe('receiveDiffSuccess', () => { describe('receiveDiffSuccess', () => {
it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, (done) => { it(`should commit ${types.RECEIVE_DIFF_SUCCESS} with the correct response`, () => {
testAction( return testAction(
actions.receiveDiffSuccess, actions.receiveDiffSuccess,
reports, reports,
state, state,
...@@ -62,14 +61,13 @@ describe('secret detection report actions', () => { ...@@ -62,14 +61,13 @@ describe('secret detection report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
describe('receiveDiffError', () => { describe('receiveDiffError', () => {
it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, (done) => { it(`should commit ${types.RECEIVE_DIFF_ERROR} with the correct response`, () => {
testAction( return testAction(
actions.receiveDiffError, actions.receiveDiffError,
error, error,
state, state,
...@@ -80,7 +78,6 @@ describe('secret detection report actions', () => { ...@@ -80,7 +78,6 @@ describe('secret detection report actions', () => {
}, },
], ],
[], [],
done,
); );
}); });
}); });
...@@ -107,9 +104,10 @@ describe('secret detection report actions', () => { ...@@ -107,9 +104,10 @@ describe('secret detection report actions', () => {
.replyOnce(200, reports.enrichData); .replyOnce(200, reports.enrichData);
}); });
it('should dispatch the `receiveDiffSuccess` action', (done) => { it('should dispatch the `receiveDiffSuccess` action', () => {
const { diff, enrichData } = reports; const { diff, enrichData } = reports;
testAction(
return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
...@@ -124,7 +122,6 @@ describe('secret detection report actions', () => { ...@@ -124,7 +122,6 @@ describe('secret detection report actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -135,10 +132,10 @@ describe('secret detection report actions', () => { ...@@ -135,10 +132,10 @@ describe('secret detection report actions', () => {
mock.onGet(diffEndpoint).replyOnce(200, reports.diff); mock.onGet(diffEndpoint).replyOnce(200, reports.diff);
}); });
it('should dispatch the `receiveDiffSuccess` action with empty enrich data', (done) => { it('should dispatch the `receiveDiffSuccess` action with empty enrich data', () => {
const { diff } = reports; const { diff } = reports;
const enrichData = []; const enrichData = [];
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
...@@ -153,7 +150,6 @@ describe('secret detection report actions', () => { ...@@ -153,7 +150,6 @@ describe('secret detection report actions', () => {
}, },
}, },
], ],
done,
); );
}); });
}); });
...@@ -167,14 +163,13 @@ describe('secret detection report actions', () => { ...@@ -167,14 +163,13 @@ describe('secret detection report actions', () => {
.replyOnce(404); .replyOnce(404);
}); });
it('should dispatch the `receiveDiffError` action', (done) => { it('should dispatch the `receiveDiffError` action', () => {
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
[], [],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }], [{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
); );
}); });
}); });
...@@ -188,14 +183,13 @@ describe('secret detection report actions', () => { ...@@ -188,14 +183,13 @@ describe('secret detection report actions', () => {
.replyOnce(200, reports.enrichData); .replyOnce(200, reports.enrichData);
}); });
it('should dispatch the `receiveDiffError` action', (done) => { it('should dispatch the `receiveDiffError` action', () => {
testAction( return testAction(
actions.fetchDiff, actions.fetchDiff,
{}, {},
{ ...rootState, ...state }, { ...rootState, ...state },
[], [],
[{ type: 'requestDiff' }, { type: 'receiveDiffError' }], [{ type: 'requestDiff' }, { type: 'receiveDiffError' }],
done,
); );
}); });
}); });
......
...@@ -4,28 +4,28 @@ import * as types from '~/vuex_shared/modules/modal/mutation_types'; ...@@ -4,28 +4,28 @@ import * as types from '~/vuex_shared/modules/modal/mutation_types';
describe('Vuex ModalModule actions', () => { describe('Vuex ModalModule actions', () => {
describe('open', () => { describe('open', () => {
it('works', (done) => { it('works', () => {
const data = { id: 7 }; const data = { id: 7 };
testAction(actions.open, data, {}, [{ type: types.OPEN, payload: data }], [], done); return testAction(actions.open, data, {}, [{ type: types.OPEN, payload: data }], []);
}); });
}); });
describe('close', () => { describe('close', () => {
it('works', (done) => { it('works', () => {
testAction(actions.close, null, {}, [{ type: types.CLOSE }], [], done); return testAction(actions.close, null, {}, [{ type: types.CLOSE }], []);
}); });
}); });
describe('show', () => { describe('show', () => {
it('works', (done) => { it('works', () => {
testAction(actions.show, null, {}, [{ type: types.SHOW }], [], done); return testAction(actions.show, null, {}, [{ type: types.SHOW }], []);
}); });
}); });
describe('hide', () => { describe('hide', () => {
it('works', (done) => { it('works', () => {
testAction(actions.hide, null, {}, [{ type: types.HIDE }], [], done); return testAction(actions.hide, null, {}, [{ type: types.HIDE }], []);
}); });
}); });
}); });
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