Commit 552c0c99 authored by Phil Hughes's avatar Phil Hughes

more store tests

parent c8f3a60d
...@@ -47,7 +47,7 @@ export default { ...@@ -47,7 +47,7 @@ export default {
[types.RECEIVE_JOBS_ERROR](state, id) { [types.RECEIVE_JOBS_ERROR](state, id) {
state.stages = state.stages.map(stage => state.stages = state.stages.map(stage =>
Object.assign(stage, { Object.assign(stage, {
isLoading: id === stage.id ? true : stage.isLoading, isLoading: id === stage.id ? false : stage.isLoading,
}), }),
); );
}, },
......
...@@ -8,11 +8,16 @@ import actions, { ...@@ -8,11 +8,16 @@ import actions, {
fetchLatestPipeline, fetchLatestPipeline,
stopPipelinePolling, stopPipelinePolling,
clearEtagPoll, clearEtagPoll,
requestJobs,
receiveJobsError,
receiveJobsSuccess,
fetchJobs,
toggleStageCollapsed,
} from '~/ide/stores/modules/pipelines/actions'; } from '~/ide/stores/modules/pipelines/actions';
import state from '~/ide/stores/modules/pipelines/state'; import state from '~/ide/stores/modules/pipelines/state';
import * as types from '~/ide/stores/modules/pipelines/mutation_types'; import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import testAction from '../../../../helpers/vuex_action_helper'; import testAction from '../../../../helpers/vuex_action_helper';
import { pipelines } from '../../../mock_data'; import { pipelines, jobs } from '../../../mock_data';
describe('IDE pipelines actions', () => { describe('IDE pipelines actions', () => {
let mockedState; let mockedState;
...@@ -176,4 +181,104 @@ describe('IDE pipelines actions', () => { ...@@ -176,4 +181,104 @@ describe('IDE pipelines actions', () => {
}); });
}); });
}); });
describe('requestJobs', () => {
it('commits request', done => {
testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done);
});
});
describe('receiveJobsError', () => {
it('commits error', done => {
testAction(
receiveJobsError,
1,
mockedState,
[{ type: types.RECEIVE_JOBS_ERROR, payload: 1 }],
[],
done,
);
});
it('creates flash message', () => {
const flashSpy = spyOnDependency(actions, 'flash');
receiveJobsError({ commit() {} }, 1);
expect(flashSpy).toHaveBeenCalled();
});
});
describe('receiveJobsSuccess', () => {
it('commits data', done => {
testAction(
receiveJobsSuccess,
{ id: 1, data: jobs },
mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }],
[],
done,
);
});
});
describe('fetchJobs', () => {
const stage = {
id: 1,
dropdownPath: `${gl.TEST_HOST}/jobs`,
};
describe('success', () => {
beforeEach(() => {
mock.onGet(stage.dropdownPath).replyOnce(200, jobs);
});
it('dispatches request', done => {
testAction(
fetchJobs,
stage,
mockedState,
[],
[
{ type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } },
],
done,
);
});
});
describe('error', () => {
beforeEach(() => {
mock.onGet(stage.dropdownPath).replyOnce(500);
});
it('dispatches error', done => {
testAction(
fetchJobs,
stage,
mockedState,
[],
[
{ type: 'requestJobs', payload: stage.id },
{ type: 'receiveJobsError', payload: stage.id },
],
done,
);
});
});
});
describe('toggleStageCollapsed', () => {
it('commits collapse', done => {
testAction(
toggleStageCollapsed,
1,
mockedState,
[{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }],
[],
done,
);
});
});
}); });
import mutations from '~/ide/stores/modules/pipelines/mutations'; import mutations from '~/ide/stores/modules/pipelines/mutations';
import state from '~/ide/stores/modules/pipelines/state'; import state from '~/ide/stores/modules/pipelines/state';
import * as types from '~/ide/stores/modules/pipelines/mutation_types'; import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import { fullPipelinesResponse, stages } from '../../../mock_data'; import { fullPipelinesResponse, stages, jobs } from '../../../mock_data';
describe('IDE pipelines mutations', () => { describe('IDE pipelines mutations', () => {
let mockedState; let mockedState;
...@@ -86,4 +86,91 @@ describe('IDE pipelines mutations', () => { ...@@ -86,4 +86,91 @@ describe('IDE pipelines mutations', () => {
]); ]);
}); });
}); });
describe(types.REQUEST_JOBS, () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
});
it('sets isLoading on stage', () => {
mutations[types.REQUEST_JOBS](mockedState, mockedState.stages[0].id);
expect(mockedState.stages[0].isLoading).toBe(true);
});
});
describe(types.RECEIVE_JOBS_ERROR, () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
});
it('sets isLoading on stage after error', () => {
mutations[types.RECEIVE_JOBS_ERROR](mockedState, mockedState.stages[0].id);
expect(mockedState.stages[0].isLoading).toBe(false);
});
});
describe(types.RECEIVE_JOBS_SUCCESS, () => {
let data;
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
data = {
latest_statuses: [...jobs],
};
});
it('updates loading', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
expect(mockedState.stages[0].isLoading).toBe(false);
});
it('sets jobs on stage', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
expect(mockedState.stages[0].jobs.length).toBe(jobs.length);
expect(mockedState.stages[0].jobs).toEqual(
jobs.map(job => ({
id: job.id,
name: job.name,
status: job.status,
path: job.build_path,
})),
);
});
});
describe(types.TOGGLE_STAGE_COLLAPSE, () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
isCollapsed: false,
}));
});
it('toggles collapsed state', () => {
const stage = mockedState.stages[0];
mutations[types.TOGGLE_STAGE_COLLAPSE](mockedState, stage.id);
expect(stage.isCollapsed).toBe(true);
mutations[types.TOGGLE_STAGE_COLLAPSE](mockedState, stage.id);
expect(stage.isCollapsed).toBe(false);
});
});
}); });
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