| ... | ... | @@ -18,19 +18,19 @@ import axios from '~/lib/utils/axios_utils'; |
|
|
|
import { createStore } from '~/ide/stores';
|
|
|
|
import * as types from '~/ide/stores/mutation_types';
|
|
|
|
import router from '~/ide/ide_router';
|
|
|
|
import { resetStore, file } from '../helpers';
|
|
|
|
import { file } from '../helpers';
|
|
|
|
import testAction from '../../helpers/vuex_action_helper';
|
|
|
|
import eventHub from '~/ide/eventhub';
|
|
|
|
|
|
|
|
const store = createStore();
|
|
|
|
|
|
|
|
describe('Multi-file store actions', () => {
|
|
|
|
let store;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(router, 'push');
|
|
|
|
});
|
|
|
|
store = createStore();
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetStore(store);
|
|
|
|
spyOn(store, 'commit').and.callThrough();
|
|
|
|
spyOn(store, 'dispatch').and.callThrough();
|
|
|
|
spyOn(router, 'push');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('redirectToUrl', () => {
|
| ... | ... | @@ -390,58 +390,82 @@ describe('Multi-file store actions', () => { |
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stage/unstageAllChanges', () => {
|
|
|
|
let file1;
|
|
|
|
let file2;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
file1 = { ...file('test'), content: 'changed test', raw: 'test' };
|
|
|
|
file2 = { ...file('test2'), content: 'changed test2', raw: 'test2' };
|
|
|
|
|
|
|
|
store.state.openFiles = [file1];
|
|
|
|
store.state.changedFiles = [file1];
|
|
|
|
store.state.stagedFiles = [{ ...file2, content: 'staged test' }];
|
|
|
|
|
|
|
|
store.state.entries = {
|
|
|
|
[file1.path]: { ...file1 },
|
|
|
|
[file2.path]: { ...file2 },
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stageAllChanges', () => {
|
|
|
|
it('adds all files from changedFiles to stagedFiles', done => {
|
|
|
|
const openFile = { ...file(), path: 'test' };
|
|
|
|
it('adds all files from changedFiles to stagedFiles', () => {
|
|
|
|
stageAllChanges(store);
|
|
|
|
|
|
|
|
store.state.openFiles.push(openFile);
|
|
|
|
store.state.stagedFiles.push(openFile);
|
|
|
|
store.state.changedFiles.push(openFile, file('new'));
|
|
|
|
expect(store.commit.calls.allArgs()).toEqual([
|
|
|
|
[types.SET_LAST_COMMIT_MSG, ''],
|
|
|
|
[types.STAGE_CHANGE, jasmine.objectContaining({ path: file1.path })],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
stageAllChanges,
|
|
|
|
null,
|
|
|
|
store.state,
|
|
|
|
[
|
|
|
|
{ type: types.SET_LAST_COMMIT_MSG, payload: '' },
|
|
|
|
{ type: types.STAGE_CHANGE, payload: store.state.changedFiles[0].path },
|
|
|
|
{ type: types.STAGE_CHANGE, payload: store.state.changedFiles[1].path },
|
|
|
|
],
|
|
|
|
it('opens pending tab if a change exists in that file', () => {
|
|
|
|
stageAllChanges(store);
|
|
|
|
|
|
|
|
expect(store.dispatch.calls.allArgs()).toEqual([
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'openPendingTab',
|
|
|
|
payload: { file: openFile, keyPrefix: 'staged' },
|
|
|
|
},
|
|
|
|
'openPendingTab',
|
|
|
|
{ file: { ...file1, staged: true, changed: true }, keyPrefix: 'staged' },
|
|
|
|
],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not open pending tab if no change exists in that file', () => {
|
|
|
|
store.state.entries[file1.path].content = 'test';
|
|
|
|
store.state.stagedFiles = [file1];
|
|
|
|
store.state.changedFiles = [store.state.entries[file1.path]];
|
|
|
|
|
|
|
|
stageAllChanges(store);
|
|
|
|
|
|
|
|
expect(store.dispatch).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unstageAllChanges', () => {
|
|
|
|
it('removes all files from stagedFiles after unstaging', done => {
|
|
|
|
const openFile = { ...file(), path: 'test' };
|
|
|
|
it('removes all files from stagedFiles after unstaging', () => {
|
|
|
|
unstageAllChanges(store);
|
|
|
|
|
|
|
|
store.state.openFiles.push(openFile);
|
|
|
|
store.state.changedFiles.push(openFile);
|
|
|
|
store.state.stagedFiles.push(openFile, file('new'));
|
|
|
|
expect(store.commit.calls.allArgs()).toEqual([
|
|
|
|
[types.UNSTAGE_CHANGE, jasmine.objectContaining({ path: file2.path })],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
unstageAllChanges,
|
|
|
|
null,
|
|
|
|
store.state,
|
|
|
|
[
|
|
|
|
{ type: types.UNSTAGE_CHANGE, payload: store.state.stagedFiles[0].path },
|
|
|
|
{ type: types.UNSTAGE_CHANGE, payload: store.state.stagedFiles[1].path },
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'openPendingTab',
|
|
|
|
payload: { file: openFile, keyPrefix: 'unstaged' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
it('opens pending tab if a change exists in that file', () => {
|
|
|
|
unstageAllChanges(store);
|
|
|
|
|
|
|
|
expect(store.dispatch.calls.allArgs()).toEqual([
|
|
|
|
['openPendingTab', { file: file1, keyPrefix: 'unstaged' }],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not open pending tab if no change exists in that file', () => {
|
|
|
|
store.state.entries[file1.path].content = 'test';
|
|
|
|
store.state.stagedFiles = [file1];
|
|
|
|
store.state.changedFiles = [store.state.entries[file1.path]];
|
|
|
|
|
|
|
|
unstageAllChanges(store);
|
|
|
|
|
|
|
|
expect(store.dispatch).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
| ... | ... | @@ -752,10 +776,6 @@ describe('Multi-file store actions', () => { |
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
resetStore(store);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('by default renames an entry and adds to changed', done => {
|
|
|
|
testAction(
|
|
|
|
renameEntry,
|
| ... | ... | @@ -966,7 +986,10 @@ describe('Multi-file store actions', () => { |
|
|
|
|
|
|
|
describe('error', () => {
|
|
|
|
let dispatch;
|
|
|
|
const callParams = [
|
|
|
|
let callParams;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
callParams = [
|
|
|
|
{
|
|
|
|
commit() {},
|
|
|
|
state: store.state,
|
| ... | ... | @@ -976,8 +999,6 @@ describe('Multi-file store actions', () => { |
|
|
|
branchId: 'master-testing',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
dispatch = jasmine.createSpy('dispatchSpy');
|
|
|
|
document.body.innerHTML += '<div class="flash-container"></div>';
|
|
|
|
});
|
| ... | ... | |
| ... | ... | |