Commit eb64cbd8 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'vs-refactor-pipelines-list-spec' into 'master'

Refactor pipelines list spec for Vuex upgrade

See merge request gitlab-org/gitlab!40707
parents c7ce3789 5b8e339e
...@@ -22,11 +22,11 @@ describe('IDE pipelines list', () => { ...@@ -22,11 +22,11 @@ describe('IDE pipelines list', () => {
const defaultState = { const defaultState = {
links: { ciHelpPagePath: TEST_HOST }, links: { ciHelpPagePath: TEST_HOST },
pipelinesEmptyStateSvgPath: TEST_HOST, pipelinesEmptyStateSvgPath: TEST_HOST,
pipelines: { };
stages: [], const defaultPipelinesState = {
failedStages: [], stages: [],
isLoadingJobs: false, failedStages: [],
}, isLoadingJobs: false,
}; };
const fetchLatestPipelineMock = jest.fn(); const fetchLatestPipelineMock = jest.fn();
...@@ -34,23 +34,20 @@ describe('IDE pipelines list', () => { ...@@ -34,23 +34,20 @@ describe('IDE pipelines list', () => {
const failedStagesGetterMock = jest.fn().mockReturnValue([]); const failedStagesGetterMock = jest.fn().mockReturnValue([]);
const fakeProjectPath = 'alpha/beta'; const fakeProjectPath = 'alpha/beta';
const createComponent = (state = {}) => { const createStore = (rootState, pipelinesState) => {
const { pipelines: pipelinesState, ...restOfState } = state; return new Vuex.Store({
const { defaultPipelines, ...defaultRestOfState } = defaultState;
const fakeStore = new Vuex.Store({
getters: { getters: {
currentProject: () => ({ web_url: 'some/url ', path_with_namespace: fakeProjectPath }), currentProject: () => ({ web_url: 'some/url ', path_with_namespace: fakeProjectPath }),
}, },
state: { state: {
...defaultRestOfState, ...defaultState,
...restOfState, ...rootState,
}, },
modules: { modules: {
pipelines: { pipelines: {
namespaced: true, namespaced: true,
state: { state: {
...defaultPipelines, ...defaultPipelinesState,
...pipelinesState, ...pipelinesState,
}, },
actions: { actions: {
...@@ -69,10 +66,12 @@ describe('IDE pipelines list', () => { ...@@ -69,10 +66,12 @@ describe('IDE pipelines list', () => {
}, },
}, },
}); });
};
const createComponent = (state = {}, pipelinesState = {}) => {
wrapper = shallowMount(List, { wrapper = shallowMount(List, {
localVue, localVue,
store: fakeStore, store: createStore(state, pipelinesState),
}); });
}; };
...@@ -94,31 +93,33 @@ describe('IDE pipelines list', () => { ...@@ -94,31 +93,33 @@ describe('IDE pipelines list', () => {
describe('when loading', () => { describe('when loading', () => {
let defaultPipelinesLoadingState; let defaultPipelinesLoadingState;
beforeAll(() => { beforeAll(() => {
defaultPipelinesLoadingState = { defaultPipelinesLoadingState = {
...defaultState.pipelines,
isLoadingPipeline: true, isLoadingPipeline: true,
}; };
}); });
it('does not render when pipeline has loaded before', () => { it('does not render when pipeline has loaded before', () => {
createComponent({ createComponent(
pipelines: { {},
{
...defaultPipelinesLoadingState, ...defaultPipelinesLoadingState,
hasLoadedPipeline: true, hasLoadedPipeline: true,
}, },
}); );
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
}); });
it('renders loading state', () => { it('renders loading state', () => {
createComponent({ createComponent(
pipelines: { {},
{
...defaultPipelinesLoadingState, ...defaultPipelinesLoadingState,
hasLoadedPipeline: false, hasLoadedPipeline: false,
}, },
}); );
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true); expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
}); });
...@@ -126,21 +127,22 @@ describe('IDE pipelines list', () => { ...@@ -126,21 +127,22 @@ describe('IDE pipelines list', () => {
describe('when loaded', () => { describe('when loaded', () => {
let defaultPipelinesLoadedState; let defaultPipelinesLoadedState;
beforeAll(() => { beforeAll(() => {
defaultPipelinesLoadedState = { defaultPipelinesLoadedState = {
...defaultState.pipelines,
isLoadingPipeline: false, isLoadingPipeline: false,
hasLoadedPipeline: true, hasLoadedPipeline: true,
}; };
}); });
it('renders empty state when no latestPipeline', () => { it('renders empty state when no latestPipeline', () => {
createComponent({ pipelines: { ...defaultPipelinesLoadedState, latestPipeline: null } }); createComponent({}, { ...defaultPipelinesLoadedState, latestPipeline: null });
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
describe('with latest pipeline loaded', () => { describe('with latest pipeline loaded', () => {
let withLatestPipelineState; let withLatestPipelineState;
beforeAll(() => { beforeAll(() => {
withLatestPipelineState = { withLatestPipelineState = {
...defaultPipelinesLoadedState, ...defaultPipelinesLoadedState,
...@@ -149,12 +151,12 @@ describe('IDE pipelines list', () => { ...@@ -149,12 +151,12 @@ describe('IDE pipelines list', () => {
}); });
it('renders ci icon', () => { it('renders ci icon', () => {
createComponent({ pipelines: withLatestPipelineState }); createComponent({}, withLatestPipelineState);
expect(wrapper.find(CiIcon).exists()).toBe(true); expect(wrapper.find(CiIcon).exists()).toBe(true);
}); });
it('renders pipeline data', () => { it('renders pipeline data', () => {
createComponent({ pipelines: withLatestPipelineState }); createComponent({}, withLatestPipelineState);
expect(wrapper.text()).toContain('#1'); expect(wrapper.text()).toContain('#1');
}); });
...@@ -162,7 +164,7 @@ describe('IDE pipelines list', () => { ...@@ -162,7 +164,7 @@ describe('IDE pipelines list', () => {
it('renders list of jobs', () => { it('renders list of jobs', () => {
const stages = []; const stages = [];
const isLoadingJobs = true; const isLoadingJobs = true;
createComponent({ pipelines: { ...withLatestPipelineState, stages, isLoadingJobs } }); createComponent({}, { ...withLatestPipelineState, stages, isLoadingJobs });
const jobProps = wrapper const jobProps = wrapper
.findAll(Tab) .findAll(Tab)
...@@ -177,7 +179,7 @@ describe('IDE pipelines list', () => { ...@@ -177,7 +179,7 @@ describe('IDE pipelines list', () => {
const failedStages = []; const failedStages = [];
failedStagesGetterMock.mockReset().mockReturnValue(failedStages); failedStagesGetterMock.mockReset().mockReturnValue(failedStages);
const isLoadingJobs = true; const isLoadingJobs = true;
createComponent({ pipelines: { ...withLatestPipelineState, isLoadingJobs } }); createComponent({}, { ...withLatestPipelineState, isLoadingJobs });
const jobProps = wrapper const jobProps = wrapper
.findAll(Tab) .findAll(Tab)
...@@ -191,12 +193,13 @@ describe('IDE pipelines list', () => { ...@@ -191,12 +193,13 @@ describe('IDE pipelines list', () => {
describe('with YAML error', () => { describe('with YAML error', () => {
it('renders YAML error', () => { it('renders YAML error', () => {
const yamlError = 'test yaml error'; const yamlError = 'test yaml error';
createComponent({ createComponent(
pipelines: { {},
{
...defaultPipelinesLoadedState, ...defaultPipelinesLoadedState,
latestPipeline: { ...pipelines[0], yamlError }, latestPipeline: { ...pipelines[0], yamlError },
}, },
}); );
expect(wrapper.text()).toContain('Found errors in your .gitlab-ci.yml:'); expect(wrapper.text()).toContain('Found errors in your .gitlab-ci.yml:');
expect(wrapper.text()).toContain(yamlError); expect(wrapper.text()).toContain(yamlError);
......
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