2018-11-08 19:23:39 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import testAction from 'spec/helpers/vuex_action_helper';
|
|
|
|
import { showTreeEntry, getFiles } from '~/ide/stores/actions/tree';
|
|
|
|
import * as types from '~/ide/stores/mutation_types';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-05-09 12:01:36 +05:30
|
|
|
import store from '~/ide/stores';
|
|
|
|
import service from '~/ide/services';
|
|
|
|
import router from '~/ide/ide_router';
|
2018-11-08 19:23:39 +05:30
|
|
|
import { file, resetStore, createEntriesFromPaths } from '../../helpers';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
describe('Multi-file store tree actions', () => {
|
|
|
|
let projectTree;
|
2018-11-08 19:23:39 +05:30
|
|
|
let mock;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
const basicCallParameters = {
|
|
|
|
endpoint: 'rootEndpoint',
|
|
|
|
projectId: 'abcproject',
|
|
|
|
branch: 'master',
|
|
|
|
branchId: 'master',
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(router, 'push');
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
store.state.currentProjectId = 'abcproject';
|
|
|
|
store.state.currentBranchId = 'master';
|
|
|
|
store.state.projects.abcproject = {
|
|
|
|
web_url: '',
|
|
|
|
branches: {
|
|
|
|
master: {
|
|
|
|
workingReference: '1',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.restore();
|
2018-05-09 12:01:36 +05:30
|
|
|
resetStore(store);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getFiles', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('success', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(service, 'getFiles').and.callThrough();
|
|
|
|
|
|
|
|
mock
|
|
|
|
.onGet(/(.*)/)
|
|
|
|
.replyOnce(200, [
|
|
|
|
'file.txt',
|
|
|
|
'folder/fileinfolder.js',
|
|
|
|
'folder/subfolder/fileinsubfolder.js',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls service getFiles', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getFiles', basicCallParameters)
|
|
|
|
.then(() => {
|
|
|
|
expect(service.getFiles).toHaveBeenCalledWith('', 'master');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds data into tree', done => {
|
|
|
|
store
|
|
|
|
.dispatch('getFiles', basicCallParameters)
|
|
|
|
.then(() => {
|
|
|
|
projectTree = store.state.trees['abcproject/master'];
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(projectTree.tree.length).toBe(2);
|
|
|
|
expect(projectTree.tree[0].type).toBe('tree');
|
|
|
|
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
|
|
|
|
expect(projectTree.tree[1].type).toBe('blob');
|
|
|
|
expect(projectTree.tree[0].tree[0].tree[0].type).toBe('blob');
|
|
|
|
expect(projectTree.tree[0].tree[0].tree[0].name).toBe('fileinsubfolder.js');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('error', () => {
|
|
|
|
it('dispatches branch not found actions when response is 404', done => {
|
|
|
|
const dispatch = jasmine.createSpy('dispatchSpy');
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
store.state.projects = {
|
|
|
|
'abc/def': {
|
|
|
|
web_url: `${gl.TEST_HOST}/files`,
|
|
|
|
},
|
|
|
|
};
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
mock.onGet(/(.*)/).replyOnce(404);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
getFiles(
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
dispatch,
|
|
|
|
state: store.state,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
projectId: 'abc/def',
|
|
|
|
branchId: 'master-testing',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.then(done.fail)
|
|
|
|
.catch(() => {
|
|
|
|
expect(dispatch.calls.argsFor(0)).toEqual([
|
|
|
|
'showBranchNotFoundError',
|
|
|
|
'master-testing',
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches error action', done => {
|
|
|
|
const dispatch = jasmine.createSpy('dispatchSpy');
|
|
|
|
|
|
|
|
store.state.projects = {
|
|
|
|
'abc/def': {
|
|
|
|
web_url: `${gl.TEST_HOST}/files`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
mock.onGet(/(.*)/).replyOnce(500);
|
|
|
|
|
|
|
|
getFiles(
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
dispatch,
|
|
|
|
state: store.state,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
projectId: 'abc/def',
|
|
|
|
branchId: 'master-testing',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.then(done.fail)
|
|
|
|
.catch(() => {
|
|
|
|
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
|
|
|
|
text: 'An error occured whilst loading all the files.',
|
|
|
|
action: jasmine.any(Function),
|
|
|
|
actionText: 'Please try again',
|
|
|
|
actionPayload: { projectId: 'abc/def', branchId: 'master-testing' },
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleTreeOpen', () => {
|
|
|
|
let tree;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
tree = file('testing', '1', 'tree');
|
|
|
|
store.state.entries[tree.path] = tree;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles the tree open', done => {
|
|
|
|
store
|
|
|
|
.dispatch('toggleTreeOpen', tree.path)
|
|
|
|
.then(() => {
|
|
|
|
expect(tree.opened).toBeTruthy();
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('showTreeEntry', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
beforeEach(() => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const paths = [
|
|
|
|
'grandparent',
|
|
|
|
'ancestor',
|
|
|
|
'grandparent/parent',
|
|
|
|
'grandparent/aunt',
|
|
|
|
'grandparent/parent/child.txt',
|
|
|
|
'grandparent/aunt/cousing.txt',
|
|
|
|
];
|
|
|
|
|
|
|
|
Object.assign(store.state.entries, createEntriesFromPaths(paths));
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('opens the parents', done => {
|
|
|
|
testAction(
|
|
|
|
showTreeEntry,
|
|
|
|
'grandparent/parent/child.txt',
|
|
|
|
store.state,
|
2018-11-18 11:00:15 +05:30
|
|
|
[{ type: types.SET_TREE_OPEN, payload: 'grandparent/parent' }],
|
|
|
|
[{ type: 'showTreeEntry', payload: 'grandparent/parent' }],
|
2018-11-08 19:23:39 +05:30
|
|
|
done,
|
|
|
|
);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|