summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/stores/actions_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/ide/stores/actions_spec.js')
-rw-r--r--spec/javascripts/ide/stores/actions_spec.js59
1 files changed, 57 insertions, 2 deletions
diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js
index 7e77b859fdd..0ee114cb70d 100644
--- a/spec/javascripts/ide/stores/actions_spec.js
+++ b/spec/javascripts/ide/stores/actions_spec.js
@@ -1,3 +1,4 @@
+import MockAdapter from 'axios-mock-adapter';
import actions, {
stageAllChanges,
unstageAllChanges,
@@ -11,6 +12,7 @@ import actions, {
renameEntry,
getBranchData,
createTempEntry,
+ discardAllChanges,
} from '~/ide/stores/actions';
import axios from '~/lib/utils/axios_utils';
import { createStore } from '~/ide/stores';
@@ -18,7 +20,6 @@ import * as types from '~/ide/stores/mutation_types';
import router from '~/ide/ide_router';
import { resetStore, file } from '../helpers';
import testAction from '../../helpers/vuex_action_helper';
-import MockAdapter from 'axios-mock-adapter';
import eventHub from '~/ide/eventhub';
const store = createStore();
@@ -60,8 +61,9 @@ describe('Multi-file store actions', () => {
});
describe('discardAllChanges', () => {
+ let f;
beforeEach(() => {
- const f = file('discardAll');
+ f = file('discardAll');
f.changed = true;
store.state.openFiles.push(f);
@@ -89,6 +91,59 @@ describe('Multi-file store actions', () => {
.then(done)
.catch(done.fail);
});
+
+ it('closes the temp file and deletes it if it was open', done => {
+ f.tempFile = true;
+
+ testAction(
+ discardAllChanges,
+ undefined,
+ store.state,
+ [{ type: types.REMOVE_ALL_CHANGES_FILES }],
+ [
+ { type: 'closeFile', payload: jasmine.objectContaining({ path: 'discardAll' }) },
+ { type: 'deleteEntry', payload: 'discardAll' },
+ ],
+ done,
+ );
+ });
+
+ it('renames the file to its original name and closes it if it was open', done => {
+ Object.assign(f, {
+ prevPath: 'parent/path/old_name',
+ prevName: 'old_name',
+ prevParentPath: 'parent/path',
+ });
+
+ testAction(
+ discardAllChanges,
+ undefined,
+ store.state,
+ [{ type: types.REMOVE_ALL_CHANGES_FILES }],
+ [
+ { type: 'closeFile', payload: jasmine.objectContaining({ path: 'discardAll' }) },
+ {
+ type: 'renameEntry',
+ payload: { path: 'discardAll', name: 'old_name', parentPath: 'parent/path' },
+ },
+ ],
+ done,
+ );
+ });
+
+ it('discards file changes on all other files', done => {
+ testAction(
+ discardAllChanges,
+ undefined,
+ store.state,
+ [
+ { type: types.DISCARD_FILE_CHANGES, payload: 'discardAll' },
+ { type: types.REMOVE_ALL_CHANGES_FILES },
+ ],
+ [],
+ done,
+ );
+ });
});
describe('closeAllFiles', () => {