summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-05-29 14:59:52 +0100
committerPhil Hughes <me@iamphill.com>2018-05-29 14:59:52 +0100
commit552c0c99bb8216d137d4c0cd295d28a800a63502 (patch)
tree65b30ebfde0f23e9215a3b0280a59b0978f60a8c /spec/javascripts
parentc8f3a60d8a392eb2701ce2a40bac4903e361c915 (diff)
downloadgitlab-ce-552c0c99bb8216d137d4c0cd295d28a800a63502.tar.gz
more store tests
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/ide/stores/modules/pipelines/actions_spec.js107
-rw-r--r--spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js89
2 files changed, 194 insertions, 2 deletions
diff --git a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js
index ee8cae9c199..f26eaf9c81f 100644
--- a/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js
+++ b/spec/javascripts/ide/stores/modules/pipelines/actions_spec.js
@@ -8,11 +8,16 @@ import actions, {
fetchLatestPipeline,
stopPipelinePolling,
clearEtagPoll,
+ requestJobs,
+ receiveJobsError,
+ receiveJobsSuccess,
+ fetchJobs,
+ toggleStageCollapsed,
} 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 } from '../../../mock_data';
+import { pipelines, jobs } from '../../../mock_data';
describe('IDE pipelines actions', () => {
let mockedState;
@@ -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,
+ );
+ });
+ });
});
diff --git a/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js b/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js
index c43d2249af5..1bd7bde7c4d 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 { fullPipelinesResponse, stages } from '../../../mock_data';
+import { fullPipelinesResponse, stages, jobs } from '../../../mock_data';
describe('IDE pipelines mutations', () => {
let mockedState;
@@ -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);
+ });
+ });
});