2018-05-09 12:01:36 +05:30
|
|
|
import mutations from '~/ide/stores/mutations/tree';
|
|
|
|
import state from '~/ide/stores/state';
|
|
|
|
import { file } from '../../helpers';
|
|
|
|
|
|
|
|
describe('Multi-file store tree mutations', () => {
|
|
|
|
let localState;
|
|
|
|
let localTree;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localState = state();
|
|
|
|
localTree = file();
|
|
|
|
|
|
|
|
localState.entries[localTree.path] = localTree;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_TREE_OPEN', () => {
|
|
|
|
it('toggles tree open', () => {
|
|
|
|
mutations.TOGGLE_TREE_OPEN(localState, localTree.path);
|
|
|
|
|
|
|
|
expect(localTree.opened).toBeTruthy();
|
|
|
|
|
|
|
|
mutations.TOGGLE_TREE_OPEN(localState, localTree.path);
|
|
|
|
|
|
|
|
expect(localTree.opened).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_DIRECTORY_DATA', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
let data;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
data = [file('tree'), file('foo'), file('blob')];
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
it('adds directory data', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
localState.trees['project/main'] = {
|
2018-05-09 12:01:36 +05:30
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_DIRECTORY_DATA(localState, {
|
|
|
|
data,
|
2021-09-04 01:27:46 +05:30
|
|
|
treePath: 'project/main',
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const tree = localState.trees['project/main'];
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
expect(tree.tree.length).toBe(3);
|
|
|
|
expect(tree.tree[0].name).toBe('tree');
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(tree.tree[1].name).toBe('foo');
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(tree.tree[2].name).toBe('blob');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('keeps loading state', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
mutations.CREATE_TREE(localState, {
|
2021-09-04 01:27:46 +05:30
|
|
|
treePath: 'project/main',
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
mutations.SET_DIRECTORY_DATA(localState, {
|
|
|
|
data,
|
2021-09-04 01:27:46 +05:30
|
|
|
treePath: 'project/main',
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(localState.trees['project/main'].loading).toBe(true);
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
it('does not override tree already in state, but merges the two with correct order', () => {
|
|
|
|
const openedFile = file('new');
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
localState.trees['project/main'] = {
|
2019-07-07 11:18:12 +05:30
|
|
|
loading: true,
|
|
|
|
tree: [openedFile],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_DIRECTORY_DATA(localState, {
|
|
|
|
data,
|
2021-09-04 01:27:46 +05:30
|
|
|
treePath: 'project/main',
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const { tree } = localState.trees['project/main'];
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(tree.length).toBe(4);
|
|
|
|
expect(tree[0].name).toBe('blob');
|
|
|
|
expect(tree[1].name).toBe('foo');
|
|
|
|
expect(tree[2].name).toBe('new');
|
|
|
|
expect(tree[3].name).toBe('tree');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns tree unchanged if the opened file is already in the tree', () => {
|
|
|
|
const openedFile = file('foo');
|
2021-09-04 01:27:46 +05:30
|
|
|
localState.trees['project/main'] = {
|
2019-07-07 11:18:12 +05:30
|
|
|
loading: true,
|
|
|
|
tree: [openedFile],
|
|
|
|
};
|
|
|
|
|
|
|
|
mutations.SET_DIRECTORY_DATA(localState, {
|
|
|
|
data,
|
2021-09-04 01:27:46 +05:30
|
|
|
treePath: 'project/main',
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const { tree } = localState.trees['project/main'];
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(tree.length).toBe(3);
|
|
|
|
|
|
|
|
expect(tree[0].name).toBe('tree');
|
|
|
|
expect(tree[1].name).toBe('foo');
|
|
|
|
expect(tree[2].name).toBe('blob');
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('REMOVE_ALL_CHANGES_FILES', () => {
|
|
|
|
it('removes all files from changedFiles state', () => {
|
|
|
|
localState.changedFiles.push(file('REMOVE_ALL_CHANGES_FILES'));
|
|
|
|
|
|
|
|
mutations.REMOVE_ALL_CHANGES_FILES(localState);
|
|
|
|
|
|
|
|
expect(localState.changedFiles.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|