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

spec fixes

parent 1e48b7ee
......@@ -149,7 +149,9 @@ export default {
});
},
[types.SET_RIGHT_PANE](state, view) {
state.rightPane = state.rightPane === view ? null : view;
Object.assign(state, {
rightPane: state.rightPane === view ? null : view,
});
},
...projectMutations,
...mergeRequestMutation,
......
......@@ -27,7 +27,9 @@ export default {
this.isTab = true;
},
updated() {
this.$parent.$forceUpdate();
if (this.$parent) {
this.$parent.$forceUpdate();
}
},
};
</script>
......
......@@ -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 = [
{
id: 1,
......
......@@ -5,15 +5,15 @@ import actions, {
receiveLatestPipelineError,
receiveLatestPipelineSuccess,
fetchLatestPipeline,
requestJobs,
receiveJobsError,
receiveJobsSuccess,
fetchJobs,
requestStages,
receiveStagesError,
receiveStagesSuccess,
fetchStages,
} 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 testAction from '../../../../helpers/vuex_action_helper';
import { pipelines, jobs } from '../../../mock_data';
import { pipelines, stages } from '../../../mock_data';
describe('IDE pipelines actions', () => {
let mockedState;
......@@ -141,19 +141,19 @@ describe('IDE pipelines actions', () => {
});
});
describe('requestJobs', () => {
describe('requestStages', () => {
it('commits request', done => {
testAction(requestJobs, null, mockedState, [{ type: types.REQUEST_JOBS }], [], done);
testAction(requestStages, null, mockedState, [{ type: types.REQUEST_STAGES }], [], done);
});
});
describe('receiveJobsError', () => {
it('commits error', done => {
testAction(
receiveJobsError,
receiveStagesError,
null,
mockedState,
[{ type: types.RECEIVE_JOBS_ERROR }],
[{ type: types.RECEIVE_STAGES_ERROR }],
[],
done,
);
......@@ -162,80 +162,53 @@ describe('IDE pipelines actions', () => {
it('creates flash message', () => {
const flashSpy = spyOnDependency(actions, 'flash');
receiveJobsError({ commit() {} });
receiveStagesError({ commit() {} });
expect(flashSpy).toHaveBeenCalled();
});
});
describe('receiveJobsSuccess', () => {
describe('receiveStagesSuccess', () => {
it('commits jobs', done => {
testAction(
receiveJobsSuccess,
jobs,
receiveStagesSuccess,
stages,
mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: jobs }],
[{ type: types.RECEIVE_STAGES_SUCCESS, payload: stages }],
[],
done,
);
});
});
describe('fetchJobs', () => {
let page = '';
describe('fetchStages', () => {
beforeEach(() => {
mockedState.latestPipeline = pipelines[0];
});
describe('success', () => {
beforeEach(() => {
mock.onGet(/\/api\/v4\/projects\/(.*)\/pipelines\/(.*)\/jobs/).replyOnce(() => [
200,
jobs,
{
'x-next-page': page,
},
]);
mock.onGet(/\/(.*)\/pipelines\/(.*)\/builds.json/).replyOnce(200, stages);
});
it('dispatches request', done => {
testAction(
fetchJobs,
fetchStages,
null,
mockedState,
[],
[{ type: 'requestJobs' }, { type: 'receiveJobsSuccess' }],
[{ type: 'requestStages' }, { type: 'receiveStagesSuccess' }],
done,
);
});
it('dispatches success with latest pipeline', done => {
testAction(
fetchJobs,
fetchStages,
null,
mockedState,
[],
[{ type: 'requestJobs' }, { type: 'receiveJobsSuccess', payload: jobs }],
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 },
],
[{ type: 'requestStages' }, { type: 'receiveStagesSuccess', payload: stages }],
done,
);
});
......@@ -243,44 +216,27 @@ describe('IDE pipelines actions', () => {
it('calls axios with correct URL', () => {
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', {
params: { page: '1' },
});
});
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' },
});
expect(apiSpy).toHaveBeenCalledWith(
'/test/project/pipelines/1/builds.json',
jasmine.anything(),
);
});
});
describe('error', () => {
beforeEach(() => {
mock.onGet(/\/api\/v4\/projects\/(.*)\/pipelines(.*)/).replyOnce(500);
mock.onGet(/\/(.*)\/pipelines\/(.*)\/builds.json/).replyOnce(500);
});
it('dispatches error', done => {
testAction(
fetchJobs,
fetchStages,
null,
mockedState,
[],
[{ type: 'requestJobs' }, { type: 'receiveJobsError' }],
[{ type: 'requestStages' }, { type: 'receiveStagesError' }],
done,
);
});
......
......@@ -37,35 +37,4 @@ describe('IDE pipeline getters', () => {
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 state from '~/ide/stores/modules/pipelines/state';
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', () => {
let mockedState;
......@@ -49,70 +49,47 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.REQUEST_JOBS, () => {
it('sets jobs loading to true', () => {
mutations[types.REQUEST_JOBS](mockedState);
describe(types.REQUEST_STAGES, () => {
it('sets stages loading to true', () => {
mutations[types.REQUEST_STAGES](mockedState);
expect(mockedState.isLoadingJobs).toBe(true);
});
});
describe(types.RECEIVE_JOBS_ERROR, () => {
describe(types.RECEIVE_STAGES_ERROR, () => {
it('sets jobs loading to false', () => {
mutations[types.RECEIVE_JOBS_ERROR](mockedState);
mutations[types.RECEIVE_STAGES_ERROR](mockedState);
expect(mockedState.isLoadingJobs).toBe(false);
});
});
describe(types.RECEIVE_JOBS_SUCCESS, () => {
describe(types.RECEIVE_STAGES_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);
});
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).toEqual([
{
title: 'test',
jobs: jasmine.anything(),
...stages[0],
id: 0,
isCollapsed: false,
isLoading: false,
jobs: [],
},
{
title: 'build',
jobs: jasmine.anything(),
},
]);
});
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,
})),
...stages[1],
id: 1,
isCollapsed: false,
isLoading: false,
jobs: [],
},
]);
});
......
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