Commit 50985f54 authored by Phil Hughes's avatar Phil Hughes

added getter for checking is their is a pipeline

parent 21f86195
...@@ -16,9 +16,7 @@ export const fetchLatestPipeline = ({ dispatch, rootState }, sha) => { ...@@ -16,9 +16,7 @@ export const fetchLatestPipeline = ({ dispatch, rootState }, sha) => {
return Api.pipelines(rootState.currentProjectId, { sha, per_page: '1' }) return Api.pipelines(rootState.currentProjectId, { sha, per_page: '1' })
.then(({ data }) => { .then(({ data }) => {
if (data.length) {
dispatch('receiveLatestPipelineSuccess', data.pop()); dispatch('receiveLatestPipelineSuccess', data.pop());
}
}) })
.catch(() => dispatch('receiveLatestPipelineError')); .catch(() => dispatch('receiveLatestPipelineError'));
}; };
......
// eslint-disable-next-line import/prefer-default-export
export const hasLatestPipeline = state => !state.isLoadingPipeline && !!state.latestPipeline;
import state from './state'; import state from './state';
import * as actions from './actions'; import * as actions from './actions';
import mutations from './mutations'; import mutations from './mutations';
import * as getters from './getters';
export default { export default {
namespaced: true, namespaced: true,
state: state(), state: state(),
actions, actions,
mutations, mutations,
getters,
}; };
...@@ -10,10 +10,13 @@ export default { ...@@ -10,10 +10,13 @@ export default {
}, },
[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](state, pipeline) { [types.RECEIVE_LASTEST_PIPELINE_SUCCESS](state, pipeline) {
state.isLoadingPipeline = false; state.isLoadingPipeline = false;
if (pipeline) {
state.latestPipeline = { state.latestPipeline = {
id: pipeline.id, id: pipeline.id,
status: pipeline.status, status: pipeline.status,
}; };
}
}, },
[types.REQUEST_JOBS](state) { [types.REQUEST_JOBS](state) {
state.isLoadingJobs = true; state.isLoadingJobs = true;
......
import * as getters from '~/ide/stores/modules/pipelines/getters';
import state from '~/ide/stores/modules/pipelines/state';
describe('IDE pipeline getters', () => {
let mockedState;
beforeEach(() => {
mockedState = state();
});
describe('hasLatestPipeline', () => {
it('returns false when loading is true', () => {
mockedState.isLoadingPipeline = true;
expect(getters.hasLatestPipeline(mockedState)).toBe(false);
});
it('returns false when pipelines is null', () => {
mockedState.latestPipeline = null;
expect(getters.hasLatestPipeline(mockedState)).toBe(false);
});
it('returns false when loading is true & pipelines is null', () => {
mockedState.latestPipeline = null;
mockedState.isLoadingPipeline = true;
expect(getters.hasLatestPipeline(mockedState)).toBe(false);
});
it('returns true when loading is false & pipelines is an object', () => {
mockedState.latestPipeline = {
id: 1,
};
mockedState.isLoadingPipeline = false;
expect(getters.hasLatestPipeline(mockedState)).toBe(true);
});
});
});
...@@ -7,7 +7,7 @@ describe('IDE pipelines mutations', () => { ...@@ -7,7 +7,7 @@ describe('IDE pipelines mutations', () => {
let mockedState; let mockedState;
beforeEach(() => { beforeEach(() => {
mockedState = state; mockedState = state();
}); });
describe(types.REQUEST_LATEST_PIPELINE, () => { describe(types.REQUEST_LATEST_PIPELINE, () => {
...@@ -41,6 +41,12 @@ describe('IDE pipelines mutations', () => { ...@@ -41,6 +41,12 @@ describe('IDE pipelines mutations', () => {
status: pipelines[0].status, status: pipelines[0].status,
}); });
}); });
it('does not set latest pipeline if pipeline is null', () => {
mutations[types.RECEIVE_LASTEST_PIPELINE_SUCCESS](mockedState, null);
expect(mockedState.latestPipeline).toEqual(null);
});
}); });
describe(types.REQUEST_JOBS, () => { describe(types.REQUEST_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