From ad0265eead72a624ce7a020847db4f0f0c877e57 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 9 Apr 2020 09:10:17 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../javascripts/ide/stores/actions/project_spec.js | 112 +++++++++------------ 1 file changed, 46 insertions(+), 66 deletions(-) (limited to 'spec/javascripts') diff --git a/spec/javascripts/ide/stores/actions/project_spec.js b/spec/javascripts/ide/stores/actions/project_spec.js index bd51222ac3c..e962224d1ad 100644 --- a/spec/javascripts/ide/stores/actions/project_spec.js +++ b/spec/javascripts/ide/stores/actions/project_spec.js @@ -4,7 +4,7 @@ import { refreshLastCommitData, showBranchNotFoundError, createNewBranchFromDefault, - showEmptyState, + loadEmptyBranch, openBranch, loadFile, loadBranch, @@ -16,6 +16,8 @@ import router from '~/ide/ide_router'; import { resetStore } from '../../helpers'; import testAction from '../../../helpers/vuex_action_helper'; +const TEST_PROJECT_ID = 'abc/def'; + describe('IDE store project actions', () => { let mock; let store; @@ -24,7 +26,7 @@ describe('IDE store project actions', () => { store = createStore(); mock = new MockAdapter(axios); - store.state.projects['abc/def'] = { + store.state.projects[TEST_PROJECT_ID] = { branches: {}, }; }); @@ -83,7 +85,7 @@ describe('IDE store project actions', () => { { type: 'SET_BRANCH_COMMIT', payload: { - projectId: 'abc/def', + projectId: TEST_PROJECT_ID, branchId: 'master', commit: { id: '123' }, }, @@ -200,17 +202,17 @@ describe('IDE store project actions', () => { }); }); - describe('showEmptyState', () => { + describe('loadEmptyBranch', () => { it('creates a blank tree and sets loading state to false', done => { testAction( - showEmptyState, - { projectId: 'abc/def', branchId: 'master' }, + loadEmptyBranch, + { projectId: TEST_PROJECT_ID, branchId: 'master' }, store.state, [ - { type: 'CREATE_TREE', payload: { treePath: 'abc/def/master' } }, + { type: 'CREATE_TREE', payload: { treePath: `${TEST_PROJECT_ID}/master` } }, { type: 'TOGGLE_LOADING', - payload: { entry: store.state.trees['abc/def/master'], forceValue: false }, + payload: { entry: store.state.trees[`${TEST_PROJECT_ID}/master`], forceValue: false }, }, ], jasmine.any(Object), @@ -218,13 +220,15 @@ describe('IDE store project actions', () => { ); }); - it('sets the currentBranchId to the branchId that was passed', done => { + it('does nothing, if tree already exists', done => { + const trees = { [`${TEST_PROJECT_ID}/master`]: [] }; + testAction( - showEmptyState, - { projectId: 'abc/def', branchId: 'master' }, - store.state, - jasmine.any(Object), - [{ type: 'setCurrentBranchId', payload: 'master' }], + loadEmptyBranch, + { projectId: TEST_PROJECT_ID, branchId: 'master' }, + { trees }, + [], + [], done, ); }); @@ -278,10 +282,29 @@ describe('IDE store project actions', () => { }); describe('loadBranch', () => { - const projectId = 'abc/def'; + const projectId = TEST_PROJECT_ID; const branchId = '123-lorem'; const ref = 'abcd2322'; + it('when empty repo, loads empty branch', done => { + const mockGetters = { emptyRepo: true }; + + testAction( + loadBranch, + { projectId, branchId }, + { ...store.state, ...mockGetters }, + [], + [{ type: 'loadEmptyBranch', payload: { projectId, branchId } }], + done, + ); + }); + + it('when branch already exists, does nothing', done => { + store.state.projects[projectId].branches[branchId] = {}; + + testAction(loadBranch, { projectId, branchId }, store.state, [], [], done); + }); + it('fetches branch data', done => { const mockGetters = { findBranch: () => ({ commit: { id: ref } }) }; spyOn(store, 'dispatch').and.returnValue(Promise.resolve()); @@ -317,7 +340,7 @@ describe('IDE store project actions', () => { }); describe('openBranch', () => { - const projectId = 'abc/def'; + const projectId = TEST_PROJECT_ID; const branchId = '123-lorem'; const branch = { @@ -335,55 +358,6 @@ describe('IDE store project actions', () => { }); }); - it('loads file right away if the branch has already been fetched', done => { - spyOn(store, 'dispatch'); - - Object.assign(store.state, { - projects: { - [projectId]: { - branches: { - [branchId]: { foo: 'bar' }, - }, - }, - }, - }); - - openBranch(store, branch) - .then(() => { - expect(store.dispatch.calls.allArgs()).toEqual([['loadFile', { basePath: undefined }]]); - }) - .then(done) - .catch(done.fail); - }); - - describe('empty repo', () => { - beforeEach(() => { - spyOn(store, 'dispatch').and.returnValue(Promise.resolve()); - - Object.assign(store.state, { - currentProjectId: 'abc/def', - projects: { - 'abc/def': { - empty_repo: true, - }, - }, - }); - }); - - afterEach(() => { - resetStore(store); - }); - - it('dispatches showEmptyState action right away', done => { - openBranch(store, branch) - .then(() => { - expect(store.dispatch.calls.allArgs()).toEqual([['showEmptyState', branch]]); - done(); - }) - .catch(done.fail); - }); - }); - describe('existing branch', () => { beforeEach(() => { spyOn(store, 'dispatch').and.returnValue(Promise.resolve()); @@ -410,11 +384,17 @@ describe('IDE store project actions', () => { it('dispatches correct branch actions', done => { openBranch(store, branch) - .then(() => { + .then(val => { expect(store.dispatch.calls.allArgs()).toEqual([ ['setCurrentBranchId', branchId], ['loadBranch', { projectId, branchId }], ]); + + expect(val).toEqual( + new Error( + `An error occurred while getting files for - ${projectId}/${branchId}`, + ), + ); }) .then(done) .catch(done.fail); -- cgit v1.2.3