summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
commitad0265eead72a624ce7a020847db4f0f0c877e57 (patch)
tree206e0564b02aa9530e3c95f70eb10a77e074bdf0 /spec/javascripts
parent4dfc8711171fe0c04bc6b8b224687603026dea46 (diff)
downloadgitlab-ce-ad0265eead72a624ce7a020847db4f0f0c877e57.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/ide/stores/actions/project_spec.js112
1 files changed, 46 insertions, 66 deletions
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 - <strong>${projectId}/${branchId}</strong>`,
+ ),
+ );
})
.then(done)
.catch(done.fail);