summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/modules/pipelines/actions_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/ide/stores/modules/pipelines/actions_spec.js')
-rw-r--r--spec/frontend/ide/stores/modules/pipelines/actions_spec.js152
1 files changed, 62 insertions, 90 deletions
diff --git a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js
index 3ede37e2eed..b76b673c3a2 100644
--- a/spec/frontend/ide/stores/modules/pipelines/actions_spec.js
+++ b/spec/frontend/ide/stores/modules/pipelines/actions_spec.js
@@ -25,6 +25,7 @@ import {
import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import state from '~/ide/stores/modules/pipelines/state';
import axios from '~/lib/utils/axios_utils';
+import waitForPromises from 'helpers/wait_for_promises';
import { pipelines, jobs } from '../../../mock_data';
describe('IDE pipelines actions', () => {
@@ -44,32 +45,30 @@ describe('IDE pipelines actions', () => {
});
describe('requestLatestPipeline', () => {
- it('commits request', (done) => {
- testAction(
+ it('commits request', () => {
+ return testAction(
requestLatestPipeline,
null,
mockedState,
[{ type: types.REQUEST_LATEST_PIPELINE }],
[],
- done,
);
});
});
describe('receiveLatestPipelineError', () => {
- it('commits error', (done) => {
- testAction(
+ it('commits error', () => {
+ return testAction(
receiveLatestPipelineError,
{ status: 404 },
mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }],
[{ type: 'stopPipelinePolling' }],
- done,
);
});
- it('dispatches setErrorMessage is not 404', (done) => {
- testAction(
+ it('dispatches setErrorMessage is not 404', () => {
+ return testAction(
receiveLatestPipelineError,
{ status: 500 },
mockedState,
@@ -86,7 +85,6 @@ describe('IDE pipelines actions', () => {
},
{ type: 'stopPipelinePolling' },
],
- done,
);
});
});
@@ -123,7 +121,7 @@ describe('IDE pipelines actions', () => {
.reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' });
});
- it('dispatches request', (done) => {
+ it('dispatches request', async () => {
jest.spyOn(axios, 'get');
jest.spyOn(Visibility, 'hidden').mockReturnValue(false);
@@ -133,34 +131,21 @@ describe('IDE pipelines actions', () => {
currentProject: { path_with_namespace: 'abc/def' },
};
- fetchLatestPipeline({ dispatch, rootGetters });
+ await fetchLatestPipeline({ dispatch, rootGetters });
expect(dispatch).toHaveBeenCalledWith('requestLatestPipeline');
- jest.advanceTimersByTime(1000);
-
- new Promise((resolve) => requestAnimationFrame(resolve))
- .then(() => {
- expect(axios.get).toHaveBeenCalled();
- expect(axios.get).toHaveBeenCalledTimes(1);
- expect(dispatch).toHaveBeenCalledWith(
- 'receiveLatestPipelineSuccess',
- expect.anything(),
- );
-
- jest.advanceTimersByTime(10000);
- })
- .then(() => new Promise((resolve) => requestAnimationFrame(resolve)))
- .then(() => {
- expect(axios.get).toHaveBeenCalled();
- expect(axios.get).toHaveBeenCalledTimes(2);
- expect(dispatch).toHaveBeenCalledWith(
- 'receiveLatestPipelineSuccess',
- expect.anything(),
- );
- })
- .then(done)
- .catch(done.fail);
+ await waitForPromises();
+
+ expect(axios.get).toHaveBeenCalled();
+ expect(axios.get).toHaveBeenCalledTimes(1);
+ expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything());
+
+ jest.advanceTimersByTime(10000);
+
+ expect(axios.get).toHaveBeenCalled();
+ expect(axios.get).toHaveBeenCalledTimes(2);
+ expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineSuccess', expect.anything());
});
});
@@ -169,27 +154,22 @@ describe('IDE pipelines actions', () => {
mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(500);
});
- it('dispatches error', (done) => {
+ it('dispatches error', async () => {
const dispatch = jest.fn().mockName('dispatch');
const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' },
currentProject: { path_with_namespace: 'abc/def' },
};
- fetchLatestPipeline({ dispatch, rootGetters });
+ await fetchLatestPipeline({ dispatch, rootGetters });
- jest.advanceTimersByTime(1500);
+ await waitForPromises();
- new Promise((resolve) => requestAnimationFrame(resolve))
- .then(() => {
- expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything());
- })
- .then(done)
- .catch(done.fail);
+ expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything());
});
});
- it('sets latest pipeline to `null` and stops polling on empty project', (done) => {
+ it('sets latest pipeline to `null` and stops polling on empty project', () => {
mockedState = {
...mockedState,
rootGetters: {
@@ -197,26 +177,31 @@ describe('IDE pipelines actions', () => {
},
};
- testAction(
+ return testAction(
fetchLatestPipeline,
{},
mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS, payload: null }],
[{ type: 'stopPipelinePolling' }],
- done,
);
});
});
describe('requestJobs', () => {
- it('commits request', (done) => {
- testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done);
+ it('commits request', () => {
+ return testAction(
+ requestJobs,
+ 1,
+ mockedState,
+ [{ type: types.REQUEST_JOBS, payload: 1 }],
+ [],
+ );
});
});
describe('receiveJobsError', () => {
- it('commits error', (done) => {
- testAction(
+ it('commits error', () => {
+ return testAction(
receiveJobsError,
{ id: 1 },
mockedState,
@@ -232,20 +217,18 @@ describe('IDE pipelines actions', () => {
},
},
],
- done,
);
});
});
describe('receiveJobsSuccess', () => {
- it('commits data', (done) => {
- testAction(
+ it('commits data', () => {
+ return testAction(
receiveJobsSuccess,
{ id: 1, data: jobs },
mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }],
[],
- done,
);
});
});
@@ -258,8 +241,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(stage.dropdownPath).replyOnce(200, jobs);
});
- it('dispatches request', (done) => {
- testAction(
+ it('dispatches request', () => {
+ return testAction(
fetchJobs,
stage,
mockedState,
@@ -268,7 +251,6 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } },
],
- done,
);
});
});
@@ -278,8 +260,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(stage.dropdownPath).replyOnce(500);
});
- it('dispatches error', (done) => {
- testAction(
+ it('dispatches error', () => {
+ return testAction(
fetchJobs,
stage,
mockedState,
@@ -288,69 +270,64 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsError', payload: stage },
],
- done,
);
});
});
});
describe('toggleStageCollapsed', () => {
- it('commits collapse', (done) => {
- testAction(
+ it('commits collapse', () => {
+ return testAction(
toggleStageCollapsed,
1,
mockedState,
[{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }],
[],
- done,
);
});
});
describe('setDetailJob', () => {
- it('commits job', (done) => {
- testAction(
+ it('commits job', () => {
+ return testAction(
setDetailJob,
'job',
mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }],
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }],
- done,
);
});
- it('dispatches rightPane/open as pipeline when job is null', (done) => {
- testAction(
+ it('dispatches rightPane/open as pipeline when job is null', () => {
+ return testAction(
setDetailJob,
null,
mockedState,
[{ type: types.SET_DETAIL_JOB, payload: null }],
[{ type: 'rightPane/open', payload: rightSidebarViews.pipelines }],
- done,
);
});
- it('dispatches rightPane/open as job', (done) => {
- testAction(
+ it('dispatches rightPane/open as job', () => {
+ return testAction(
setDetailJob,
'job',
mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }],
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }],
- done,
);
});
});
describe('requestJobLogs', () => {
- it('commits request', (done) => {
- testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], [], done);
+ it('commits request', () => {
+ return testAction(requestJobLogs, null, mockedState, [{ type: types.REQUEST_JOB_LOGS }], []);
});
});
describe('receiveJobLogsError', () => {
- it('commits error', (done) => {
- testAction(
+ it('commits error', () => {
+ return testAction(
receiveJobLogsError,
null,
mockedState,
@@ -366,20 +343,18 @@ describe('IDE pipelines actions', () => {
},
},
],
- done,
);
});
});
describe('receiveJobLogsSuccess', () => {
- it('commits data', (done) => {
- testAction(
+ it('commits data', () => {
+ return testAction(
receiveJobLogsSuccess,
'data',
mockedState,
[{ type: types.RECEIVE_JOB_LOGS_SUCCESS, payload: 'data' }],
[],
- done,
);
});
});
@@ -395,8 +370,8 @@ describe('IDE pipelines actions', () => {
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' });
});
- it('dispatches request', (done) => {
- testAction(
+ it('dispatches request', () => {
+ return testAction(
fetchJobLogs,
null,
mockedState,
@@ -405,7 +380,6 @@ describe('IDE pipelines actions', () => {
{ type: 'requestJobLogs' },
{ type: 'receiveJobLogsSuccess', payload: { html: 'html' } },
],
- done,
);
});
@@ -426,22 +400,21 @@ describe('IDE pipelines actions', () => {
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500);
});
- it('dispatches error', (done) => {
- testAction(
+ it('dispatches error', () => {
+ return testAction(
fetchJobLogs,
null,
mockedState,
[],
[{ type: 'requestJobLogs' }, { type: 'receiveJobLogsError' }],
- done,
);
});
});
});
describe('resetLatestPipeline', () => {
- it('commits reset mutations', (done) => {
- testAction(
+ it('commits reset mutations', () => {
+ return testAction(
resetLatestPipeline,
null,
mockedState,
@@ -450,7 +423,6 @@ describe('IDE pipelines actions', () => {
{ type: types.SET_DETAIL_JOB, payload: null },
],
[],
- done,
);
});
});