Commit 8b1c43bd authored by Phil Hughes's avatar Phil Hughes

spec fixes

parent 1e48b7ee
...@@ -149,7 +149,9 @@ export default { ...@@ -149,7 +149,9 @@ export default {
}); });
}, },
[types.SET_RIGHT_PANE](state, view) { [types.SET_RIGHT_PANE](state, view) {
state.rightPane = state.rightPane === view ? null : view; Object.assign(state, {
rightPane: state.rightPane === view ? null : view,
});
}, },
...projectMutations, ...projectMutations,
...mergeRequestMutation, ...mergeRequestMutation,
......
...@@ -27,7 +27,9 @@ export default { ...@@ -27,7 +27,9 @@ export default {
this.isTab = true; this.isTab = true;
}, },
updated() { updated() {
if (this.$parent) {
this.$parent.$forceUpdate(); this.$parent.$forceUpdate();
}
}, },
}; };
</script> </script>
......
...@@ -29,6 +29,27 @@ export const pipelines = [ ...@@ -29,6 +29,27 @@ export const pipelines = [
}, },
]; ];
export const stages = [
{
dropdown_path: 'testing',
name: 'build',
status: {
icon: 'status_failed',
group: 'failed',
text: 'Failed',
},
},
{
dropdown_path: 'testing',
name: 'test',
status: {
icon: 'status_failed',
group: 'failed',
text: 'Failed',
},
},
];
export const jobs = [ export const jobs = [
{ {
id: 1, id: 1,
......
...@@ -5,15 +5,15 @@ import actions, { ...@@ -5,15 +5,15 @@ import actions, {
receiveLatestPipelineError, receiveLatestPipelineError,
receiveLatestPipelineSuccess, receiveLatestPipelineSuccess,
fetchLatestPipeline, fetchLatestPipeline,
requestJobs, requestStages,
receiveJobsError, receiveStagesError,
receiveJobsSuccess, receiveStagesSuccess,
fetchJobs, fetchStages,
} 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, jobs } from '../../../mock_data'; import { pipelines, stages } from '../../../mock_data';
describe('IDE pipelines actions', () => { describe('IDE pipelines actions', () => {
let mockedState; let mockedState;
...@@ -141,19 +141,19 @@ describe('IDE pipelines actions', () => { ...@@ -141,19 +141,19 @@ describe('IDE pipelines actions', () => {
}); });
}); });
describe('requestJobs', () => { describe('requestStages', () => {
it('commits request', done => { it('commits request', done => {
testAction(requestJobs, null, mockedState, [{ type: types.REQUEST_JOBS }], [], done); testAction(requestStages, null, mockedState, [{ type: types.REQUEST_STAGES }], [], done);
}); });
}); });
describe('receiveJobsError', () => { describe('receiveJobsError', () => {
it('commits error', done => { it('commits error', done => {
testAction( testAction(
receiveJobsError, receiveStagesError,
null, null,
mockedState, mockedState,
[{ type: types.RECEIVE_JOBS_ERROR }], [{ type: types.RECEIVE_STAGES_ERROR }],
[], [],
done, done,
); );
...@@ -162,80 +162,53 @@ describe('IDE pipelines actions', () => { ...@@ -162,80 +162,53 @@ describe('IDE pipelines actions', () => {
it('creates flash message', () => { it('creates flash message', () => {
const flashSpy = spyOnDependency(actions, 'flash'); const flashSpy = spyOnDependency(actions, 'flash');
receiveJobsError({ commit() {} }); receiveStagesError({ commit() {} });
expect(flashSpy).toHaveBeenCalled(); expect(flashSpy).toHaveBeenCalled();
}); });
}); });
describe('receiveJobsSuccess', () => { describe('receiveStagesSuccess', () => {
it('commits jobs', done => { it('commits jobs', done => {
testAction( testAction(
receiveJobsSuccess, receiveStagesSuccess,
jobs, stages,
mockedState, mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: jobs }], [{ type: types.RECEIVE_STAGES_SUCCESS, payload: stages }],
[], [],
done, done,
); );
}); });
}); });
describe('fetchJobs', () => { describe('fetchStages', () => {
let page = '';
beforeEach(() => { beforeEach(() => {
mockedState.latestPipeline = pipelines[0]; mockedState.latestPipeline = pipelines[0];
}); });
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(/\/api\/v4\/projects\/(.*)\/pipelines\/(.*)\/jobs/).replyOnce(() => [ mock.onGet(/\/(.*)\/pipelines\/(.*)\/builds.json/).replyOnce(200, stages);
200,
jobs,
{
'x-next-page': page,
},
]);
}); });
it('dispatches request', done => { it('dispatches request', done => {
testAction( testAction(
fetchJobs, fetchStages,
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestJobs' }, { type: 'receiveJobsSuccess' }], [{ type: 'requestStages' }, { type: 'receiveStagesSuccess' }],
done, done,
); );
}); });
it('dispatches success with latest pipeline', done => { it('dispatches success with latest pipeline', done => {
testAction( testAction(
fetchJobs, fetchStages,
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestJobs' }, { type: 'receiveJobsSuccess', payload: jobs }], [{ type: 'requestStages' }, { type: 'receiveStagesSuccess', payload: stages }],
done,
);
});
it('dispatches twice for both pages', done => {
page = '2';
testAction(
fetchJobs,
null,
mockedState,
[],
[
{ type: 'requestJobs' },
{ type: 'receiveJobsSuccess', payload: jobs },
{ type: 'fetchJobs', payload: '2' },
{ type: 'requestJobs' },
{ type: 'receiveJobsSuccess', payload: jobs },
],
done, done,
); );
}); });
...@@ -243,44 +216,27 @@ describe('IDE pipelines actions', () => { ...@@ -243,44 +216,27 @@ describe('IDE pipelines actions', () => {
it('calls axios with correct URL', () => { it('calls axios with correct URL', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchJobs({ dispatch() {}, state: mockedState, rootState: mockedState }); fetchStages({ dispatch() {}, state: mockedState, rootState: mockedState });
expect(apiSpy).toHaveBeenCalledWith('/api/v4/projects/test%2Fproject/pipelines/1/jobs', { expect(apiSpy).toHaveBeenCalledWith(
params: { page: '1' }, '/test/project/pipelines/1/builds.json',
}); jasmine.anything(),
}); );
it('calls axios with page next page', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchJobs({ dispatch() {}, state: mockedState, rootState: mockedState });
expect(apiSpy).toHaveBeenCalledWith('/api/v4/projects/test%2Fproject/pipelines/1/jobs', {
params: { page: '1' },
});
page = '2';
fetchJobs({ dispatch() {}, state: mockedState, rootState: mockedState }, page);
expect(apiSpy).toHaveBeenCalledWith('/api/v4/projects/test%2Fproject/pipelines/1/jobs', {
params: { page: '2' },
});
}); });
}); });
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(/\/api\/v4\/projects\/(.*)\/pipelines(.*)/).replyOnce(500); mock.onGet(/\/(.*)\/pipelines\/(.*)\/builds.json/).replyOnce(500);
}); });
it('dispatches error', done => { it('dispatches error', done => {
testAction( testAction(
fetchJobs, fetchStages,
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestJobs' }, { type: 'receiveJobsError' }], [{ type: 'requestStages' }, { type: 'receiveStagesError' }],
done, done,
); );
}); });
......
...@@ -37,35 +37,4 @@ describe('IDE pipeline getters', () => { ...@@ -37,35 +37,4 @@ describe('IDE pipeline getters', () => {
expect(getters.hasLatestPipeline(mockedState)).toBe(true); expect(getters.hasLatestPipeline(mockedState)).toBe(true);
}); });
}); });
describe('failedJobs', () => {
it('returns array of failed jobs', () => {
mockedState.stages = [
{
title: 'test',
jobs: [{ id: 1, status: 'failed' }, { id: 2, status: 'success' }],
},
{
title: 'build',
jobs: [{ id: 3, status: 'failed' }, { id: 4, status: 'failed' }],
},
];
expect(getters.failedJobs(mockedState).length).toBe(3);
expect(getters.failedJobs(mockedState)).toEqual([
{
id: 1,
status: jasmine.anything(),
},
{
id: 3,
status: jasmine.anything(),
},
{
id: 4,
status: jasmine.anything(),
},
]);
});
});
}); });
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 { pipelines, jobs } from '../../../mock_data'; import { pipelines, stages } from '../../../mock_data';
describe('IDE pipelines mutations', () => { describe('IDE pipelines mutations', () => {
let mockedState; let mockedState;
...@@ -49,70 +49,47 @@ describe('IDE pipelines mutations', () => { ...@@ -49,70 +49,47 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.REQUEST_JOBS, () => { describe(types.REQUEST_STAGES, () => {
it('sets jobs loading to true', () => { it('sets stages loading to true', () => {
mutations[types.REQUEST_JOBS](mockedState); mutations[types.REQUEST_STAGES](mockedState);
expect(mockedState.isLoadingJobs).toBe(true); expect(mockedState.isLoadingJobs).toBe(true);
}); });
}); });
describe(types.RECEIVE_JOBS_ERROR, () => { describe(types.RECEIVE_STAGES_ERROR, () => {
it('sets jobs loading to false', () => { it('sets jobs loading to false', () => {
mutations[types.RECEIVE_JOBS_ERROR](mockedState); mutations[types.RECEIVE_STAGES_ERROR](mockedState);
expect(mockedState.isLoadingJobs).toBe(false); expect(mockedState.isLoadingJobs).toBe(false);
}); });
}); });
describe(types.RECEIVE_JOBS_SUCCESS, () => { describe(types.RECEIVE_STAGES_SUCCESS, () => {
it('sets jobs loading to false on success', () => { it('sets jobs loading to false on success', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, jobs); mutations[types.RECEIVE_STAGES_SUCCESS](mockedState, stages);
expect(mockedState.isLoadingJobs).toBe(false); expect(mockedState.isLoadingJobs).toBe(false);
}); });
it('sets stages', () => { it('sets stages', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, jobs); mutations[types.RECEIVE_STAGES_SUCCESS](mockedState, stages);
expect(mockedState.stages.length).toBe(2); expect(mockedState.stages.length).toBe(2);
expect(mockedState.stages).toEqual([ expect(mockedState.stages).toEqual([
{ {
title: 'test', ...stages[0],
jobs: jasmine.anything(), id: 0,
isCollapsed: false,
isLoading: false,
jobs: [],
}, },
{ {
title: 'build', ...stages[1],
jobs: jasmine.anything(), id: 1,
}, isCollapsed: false,
]); isLoading: false,
}); jobs: [],
it('sets jobs in stages', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, jobs);
expect(mockedState.stages[0].jobs.length).toBe(3);
expect(mockedState.stages[1].jobs.length).toBe(1);
expect(mockedState.stages).toEqual([
{
title: jasmine.anything(),
jobs: jobs.filter(job => job.stage === 'test').map(job => ({
id: job.id,
name: job.name,
status: job.status,
stage: job.stage,
duration: job.duration,
})),
},
{
title: jasmine.anything(),
jobs: jobs.filter(job => job.stage === 'build').map(job => ({
id: job.id,
name: job.name,
status: job.status,
stage: job.stage,
duration: job.duration,
})),
}, },
]); ]);
}); });
......
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