2018-04-25 05:38:06 -04:00
|
|
|
import actions, {
|
|
|
|
stageAllChanges,
|
|
|
|
unstageAllChanges,
|
|
|
|
toggleFileFinder,
|
|
|
|
setCurrentBranchId,
|
|
|
|
setEmptyStateSvgs,
|
|
|
|
updateActivityBarView,
|
2018-04-25 05:51:41 -04:00
|
|
|
updateTempFlagForEntry,
|
2018-04-25 05:38:06 -04:00
|
|
|
} from '~/ide/stores/actions';
|
2018-03-20 10:16:38 -04:00
|
|
|
import store from '~/ide/stores';
|
2018-03-29 10:16:19 -04:00
|
|
|
import * as types from '~/ide/stores/mutation_types';
|
2018-03-20 10:16:38 -04:00
|
|
|
import router from '~/ide/ide_router';
|
2018-03-20 10:12:48 -04:00
|
|
|
import { resetStore, file } from '../helpers';
|
2018-04-18 06:29:40 -04:00
|
|
|
import testAction from '../../helpers/vuex_action_helper';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
describe('Multi-file store actions', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(router, 'push');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetStore(store);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('redirectToUrl', () => {
|
|
|
|
it('calls visitUrl', done => {
|
2018-04-13 23:49:11 -04:00
|
|
|
const visitUrl = spyOnDependency(actions, 'visitUrl');
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('redirectToUrl', 'test')
|
|
|
|
.then(() => {
|
2018-04-13 23:49:11 -04:00
|
|
|
expect(visitUrl).toHaveBeenCalledWith('test');
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setInitialData', () => {
|
|
|
|
it('commits initial data', done => {
|
|
|
|
store
|
|
|
|
.dispatch('setInitialData', { canCommit: true })
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.canCommit).toBeTruthy();
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('discardAllChanges', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const f = file('discardAll');
|
|
|
|
f.changed = true;
|
|
|
|
|
|
|
|
store.state.openFiles.push(f);
|
|
|
|
store.state.changedFiles.push(f);
|
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('discards changes in file', done => {
|
|
|
|
store
|
|
|
|
.dispatch('discardAllChanges')
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.openFiles.changed).toBeFalsy();
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all files from changedFiles state', done => {
|
|
|
|
store
|
|
|
|
.dispatch('discardAllChanges')
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.changedFiles.length).toBe(0);
|
|
|
|
expect(store.state.openFiles.length).toBe(1);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('closeAllFiles', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const f = file('closeAll');
|
|
|
|
store.state.openFiles.push(f);
|
|
|
|
store.state.openFiles[0].opened = true;
|
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('closes all open files', done => {
|
|
|
|
store
|
|
|
|
.dispatch('closeAllFiles')
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.openFiles.length).toBe(0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createTempEntry', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
document.body.innerHTML += '<div class="flash-container"></div>';
|
|
|
|
|
|
|
|
store.state.currentProjectId = 'abcproject';
|
|
|
|
store.state.currentBranchId = 'mybranch';
|
|
|
|
|
|
|
|
store.state.trees['abcproject/mybranch'] = {
|
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
store.state.projects.abcproject = {
|
|
|
|
web_url: '',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.querySelector('.flash-container').remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tree', () => {
|
|
|
|
it('creates temp tree', done => {
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
branchId: store.state.currentBranchId,
|
|
|
|
name: 'test',
|
|
|
|
type: 'tree',
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const entry = store.state.entries.test;
|
|
|
|
|
|
|
|
expect(entry).not.toBeNull();
|
|
|
|
expect(entry.type).toBe('tree');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates new folder inside another tree', done => {
|
|
|
|
const tree = {
|
|
|
|
type: 'tree',
|
|
|
|
name: 'testing',
|
|
|
|
path: 'testing',
|
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
store.state.entries[tree.path] = tree;
|
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
branchId: store.state.currentBranchId,
|
|
|
|
name: 'testing/test',
|
|
|
|
type: 'tree',
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(tree.tree[0].tempFile).toBeTruthy();
|
|
|
|
expect(tree.tree[0].name).toBe('test');
|
|
|
|
expect(tree.tree[0].type).toBe('tree');
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not create new tree if already exists', done => {
|
|
|
|
const tree = {
|
|
|
|
type: 'tree',
|
|
|
|
path: 'testing',
|
|
|
|
tempFile: false,
|
|
|
|
tree: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
store.state.entries[tree.path] = tree;
|
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
branchId: store.state.currentBranchId,
|
|
|
|
name: 'testing',
|
|
|
|
type: 'tree',
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.entries[tree.path].tempFile).toEqual(false);
|
|
|
|
expect(document.querySelector('.flash-alert')).not.toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('blob', () => {
|
|
|
|
it('creates temp file', done => {
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
name: 'test',
|
|
|
|
branchId: 'mybranch',
|
|
|
|
type: 'blob',
|
|
|
|
})
|
|
|
|
.then(f => {
|
|
|
|
expect(f.tempFile).toBeTruthy();
|
2018-04-18 06:29:40 -04:00
|
|
|
expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds tmp file to open files', done => {
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
name: 'test',
|
|
|
|
branchId: 'mybranch',
|
|
|
|
type: 'blob',
|
|
|
|
})
|
|
|
|
.then(f => {
|
|
|
|
expect(store.state.openFiles.length).toBe(1);
|
|
|
|
expect(store.state.openFiles[0].name).toBe(f.name);
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds tmp file to changed files', done => {
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
name: 'test',
|
|
|
|
branchId: 'mybranch',
|
|
|
|
type: 'blob',
|
|
|
|
})
|
|
|
|
.then(f => {
|
|
|
|
expect(store.state.changedFiles.length).toBe(1);
|
|
|
|
expect(store.state.changedFiles[0].name).toBe(f.name);
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets tmp file as active', done => {
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
name: 'test',
|
|
|
|
branchId: 'mybranch',
|
|
|
|
type: 'blob',
|
|
|
|
})
|
|
|
|
.then(f => {
|
|
|
|
expect(f.active).toBeTruthy();
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates flash message if file already exists', done => {
|
|
|
|
const f = file('test', '1', 'blob');
|
|
|
|
store.state.trees['abcproject/mybranch'].tree = [f];
|
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('createTempEntry', {
|
|
|
|
name: 'test',
|
|
|
|
branchId: 'mybranch',
|
|
|
|
type: 'blob',
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
expect(document.querySelector('.flash-alert')).not.toBeNull();
|
|
|
|
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('popHistoryState', () => {});
|
|
|
|
|
|
|
|
describe('scrollToTab', () => {
|
|
|
|
it('focuses the current active element', done => {
|
|
|
|
document.body.innerHTML +=
|
|
|
|
'<div id="tabs"><div class="active"><div class="repo-tab"></div></div></div>';
|
|
|
|
const el = document.querySelector('.repo-tab');
|
|
|
|
spyOn(el, 'focus');
|
|
|
|
|
|
|
|
store
|
|
|
|
.dispatch('scrollToTab')
|
|
|
|
.then(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(el.focus).toHaveBeenCalled();
|
|
|
|
|
|
|
|
document.getElementById('tabs').remove();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-21 06:05:08 -04:00
|
|
|
describe('stageAllChanges', () => {
|
|
|
|
it('adds all files from changedFiles to stagedFiles', done => {
|
2018-03-29 10:16:19 -04:00
|
|
|
store.state.changedFiles.push(file(), file('new'));
|
|
|
|
|
|
|
|
testAction(
|
2018-04-13 23:49:11 -04:00
|
|
|
stageAllChanges,
|
2018-03-29 10:16:19 -04:00
|
|
|
null,
|
|
|
|
store.state,
|
|
|
|
[
|
2018-05-06 07:30:50 -04:00
|
|
|
{ type: types.SET_LAST_COMMIT_MSG, payload: '' },
|
2018-03-29 10:16:19 -04:00
|
|
|
{ type: types.STAGE_CHANGE, payload: store.state.changedFiles[0].path },
|
|
|
|
{ type: types.STAGE_CHANGE, payload: store.state.changedFiles[1].path },
|
|
|
|
],
|
2018-04-05 05:46:19 -04:00
|
|
|
[],
|
2018-03-29 10:16:19 -04:00
|
|
|
done,
|
|
|
|
);
|
2018-03-21 06:05:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unstageAllChanges', () => {
|
|
|
|
it('removes all files from stagedFiles after unstaging', done => {
|
2018-03-29 10:16:19 -04:00
|
|
|
store.state.stagedFiles.push(file(), file('new'));
|
|
|
|
|
|
|
|
testAction(
|
2018-04-13 23:49:11 -04:00
|
|
|
unstageAllChanges,
|
2018-03-29 10:16:19 -04:00
|
|
|
null,
|
|
|
|
store.state,
|
|
|
|
[
|
|
|
|
{ type: types.UNSTAGE_CHANGE, payload: store.state.stagedFiles[0].path },
|
|
|
|
{ type: types.UNSTAGE_CHANGE, payload: store.state.stagedFiles[1].path },
|
|
|
|
],
|
2018-04-05 05:46:19 -04:00
|
|
|
[],
|
2018-03-29 10:16:19 -04:00
|
|
|
done,
|
|
|
|
);
|
2018-03-21 06:05:08 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-20 10:12:48 -04:00
|
|
|
describe('updateViewer', () => {
|
|
|
|
it('updates viewer state', done => {
|
|
|
|
store
|
|
|
|
.dispatch('updateViewer', 'diff')
|
|
|
|
.then(() => {
|
|
|
|
expect(store.state.viewer).toBe('diff');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-04-18 06:29:40 -04:00
|
|
|
|
|
|
|
describe('updateActivityBarView', () => {
|
|
|
|
it('commits UPDATE_ACTIVITY_BAR_VIEW', done => {
|
|
|
|
testAction(
|
2018-04-25 05:38:06 -04:00
|
|
|
updateActivityBarView,
|
2018-04-18 06:29:40 -04:00
|
|
|
'test',
|
|
|
|
{},
|
|
|
|
[{ type: 'UPDATE_ACTIVITY_BAR_VIEW', payload: 'test' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setEmptyStateSvgs', () => {
|
|
|
|
it('commits setEmptyStateSvgs', done => {
|
|
|
|
testAction(
|
2018-04-25 05:38:06 -04:00
|
|
|
setEmptyStateSvgs,
|
2018-04-18 06:29:40 -04:00
|
|
|
'svg',
|
|
|
|
{},
|
|
|
|
[{ type: 'SET_EMPTY_STATE_SVGS', payload: 'svg' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
describe('updateTempFlagForEntry', () => {
|
|
|
|
it('commits UPDATE_TEMP_FLAG', done => {
|
|
|
|
const f = {
|
|
|
|
...file(),
|
|
|
|
path: 'test',
|
|
|
|
tempFile: true,
|
|
|
|
};
|
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
|
|
|
|
testAction(
|
2018-04-25 05:51:41 -04:00
|
|
|
updateTempFlagForEntry,
|
2018-04-19 10:51:43 -04:00
|
|
|
{ file: f, tempFile: false },
|
2018-04-10 06:10:16 -04:00
|
|
|
store.state,
|
|
|
|
[{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('commits UPDATE_TEMP_FLAG and dispatches for parent', done => {
|
|
|
|
const parent = {
|
|
|
|
...file(),
|
|
|
|
path: 'testing',
|
|
|
|
};
|
|
|
|
const f = {
|
|
|
|
...file(),
|
|
|
|
path: 'test',
|
|
|
|
parentPath: 'testing',
|
|
|
|
};
|
|
|
|
store.state.entries[parent.path] = parent;
|
|
|
|
store.state.entries[f.path] = f;
|
|
|
|
|
|
|
|
testAction(
|
2018-04-25 05:51:41 -04:00
|
|
|
updateTempFlagForEntry,
|
2018-04-19 10:51:43 -04:00
|
|
|
{ file: f, tempFile: false },
|
2018-04-10 06:10:16 -04:00
|
|
|
store.state,
|
|
|
|
[{ type: 'UPDATE_TEMP_FLAG', payload: { path: f.path, tempFile: false } }],
|
2018-04-19 10:51:43 -04:00
|
|
|
[{ type: 'updateTempFlagForEntry', payload: { file: parent, tempFile: false } }],
|
2018-04-10 06:10:16 -04:00
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-04-25 05:51:41 -04:00
|
|
|
|
2018-04-18 06:29:40 -04:00
|
|
|
describe('setCurrentBranchId', () => {
|
|
|
|
it('commits setCurrentBranchId', done => {
|
|
|
|
testAction(
|
2018-04-25 05:38:06 -04:00
|
|
|
setCurrentBranchId,
|
2018-04-18 06:29:40 -04:00
|
|
|
'branchId',
|
|
|
|
{},
|
|
|
|
[{ type: 'SET_CURRENT_BRANCH', payload: 'branchId' }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-04-25 05:38:06 -04:00
|
|
|
|
2018-04-13 05:43:16 -04:00
|
|
|
describe('toggleFileFinder', () => {
|
|
|
|
it('commits TOGGLE_FILE_FINDER', done => {
|
|
|
|
testAction(
|
2018-04-24 12:38:48 -04:00
|
|
|
toggleFileFinder,
|
2018-04-13 05:43:16 -04:00
|
|
|
true,
|
|
|
|
null,
|
|
|
|
[{ type: 'TOGGLE_FILE_FINDER', payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
});
|