diff options
Diffstat (limited to 'spec/frontend/import_projects/store/mutations_spec.js')
-rw-r--r-- | spec/frontend/import_projects/store/mutations_spec.js | 178 |
1 files changed, 97 insertions, 81 deletions
diff --git a/spec/frontend/import_projects/store/mutations_spec.js b/spec/frontend/import_projects/store/mutations_spec.js index 3672ec9f2c0..5d78a7fa9e7 100644 --- a/spec/frontend/import_projects/store/mutations_spec.js +++ b/spec/frontend/import_projects/store/mutations_spec.js @@ -1,9 +1,11 @@ import * as types from '~/import_projects/store/mutation_types'; import mutations from '~/import_projects/store/mutations'; +import getInitialState from '~/import_projects/store/state'; import { STATUSES } from '~/import_projects/constants'; describe('import_projects store mutations', () => { let state; + const SOURCE_PROJECT = { id: 1, full_name: 'full/name', @@ -19,13 +21,23 @@ describe('import_projects store mutations', () => { }; describe(`${types.SET_FILTER}`, () => { - it('overwrites current filter value', () => { - state = { filter: 'some-value' }; - const NEW_VALUE = 'new-value'; + const NEW_VALUE = 'new-value'; + beforeEach(() => { + state = { + filter: 'some-value', + repositories: ['some', ' repositories'], + pageInfo: { page: 1 }, + }; mutations[types.SET_FILTER](state, NEW_VALUE); + }); - expect(state.filter).toBe(NEW_VALUE); + it('removes current repositories list', () => { + expect(state.repositories.length).toBe(0); + }); + + it('resets current page to 0', () => { + expect(state.pageInfo.page).toBe(0); }); }); @@ -40,93 +52,104 @@ describe('import_projects store mutations', () => { }); describe(`${types.RECEIVE_REPOS_SUCCESS}`, () => { - describe('for imported projects', () => { - const response = { - importedProjects: [IMPORTED_PROJECT], - providerRepos: [], - }; + describe('with legacy response format', () => { + describe('for imported projects', () => { + const response = { + importedProjects: [IMPORTED_PROJECT], + providerRepos: [], + }; - it('picks import status from response', () => { - state = {}; + it('recreates importSource from response', () => { + state = getInitialState(); - mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + mutations[types.RECEIVE_REPOS_SUCCESS](state, response); - expect(state.repositories[0].importStatus).toBe(IMPORTED_PROJECT.importStatus); - }); + expect(state.repositories[0].importSource).toStrictEqual( + expect.objectContaining({ + fullName: IMPORTED_PROJECT.importSource, + sanitizedName: IMPORTED_PROJECT.name, + providerLink: IMPORTED_PROJECT.providerLink, + }), + ); + }); - it('recreates importSource from response', () => { - state = {}; + it('passes project to importProject', () => { + state = getInitialState(); - mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + mutations[types.RECEIVE_REPOS_SUCCESS](state, response); - expect(state.repositories[0].importSource).toStrictEqual( - expect.objectContaining({ - fullName: IMPORTED_PROJECT.importSource, - sanitizedName: IMPORTED_PROJECT.name, - providerLink: IMPORTED_PROJECT.providerLink, - }), - ); + expect(IMPORTED_PROJECT).toStrictEqual( + expect.objectContaining(state.repositories[0].importedProject), + ); + }); }); - it('passes project to importProject', () => { - state = {}; + describe('for importable projects', () => { + beforeEach(() => { + state = getInitialState(); - mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + const response = { + importedProjects: [], + providerRepos: [SOURCE_PROJECT], + }; + mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + }); - expect(IMPORTED_PROJECT).toStrictEqual( - expect.objectContaining(state.repositories[0].importedProject), - ); + it('sets importSource to project', () => { + expect(state.repositories[0].importSource).toBe(SOURCE_PROJECT); + }); }); - }); - describe('for importable projects', () => { - beforeEach(() => { - state = {}; + describe('for incompatible projects', () => { const response = { importedProjects: [], - providerRepos: [SOURCE_PROJECT], + providerRepos: [], + incompatibleRepos: [SOURCE_PROJECT], }; - mutations[types.RECEIVE_REPOS_SUCCESS](state, response); - }); - it('sets import status to none', () => { - expect(state.repositories[0].importStatus).toBe(STATUSES.NONE); - }); + beforeEach(() => { + state = getInitialState(); + mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + }); + + it('sets incompatible flag', () => { + expect(state.repositories[0].importSource.incompatible).toBe(true); + }); - it('sets importSource to project', () => { - expect(state.repositories[0].importSource).toBe(SOURCE_PROJECT); + it('sets importSource to project', () => { + expect(state.repositories[0].importSource).toStrictEqual( + expect.objectContaining(SOURCE_PROJECT), + ); + }); }); - }); - describe('for incompatible projects', () => { - const response = { - importedProjects: [], - providerRepos: [], - incompatibleRepos: [SOURCE_PROJECT], - }; + it('sets repos loading flag to false', () => { + const response = { + importedProjects: [], + providerRepos: [], + }; + + state = getInitialState(); - beforeEach(() => { - state = {}; mutations[types.RECEIVE_REPOS_SUCCESS](state, response); - }); - it('sets incompatible flag', () => { - expect(state.repositories[0].importSource.incompatible).toBe(true); + expect(state.isLoadingRepos).toBe(false); }); + }); - it('sets importSource to project', () => { - expect(state.repositories[0].importSource).toStrictEqual( - expect.objectContaining(SOURCE_PROJECT), - ); - }); + it('passes response as it is', () => { + const response = []; + state = getInitialState(); + + mutations[types.RECEIVE_REPOS_SUCCESS](state, response); + + expect(state.repositories).toStrictEqual(response); }); it('sets repos loading flag to false', () => { - const response = { - importedProjects: [], - providerRepos: [], - }; - state = {}; + const response = []; + + state = getInitialState(); mutations[types.RECEIVE_REPOS_SUCCESS](state, response); @@ -136,7 +159,7 @@ describe('import_projects store mutations', () => { describe(`${types.RECEIVE_REPOS_ERROR}`, () => { it('sets repos loading flag to false', () => { - state = {}; + state = getInitialState(); mutations[types.RECEIVE_REPOS_ERROR](state); @@ -154,7 +177,7 @@ describe('import_projects store mutations', () => { }); it(`sets status to ${STATUSES.SCHEDULING}`, () => { - expect(state.repositories[0].importStatus).toBe(STATUSES.SCHEDULING); + expect(state.repositories[0].importedProject.importStatus).toBe(STATUSES.SCHEDULING); }); }); @@ -170,7 +193,9 @@ describe('import_projects store mutations', () => { }); it('sets import status', () => { - expect(state.repositories[0].importStatus).toBe(IMPORTED_PROJECT.importStatus); + expect(state.repositories[0].importedProject.importStatus).toBe( + IMPORTED_PROJECT.importStatus, + ); }); it('sets imported project', () => { @@ -188,8 +213,8 @@ describe('import_projects store mutations', () => { mutations[types.RECEIVE_IMPORT_ERROR](state, REPO_ID); }); - it(`resets import status to ${STATUSES.NONE}`, () => { - expect(state.repositories[0].importStatus).toBe(STATUSES.NONE); + it(`removes importedProject entry`, () => { + expect(state.repositories[0].importedProject).toBeNull(); }); }); @@ -203,7 +228,9 @@ describe('import_projects store mutations', () => { mutations[types.RECEIVE_JOBS_SUCCESS](state, updatedProjects); - expect(state.repositories[0].importStatus).toBe(updatedProjects[0].importStatus); + expect(state.repositories[0].importedProject.importStatus).toBe( + updatedProjects[0].importStatus, + ); }); }); @@ -280,17 +307,6 @@ describe('import_projects store mutations', () => { }); }); - describe(`${types.SET_PAGE_INFO}`, () => { - it('sets passed page info', () => { - state = {}; - const pageInfo = { page: 1, total: 10 }; - - mutations[types.SET_PAGE_INFO](state, pageInfo); - - expect(state.pageInfo).toBe(pageInfo); - }); - }); - describe(`${types.SET_PAGE}`, () => { it('sets page number', () => { const NEW_PAGE = 4; |