diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-08-27 10:43:04 +0200 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-08-27 10:43:04 +0200 |
commit | 89aefc28d722700eebe0f93625cb490d3e1c9387 (patch) | |
tree | 04081c013e6026fee27b424ce14a255c3ce65add | |
parent | e505ea18c48724025645df76509524d298984598 (diff) | |
download | gitlab-ce-50101-vuex-store.tar.gz |
Adds specs for actions50101-vuex-store
-rw-r--r-- | app/assets/javascripts/jobs/store/actions.js | 8 | ||||
-rw-r--r-- | spec/javascripts/jobs/store/actions_spec.js | 494 |
2 files changed, 443 insertions, 59 deletions
diff --git a/app/assets/javascripts/jobs/store/actions.js b/app/assets/javascripts/jobs/store/actions.js index 9f62d3f52fa..a0845bb803c 100644 --- a/app/assets/javascripts/jobs/store/actions.js +++ b/app/assets/javascripts/jobs/store/actions.js @@ -38,7 +38,7 @@ export const fetchJob = ({ state, dispatch }) => { return axios.get(endpoint); }, }, - data: state.endpoint, + data: state.jobEndpoint, method: 'getJob', successCallback: ({ data }) => dispatch('receiveJobSuccess', data), errorCallback: () => dispatch('receiveJobError'), @@ -48,7 +48,7 @@ export const fetchJob = ({ state, dispatch }) => { eTagPoll.makeRequest(); } else { axios - .get(state.endpoint) + .get(state.jobEndpoint) .then(({ data }) => dispatch('receiveJobSuccess', data)) .catch(() => dispatch('receiveJobError')); } @@ -155,12 +155,12 @@ export const requestJobsForStage = ({ commit }) => commit(types.REQUEST_JOBS_FOR export const setSelectedStage = ({ commit }, stage) => commit(types.SET_SELECTED_STAGE, stage); // On stage click, set selected stage + fetch job -export const fetchJobsForStage = ({ dispatch }, stage) => { +export const fetchJobsForStage = ({ state, dispatch }, stage) => { dispatch('setSelectedStage', stage); dispatch('requestJobsForStage'); axios - .get() + .get(state.stageJobsEndpoint) .then(({ data }) => dispatch('receiveJobsForStageSuccess', data)) .catch(() => dispatch('receiveJobsForStageError')); }; diff --git a/spec/javascripts/jobs/store/actions_spec.js b/spec/javascripts/jobs/store/actions_spec.js index 7768644c797..248739146de 100644 --- a/spec/javascripts/jobs/store/actions_spec.js +++ b/spec/javascripts/jobs/store/actions_spec.js @@ -45,7 +45,7 @@ describe('Job State actions', () => { }); describe('setJobEndpoint', () => { - it('should commit SET_JOB_ENDPOINT mutation', (done) => { + it('should commit SET_JOB_ENDPOINT mutation', done => { testAction( setJobEndpoint, 'job/872324.json', @@ -58,7 +58,7 @@ describe('Job State actions', () => { }); describe('setTraceEndpoint', () => { - it('should commit SET_TRACE_ENDPOINT mutation', (done) => { + it('should commit SET_TRACE_ENDPOINT mutation', done => { testAction( setTraceEndpoint, 'job/872324/trace.json', @@ -71,7 +71,7 @@ describe('Job State actions', () => { }); describe('setStagesEndpoint', () => { - it('should commit SET_STAGES_ENDPOINT mutation', (done) => { + it('should commit SET_STAGES_ENDPOINT mutation', done => { testAction( setStagesEndpoint, 'job/872324/stages.json', @@ -84,7 +84,7 @@ describe('Job State actions', () => { }); describe('setJobsEndpoint', () => { - it('should commit SET_JOBS_ENDPOINT mutation', (done) => { + it('should commit SET_JOBS_ENDPOINT mutation', done => { testAction( setJobsEndpoint, 'job/872324/stages/build.json', @@ -97,24 +97,75 @@ describe('Job State actions', () => { }); describe('requestJob', () => { - it('should commit REQUEST_JOB mutation', (done) => { - testAction( - requestJob, - null, - mockedState, - [{ type: types.REQUEST_JOB }], - [], - done, - ); + it('should commit REQUEST_JOB mutation', done => { + testAction(requestJob, null, mockedState, [{ type: types.REQUEST_JOB }], [], done); }); }); describe('fetchJob', () => { + let mock; + + beforeEach(() => { + mockedState.jobEndpoint = `${TEST_HOST}/endpoint.json`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + stopPolling(); + clearEtagPoll(); + }); + + describe('success', () => { + it('dispatches requestJob and receiveJobSuccess ', done => { + mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, { id: 121212, name: 'karma' }); + + testAction( + fetchJob, + null, + mockedState, + [], + [ + { + type: 'requestJob', + }, + { + payload: { data: { id: 121212, name: 'karma' }, status: 200 }, + type: 'receiveJobSuccess', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + beforeEach(() => { + mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); + }); + it('dispatches requestJob and receiveJobError ', done => { + testAction( + fetchJob, + null, + mockedState, + [], + [ + { + type: 'requestJob', + }, + { + type: 'receiveJobError', + }, + ], + done, + ); + }); + }); }); describe('receiveJobSuccess', () => { - it('should commit RECEIVE_JOB_SUCCESS mutation', (done) => { + it('should commit RECEIVE_JOB_SUCCESS mutation', done => { testAction( receiveJobSuccess, { id: 121232132 }, @@ -127,117 +178,450 @@ describe('Job State actions', () => { }); describe('receiveJobError', () => { - it('should commit RECEIVE_JOB_ERROR mutation', (done) => { + it('should commit RECEIVE_JOB_ERROR mutation', done => { + testAction(receiveJobError, null, mockedState, [{ type: types.RECEIVE_JOB_ERROR }], [], done); + }); + }); + + describe('scrollTop', () => { + it('should commit SCROLL_TO_TOP mutation', done => { + testAction(scrollTop, null, mockedState, [{ type: types.SCROLL_TO_TOP }], [], done); + }); + }); + + describe('scrollBottom', () => { + it('should commit SCROLL_TO_BOTTOM mutation', done => { + testAction(scrollBottom, null, mockedState, [{ type: types.SCROLL_TO_BOTTOM }], [], done); + }); + }); + + describe('requestTrace', () => { + it('should commit REQUEST_TRACE mutation', done => { + testAction(requestTrace, null, mockedState, [{ type: types.REQUEST_TRACE }], [], done); + }); + }); + + describe('fetchTrace', () => { + let mock; + + beforeEach(() => { + mockedState.traceEndpoint = `${TEST_HOST}/endpoint`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + stopPolling(); + clearEtagPoll(); + }); + + describe('success', () => { + it('dispatches requestTrace, fetchFavicon, receiveTraceSuccess and stopPollingTrace when job is complete', done => { + mock + .onGet(`${TEST_HOST}/endpoint/trace.json`) + .replyOnce(200, { + html: 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- :', + complete: true, + }); + + testAction( + fetchTrace, + null, + mockedState, + [], + [ + { + type: 'requestTrace', + }, + { + type: 'fetchFavicon', + }, + { + payload: { + data: { html: 'I, [2018-08-17T22:57:45.707325 #1841] INFO -- :', complete: true }, + status: 200, + }, + type: 'receiveTraceSuccess', + }, + { + type: 'stopPollingTrace', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + beforeEach(() => { + mock.onGet(`${TEST_HOST}/endpoint/trace.json`).reply(500); + }); + + it('dispatches requestTrace and receiveTraceError ', done => { + testAction( + fetchTrace, + null, + mockedState, + [], + [ + { + type: 'requestTrace', + }, + { + type: 'receiveTraceError', + }, + ], + done, + ); + }); + }); + }); + + describe('stopPollingTrace', () => { + it('should commit STOP_POLLING_TRACE mutation ', done => { testAction( - receiveJobError, + stopPollingTrace, null, mockedState, - [{ type: types.RECEIVE_JOB_ERROR }], + [{ type: types.STOP_POLLING_TRACE }], [], done, ); }); }); - describe('scrollTop', () => { - it('should commit SCROLL_TO_TOP mutation', (done) => { + describe('receiveTraceSuccess', () => { + it('should commit RECEIVE_TRACE_SUCCESS mutation ', done => { testAction( - scrollTop, - null, + receiveTraceSuccess, + 'hello world', mockedState, - [{ type: types.SCROLL_TO_TOP }], + [{ type: types.RECEIVE_TRACE_SUCCESS, payload: 'hello world' }], [], done, ); }); }); - describe('scrollBottom', () => { - it('should commit SCROLL_TO_BOTTOM mutation', (done) => { + describe('receiveTraceError', () => { + it('should commit RECEIVE_TRACE_ERROR mutation ', done => { testAction( - scrollBottom, + receiveTraceError, null, mockedState, - [{ type: types.SCROLL_TO_BOTTOM }], + [{ type: types.RECEIVE_TRACE_ERROR }], [], done, ); }); }); - describe('requestTrace', () => { - it('should commit REQUEST_TRACE mutation', (done) => { + describe('fetchFavicon', () => { + let mock; + + beforeEach(() => { + mockedState.pagePath = `${TEST_HOST}/endpoint`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('success', () => { + it('dispatches requestStatusFavicon and receiveStatusFaviconSuccess ', done => { + mock.onGet(`${TEST_HOST}/endpoint/status.json`).replyOnce(200); + + testAction( + fetchFavicon, + null, + mockedState, + [], + [ + { + type: 'requestStatusFavicon', + }, + { + type: 'receiveStatusFaviconSuccess', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + beforeEach(() => { + mock.onGet(`${TEST_HOST}/endpoint/status.json`).reply(500); + }); + + it('dispatches requestStatusFavicon and requestStatusFaviconError ', done => { + testAction( + fetchFavicon, + null, + mockedState, + [], + [ + { + type: 'requestStatusFavicon', + }, + { + type: 'requestStatusFaviconError', + }, + ], + done, + ); + }); + }); + }); + + describe('requestStatusFavicon', () => { + it('should commit REQUEST_STATUS_FAVICON mutation ', done => { testAction( - requestTrace, + requestStatusFavicon, null, mockedState, - [{ type: types.REQUEST_TRACE }], + [{ type: types.REQUEST_STATUS_FAVICON }], [], done, ); }); }); - describe('fetchTrace', () => {}); + describe('receiveStatusFaviconSuccess', () => { + it('should commit RECEIVE_STATUS_FAVICON_SUCCESS mutation ', done => { + testAction( + receiveStatusFaviconSuccess, + null, + mockedState, + [{ type: types.RECEIVE_STATUS_FAVICON_SUCCESS }], + [], + done, + ); + }); + }); - describe('stopPollingTrace', () => { - it('should commit STOP_POLLING_TRACE mutation ', (done) => { + describe('requestStatusFaviconError', () => { + it('should commit RECEIVE_STATUS_FAVICON_ERROR mutation ', done => { testAction( - stopPollingTrace, + requestStatusFaviconError, null, mockedState, - [{ type: types.STOP_POLLING_TRACE }], + [{ type: types.RECEIVE_STATUS_FAVICON_ERROR }], [], done, ); }); }); - describe('receiveTraceSuccess', () => { - it('should commit RECEIVE_TRACE_SUCCESS mutation ', (done) => { + describe('requestStages', () => { + it('should commit REQUEST_STAGES mutation ', done => { + testAction(requestStages, null, mockedState, [{ type: types.REQUEST_STAGES }], [], done); + }); + }); + + describe('fetchStages', () => { + let mock; + + beforeEach(() => { + mockedState.stagesEndpoint = `${TEST_HOST}/endpoint.json`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('success', () => { + it('dispatches requestStages and receiveStagesSuccess ', done => { + mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, [{ id: 121212, name: 'build' }]); + + testAction( + fetchStages, + null, + mockedState, + [], + [ + { + type: 'requestStages', + }, + { + payload: { data: [{ id: 121212, name: 'build' }], status: 200 }, + type: 'receiveStagesSuccess', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + beforeEach(() => { + mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); + }); + + it('dispatches requestStages and receiveStagesError ', done => { + testAction( + fetchStages, + null, + mockedState, + [], + [ + { + type: 'requestStages', + }, + { + type: 'receiveStagesError', + }, + ], + done, + ); + }); + }); + }); + + describe('receiveStagesSuccess', () => { + it('should commit RECEIVE_STAGES_SUCCESS mutation ', done => { testAction( - receiveTraceSuccess, - 'hello world', + receiveStagesSuccess, + null, mockedState, - [{ type: types.RECEIVE_TRACE_SUCCESS, payload: 'hello world' }], + [{ type: types.RECEIVE_STAGES_SUCCESS }], [], done, ); }); }); - describe('receiveTraceError', () => { - it('should commit RECEIVE_TRACE_ERROR mutation ', (done) => { + describe('receiveStagesError', () => { + it('should commit RECEIVE_STAGES_ERROR mutation ', done => { testAction( - receiveTraceError, + receiveStagesError, null, mockedState, - [{ type: types.RECEIVE_TRACE_ERROR }], + [{ type: types.RECEIVE_STAGES_ERROR }], [], done, ); }); }); - describe('fetchFavicon', () => {}); + describe('requestJobsForStage', () => { + it('should commit REQUEST_JOBS_FOR_STAGE mutation ', done => { + testAction( + requestJobsForStage, + null, + mockedState, + [{ type: types.REQUEST_JOBS_FOR_STAGE }], + [], + done, + ); + }); + }); - describe('requestStatusFavicon', () => {}); + describe('setSelectedStage', () => { + it('should commit SET_SELECTED_STAGE mutation ', done => { + testAction( + setSelectedStage, + { name: 'build' }, + mockedState, + [{ type: types.SET_SELECTED_STAGE, paylod: { name: 'build' } }], + [], + done, + ); + }); + }); - describe('receiveStatusFaviconSuccess', () => {}); + describe('fetchJobsForStage', () => { + let mock; - describe('requestStatusFaviconError', () => {}); + beforeEach(() => { + mockedState.stageJobsEndpoint = `${TEST_HOST}/endpoint.json`; + mock = new MockAdapter(axios); + }); - describe('requestStages', () => {}); + afterEach(() => { + mock.restore(); + }); - describe('fetchStages', () => {}); + describe('success', () => { + it('dispatches setSelectedStage, requestJobsForStage and receiveJobsForStageSuccess ', done => { + mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, [{ id: 121212, name: 'build' }]); - describe('requestJobsForStage', () => {}); + testAction( + fetchJobsForStage, + null, + mockedState, + [], + [ + { + type: 'setSelectedStage', + payload: null, + }, + { + type: 'requestJobsForStage', + }, + { + payload: { data: [{ id: 121212, name: 'build' }], status: 200 }, + type: 'receiveJobsForStageSuccess', + }, + ], + done, + ); + }); + }); - describe('setSelectedStage', () => {}); + describe('error', () => { + beforeEach(() => { + mock.onGet(`${TEST_HOST}/endpoint.json`).reply(500); + }); - describe('fetchJobsForStage', () => {}); + it('dispatches setSelectedStage, requestJobsForStage and receiveJobsForStageError', done => { + testAction( + fetchJobsForStage, + null, + mockedState, + [], + [ + { + type: 'setSelectedStage', + }, + { + type: 'requestJobsForStage', + }, + { + type: 'receiveJobsForStageError', + }, + ], + done, + ); + }); + }); + }); - describe('receiveJobsForStageSuccess', () => {}); + describe('receiveJobsForStageSuccess', () => { + it('should commit RECEIVE_JOBS_FOR_STAGE_SUCCESS mutation ', done => { + testAction( + receiveJobsForStageSuccess, + [{ id: 121212, name: 'karma' }], + mockedState, + [{ type: types.RECEIVE_JOBS_FOR_STAGE_SUCCESS }], + [], + done, + ); + }); + }); - describe('receiveJobsForStageError', () => {}); + describe('receiveJobsForStageError', () => { + it('should commit RECEIVE_JOBS_FOR_STAGE_ERROR mutation ', done => { + testAction( + receiveJobsForStageError, + null, + mockedState, + [{ type: types.RECEIVE_JOBS_FOR_STAGE_ERROR }], + [], + done, + ); + }); + }); }); |