diff options
author | Phil Hughes <me@iamphill.com> | 2018-05-14 10:33:48 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-05-22 11:11:35 +0100 |
commit | 50985f54baf9a4d7e840e22ce8914f0bc919f5d8 (patch) | |
tree | 1572fd8a9defa0e9ea01991e242286eaf83c0641 | |
parent | 21f861953958cece97df1ed2814e14bd67e1ddbe (diff) | |
download | gitlab-ce-50985f54baf9a4d7e840e22ce8914f0bc919f5d8.tar.gz |
added getter for checking is their is a pipeline
6 files changed, 59 insertions, 8 deletions
diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/actions.js b/app/assets/javascripts/ide/stores/modules/pipelines/actions.js index a412983c650..146a0e72354 100644 --- a/app/assets/javascripts/ide/stores/modules/pipelines/actions.js +++ b/app/assets/javascripts/ide/stores/modules/pipelines/actions.js @@ -16,9 +16,7 @@ export const fetchLatestPipeline = ({ dispatch, rootState }, sha) => { return Api.pipelines(rootState.currentProjectId, { sha, per_page: '1' }) .then(({ data }) => { - if (data.length) { - dispatch('receiveLatestPipelineSuccess', data.pop()); - } + dispatch('receiveLatestPipelineSuccess', data.pop()); }) .catch(() => dispatch('receiveLatestPipelineError')); }; diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/getters.js b/app/assets/javascripts/ide/stores/modules/pipelines/getters.js new file mode 100644 index 00000000000..8344bb1b34e --- /dev/null +++ b/app/assets/javascripts/ide/stores/modules/pipelines/getters.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export const hasLatestPipeline = state => !state.isLoadingPipeline && !!state.latestPipeline; diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/index.js b/app/assets/javascripts/ide/stores/modules/pipelines/index.js index 04e7e0f08f1..b44c3141b81 100644 --- a/app/assets/javascripts/ide/stores/modules/pipelines/index.js +++ b/app/assets/javascripts/ide/stores/modules/pipelines/index.js @@ -1,10 +1,12 @@ import state from './state'; import * as actions from './actions'; import mutations from './mutations'; +import * as getters from './getters'; export default { namespaced: true, state: state(), actions, mutations, + getters, }; diff --git a/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js b/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js index 60aa9b7bf32..382775de10a 100644 --- a/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js +++ b/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js @@ -10,10 +10,13 @@ export default { }, [types.RECEIVE_LASTEST_PIPELINE_SUCCESS](state, pipeline) { state.isLoadingPipeline = false; - state.latestPipeline = { - id: pipeline.id, - status: pipeline.status, - }; + + if (pipeline) { + state.latestPipeline = { + id: pipeline.id, + status: pipeline.status, + }; + } }, [types.REQUEST_JOBS](state) { state.isLoadingJobs = true; diff --git a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js new file mode 100644 index 00000000000..4514896b5ea --- /dev/null +++ b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js @@ -0,0 +1,40 @@ +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); + }); + }); +}); diff --git a/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js b/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js index d9429cb8e8b..59e218ef0a6 100644 --- a/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js +++ b/spec/javascripts/ide/stores/modules/pipelines/mutations_spec.js @@ -7,7 +7,7 @@ describe('IDE pipelines mutations', () => { let mockedState; beforeEach(() => { - mockedState = state; + mockedState = state(); }); describe(types.REQUEST_LATEST_PIPELINE, () => { @@ -41,6 +41,12 @@ describe('IDE pipelines mutations', () => { 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, () => { |