diff options
author | Phil Hughes <me@iamphill.com> | 2018-05-24 15:07:09 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-05-24 15:07:09 +0100 |
commit | 8b1c43bde36c902d138b06dfb91ffab4bc1eb8ad (patch) | |
tree | fea870c265a48e4bbda0d330718e4499473c08da /spec | |
parent | 1e48b7eec0499e44eb1dcd32393005f709b5c816 (diff) | |
download | gitlab-ce-8b1c43bde36c902d138b06dfb91ffab4bc1eb8ad.tar.gz |
spec fixes
Diffstat (limited to 'spec')
4 files changed, 68 insertions, 145 deletions
diff --git a/spec/javascripts/ide/mock_data.js b/spec/javascripts/ide/mock_data.js index 7e641c7984b..a0cb8bae91c 100644 --- a/spec/javascripts/ide/mock_data.js +++ b/spec/javascripts/ide/mock_data.js @@ -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, diff --git a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js index 85fbcf8084b..bcf9d9e1513 100644 --- a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js +++ b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js @@ -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, ); }); diff --git a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js index b2a7e8a9025..4514896b5ea 100644 --- a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js +++ b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js @@ -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(), - }, - ]); - }); - }); }); diff --git a/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js b/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js index 8262e916243..d47ec33ad4d 100644 --- a/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js +++ b/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js @@ -1,7 +1,7 @@ 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: [], }, ]); }); |