diff options
author | Natalia Tepluhina <ntepluhina@gitlab.com> | 2019-03-04 11:39:55 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-03-04 11:39:55 +0000 |
commit | d9ba40aa044e63b95de2e1dae1d54da7f500cd6b (patch) | |
tree | 4001b7228e99c23d0a5a27f04c29d36b566d0206 /spec/javascripts/ide | |
parent | c082ce08c842516c0c3fc85bbf0167281db201c6 (diff) | |
download | gitlab-ce-d9ba40aa044e63b95de2e1dae1d54da7f500cd6b.tar.gz |
Fixed mutation for root
- fixed test spec
- added warning only if file is deleted
Diffstat (limited to 'spec/javascripts/ide')
-rw-r--r-- | spec/javascripts/ide/components/new_dropdown/modal_spec.js | 55 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions_spec.js | 28 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/mutations_spec.js | 14 |
3 files changed, 88 insertions, 9 deletions
diff --git a/spec/javascripts/ide/components/new_dropdown/modal_spec.js b/spec/javascripts/ide/components/new_dropdown/modal_spec.js index d94cc1a8faa..d1a0964ccdd 100644 --- a/spec/javascripts/ide/components/new_dropdown/modal_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/modal_spec.js @@ -18,6 +18,9 @@ describe('new file modal component', () => { store.state.entryModal = { type, path: '', + entry: { + path: '', + }, }; vm = createComponentWithStore(Component, store).$mount(); @@ -74,6 +77,7 @@ describe('new file modal component', () => { entry: { name: 'test', type: 'blob', + path: 'test-path', }, }; @@ -97,7 +101,7 @@ describe('new file modal component', () => { describe('entryName', () => { it('returns entries name', () => { - expect(vm.entryName).toBe('test'); + expect(vm.entryName).toBe('test-path'); }); it('updated name', () => { @@ -107,4 +111,53 @@ describe('new file modal component', () => { }); }); }); + + describe('submitForm', () => { + it('throws an error when target entry exists', () => { + const store = createStore(); + store.state.entryModal = { + type: 'rename', + path: 'test-path/test', + entry: { + name: 'test', + type: 'blob', + path: 'test-path/test', + }, + }; + store.state.entries = { + 'test-path/test': { + name: 'test', + deleted: false, + }, + }; + + vm = createComponentWithStore(Component, store).$mount(); + const flashSpy = spyOnDependency(modal, 'flash'); + vm.submitForm(); + + expect(flashSpy).toHaveBeenCalled(); + }); + + it('calls createTempEntry when target path does not exist', () => { + const store = createStore(); + store.state.entryModal = { + type: 'rename', + path: 'test-path/test', + entry: { + name: 'test', + type: 'blob', + path: 'test-path1/test', + }, + }; + + vm = createComponentWithStore(Component, store).$mount(); + spyOn(vm, 'createTempEntry').and.callFake(() => Promise.resolve()); + vm.submitForm(); + + expect(vm.createTempEntry).toHaveBeenCalledWith({ + name: 'test-path1', + type: 'tree', + }); + }); + }); }); diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js index df291ade3f7..0b5587d02ae 100644 --- a/spec/javascripts/ide/stores/actions_spec.js +++ b/spec/javascripts/ide/stores/actions_spec.js @@ -499,12 +499,12 @@ describe('Multi-file store actions', () => { testAction( renameEntry, - { path: 'test', name: 'new-name' }, + { path: 'test', name: 'new-name', entryPath: null, parentPath: 'parent-path' }, store.state, [ { type: types.RENAME_ENTRY, - payload: { path: 'test', name: 'new-name', entryPath: null }, + payload: { path: 'test', name: 'new-name', entryPath: null, parentPath: 'parent-path' }, }, ], [{ type: 'deleteEntry', payload: 'test' }], @@ -527,17 +527,33 @@ describe('Multi-file store actions', () => { testAction( renameEntry, - { path: 'test', name: 'new-name' }, + { path: 'test', name: 'new-name', parentPath: 'parent-path' }, store.state, [ { type: types.RENAME_ENTRY, - payload: { path: 'test', name: 'new-name', entryPath: null }, + payload: { path: 'test', name: 'new-name', entryPath: null, parentPath: 'parent-path' }, }, ], [ - { type: 'renameEntry', payload: { path: 'test', name: 'new-name', entryPath: 'tree-1' } }, - { type: 'renameEntry', payload: { path: 'test', name: 'new-name', entryPath: 'tree-2' } }, + { + type: 'renameEntry', + payload: { + path: 'test', + name: 'new-name', + entryPath: 'tree-1', + parentPath: 'parent-path/new-name', + }, + }, + { + type: 'renameEntry', + payload: { + path: 'test', + name: 'new-name', + entryPath: 'tree-2', + parentPath: 'parent-path/new-name', + }, + }, { type: 'deleteEntry', payload: 'test' }, ], done, diff --git a/spec/javascripts/ide/stores/mutations_spec.js b/spec/javascripts/ide/stores/mutations_spec.js index 41dd3d3c67f..5ee098bf17f 100644 --- a/spec/javascripts/ide/stores/mutations_spec.js +++ b/spec/javascripts/ide/stores/mutations_spec.js @@ -298,7 +298,12 @@ describe('Multi-file store mutations', () => { }); it('creates new renamed entry', () => { - mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); + mutations.RENAME_ENTRY(localState, { + path: 'oldPath', + name: 'newPath', + entryPath: null, + parentPath: '', + }); expect(localState.entries.newPath).toEqual({ ...localState.entries.oldPath, @@ -335,7 +340,12 @@ describe('Multi-file store mutations', () => { ...file(), }; - mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); + mutations.RENAME_ENTRY(localState, { + path: 'oldPath', + name: 'newPath', + entryPath: null, + parentPath: 'parentPath', + }); expect(localState.entries.parentPath.tree.length).toBe(1); }); |