store specs

This commit is contained in:
Phil Hughes 2018-06-01 14:44:22 +01:00
parent 8c3a2c5576
commit 2d6022e086
No known key found for this signature in database
GPG key ID: 32245528C52E0F9F
4 changed files with 189 additions and 1 deletions

View file

@ -99,7 +99,7 @@ export const fetchJobTrace = ({ dispatch, state }) => {
return axios
.get(`${state.detailJob.path}/trace`, { params: { format: 'json' } })
.then(({ data }) => dispatch('receiveJobTraceSuccess', data))
.catch(() => dispatch('requestJobTraceError'));
.catch(() => dispatch('receiveJobTraceError'));
};
export default () => {};

View file

@ -75,6 +75,7 @@ export const jobs = [
},
stage: 'test',
duration: 1,
started: new Date(),
},
{
id: 2,
@ -86,6 +87,7 @@ export const jobs = [
},
stage: 'test',
duration: 1,
started: new Date(),
},
{
id: 3,
@ -97,6 +99,7 @@ export const jobs = [
},
stage: 'test',
duration: 1,
started: new Date(),
},
{
id: 4,
@ -108,6 +111,7 @@ export const jobs = [
},
stage: 'build',
duration: 1,
started: new Date(),
},
];

View file

@ -13,9 +13,15 @@ import actions, {
receiveJobsSuccess,
fetchJobs,
toggleStageCollapsed,
setDetailJob,
requestJobTrace,
receiveJobTraceError,
receiveJobTraceSuccess,
fetchJobTrace,
} from '~/ide/stores/modules/pipelines/actions';
import state from '~/ide/stores/modules/pipelines/state';
import * as types from '~/ide/stores/modules/pipelines/mutation_types';
import { rightSidebarViews } from '~/ide/constants';
import testAction from '../../../../helpers/vuex_action_helper';
import { pipelines, jobs } from '../../../mock_data';
@ -281,4 +287,133 @@ describe('IDE pipelines actions', () => {
);
});
});
describe('setDetailJob', () => {
it('commits job', done => {
testAction(
setDetailJob,
'job',
mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }],
[{ type: 'setRightPane' }],
done,
);
});
it('dispatches setRightPane as pipeline when job is null', done => {
testAction(
setDetailJob,
null,
mockedState,
[{ type: types.SET_DETAIL_JOB }],
[{ type: 'setRightPane', payload: rightSidebarViews.pipelines }],
done,
);
});
it('dispatches setRightPane as job', done => {
testAction(
setDetailJob,
'job',
mockedState,
[{ type: types.SET_DETAIL_JOB }],
[{ type: 'setRightPane', payload: rightSidebarViews.jobsDetail }],
done,
);
});
});
describe('requestJobTrace', () => {
it('commits request', done => {
testAction(requestJobTrace, null, mockedState, [{ type: types.REQUEST_JOB_TRACE }], [], done);
});
});
describe('receiveJobTraceError', () => {
it('commits error', done => {
testAction(
receiveJobTraceError,
null,
mockedState,
[{ type: types.RECEIVE_JOB_TRACE_ERROR }],
[],
done,
);
});
it('creates flash message', () => {
const flashSpy = spyOnDependency(actions, 'flash');
receiveJobTraceError({ commit() {} });
expect(flashSpy).toHaveBeenCalled();
});
});
describe('receiveJobTraceSuccess', () => {
it('commits data', done => {
testAction(
receiveJobTraceSuccess,
'data',
mockedState,
[{ type: types.RECEIVE_JOB_TRACE_SUCCESS, payload: 'data' }],
[],
done,
);
});
});
describe('fetchJobTrace', () => {
beforeEach(() => {
mockedState.detailJob = {
path: `${gl.TEST_HOST}/project/builds`,
};
});
describe('success', () => {
beforeEach(() => {
spyOn(axios, 'get').and.callThrough();
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' });
});
it('dispatches request', done => {
testAction(
fetchJobTrace,
null,
mockedState,
[],
[
{ type: 'requestJobTrace' },
{ type: 'receiveJobTraceSuccess', payload: { html: 'html' } },
],
done,
);
});
it('sends get request to correct URL', () => {
fetchJobTrace({ state: mockedState, dispatch() {} });
expect(axios.get).toHaveBeenCalledWith(`${gl.TEST_HOST}/project/builds/trace`, {
params: { format: 'json' },
});
});
});
describe('error', () => {
beforeEach(() => {
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(500);
});
it('dispatches error', done => {
testAction(
fetchJobTrace,
null,
mockedState,
[],
[{ type: 'requestJobTrace' }, { type: 'receiveJobTraceError' }],
done,
);
});
});
});
});

View file

@ -147,6 +147,10 @@ describe('IDE pipelines mutations', () => {
name: job.name,
status: job.status,
path: job.build_path,
rawPath: `${job.build_path}/raw`,
started: job.started,
isLoading: false,
output: '',
})),
);
});
@ -171,4 +175,49 @@ describe('IDE pipelines mutations', () => {
expect(mockedState.stages[0].isCollapsed).toBe(false);
});
});
describe(types.SET_DETAIL_JOB, () => {
it('sets detail job', () => {
mutations[types.SET_DETAIL_JOB](mockedState, jobs[0]);
expect(mockedState.detailJob).toEqual(jobs[0]);
});
});
describe(types.REQUEST_JOB_TRACE, () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0] };
});
it('sets loading on detail job', () => {
mutations[types.REQUEST_JOB_TRACE](mockedState);
expect(mockedState.detailJob.isLoading).toBe(true);
});
});
describe(types.RECEIVE_JOB_TRACE_ERROR, () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
it('sets loading to false on detail job', () => {
mutations[types.RECEIVE_JOB_TRACE_ERROR](mockedState);
expect(mockedState.detailJob.isLoading).toBe(false);
});
});
describe(types.RECEIVE_JOB_TRACE_SUCCESS, () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
it('sets output on detail job', () => {
mutations[types.RECEIVE_JOB_TRACE_SUCCESS](mockedState, { html: 'html' });
expect(mockedState.detailJob.output).toBe('html');
expect(mockedState.detailJob.isLoading).toBe(false);
});
});
});