diff options
author | Denys Mishunov <dmishunov@gitlab.com> | 2019-07-02 11:12:16 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-07-02 11:12:16 +0000 |
commit | 5a7834e5a91549b5ecb8890a718efa93dd61ae7a (patch) | |
tree | b65ffc957ffc3024734bff752e426cd8757c1f6c /spec/javascripts | |
parent | c2118657dbe7728a751f29767cc89b4a80f39b92 (diff) | |
download | gitlab-ce-5a7834e5a91549b5ecb8890a718efa93dd61ae7a.tar.gz |
Allow adding new entries to existing path
If an entry has been removed from the tree and later, during the same
session, a user is trying to add a new item with the same name/path we
should allow for that as long as the original entry is marked with
`deleted`.
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/ide/stores/actions_spec.js | 43 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/mutations/file_spec.js | 13 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/mutations_spec.js | 68 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/utils_spec.js | 26 |
4 files changed, 139 insertions, 11 deletions
diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js index 2d105103c1c..8504fb3f42b 100644 --- a/spec/javascripts/ide/stores/actions_spec.js +++ b/spec/javascripts/ide/stores/actions_spec.js @@ -10,6 +10,7 @@ import actions, { deleteEntry, renameEntry, getBranchData, + createTempEntry, } from '~/ide/stores/actions'; import axios from '~/lib/utils/axios_utils'; import store from '~/ide/stores'; @@ -247,18 +248,30 @@ describe('Multi-file store actions', () => { }); it('sets tmp file as active', done => { - store - .dispatch('createTempEntry', { + testAction( + createTempEntry, + { name: 'test', branchId: 'mybranch', type: 'blob', - }) - .then(f => { - expect(f.active).toBeTruthy(); - - done(); - }) - .catch(done.fail); + }, + store.state, + [ + { type: types.CREATE_TMP_ENTRY, payload: jasmine.any(Object) }, + { type: types.TOGGLE_FILE_OPEN, payload: 'test' }, + { type: types.ADD_FILE_TO_CHANGED, payload: 'test' }, + ], + [ + { + type: 'setFileActive', + payload: 'test', + }, + { + type: 'triggerFilesChange', + }, + ], + done, + ); }); it('creates flash message if file already exists', done => { @@ -488,7 +501,11 @@ describe('Multi-file store actions', () => { 'path', store.state, [{ type: types.DELETE_ENTRY, payload: 'path' }], - [{ type: 'burstUnusedSeal' }, { type: 'triggerFilesChange' }], + [ + { type: 'burstUnusedSeal' }, + { type: 'stageChange', payload: 'path' }, + { type: 'triggerFilesChange' }, + ], done, ); }); @@ -515,7 +532,11 @@ describe('Multi-file store actions', () => { 'testFolder/entry-to-delete', store.state, [{ type: types.DELETE_ENTRY, payload: 'testFolder/entry-to-delete' }], - [{ type: 'burstUnusedSeal' }, { type: 'triggerFilesChange' }], + [ + { type: 'burstUnusedSeal' }, + { type: 'stageChange', payload: 'testFolder/entry-to-delete' }, + { type: 'triggerFilesChange' }, + ], done, ); }); diff --git a/spec/javascripts/ide/stores/mutations/file_spec.js b/spec/javascripts/ide/stores/mutations/file_spec.js index efd0d86552b..18ee4330f69 100644 --- a/spec/javascripts/ide/stores/mutations/file_spec.js +++ b/spec/javascripts/ide/stores/mutations/file_spec.js @@ -315,6 +315,19 @@ describe('IDE store file mutations', () => { expect(localState.stagedFiles.length).toBe(1); expect(localState.stagedFiles[0].raw).toEqual('testing 123'); }); + + it('adds already-staged file to `replacedFiles`', () => { + localFile.raw = 'already-staged'; + + mutations.STAGE_CHANGE(localState, localFile.path); + + localFile.raw = 'testing 123'; + + mutations.STAGE_CHANGE(localState, localFile.path); + + expect(localState.replacedFiles.length).toBe(1); + expect(localState.replacedFiles[0].raw).toEqual('already-staged'); + }); }); describe('UNSTAGE_CHANGE', () => { diff --git a/spec/javascripts/ide/stores/mutations_spec.js b/spec/javascripts/ide/stores/mutations_spec.js index 460c5b01081..2470c99e300 100644 --- a/spec/javascripts/ide/stores/mutations_spec.js +++ b/spec/javascripts/ide/stores/mutations_spec.js @@ -79,6 +79,16 @@ describe('Multi-file store mutations', () => { }); }); + describe('CLEAR_REPLACED_FILES', () => { + it('clears replacedFiles array', () => { + localState.replacedFiles.push('a'); + + mutations.CLEAR_REPLACED_FILES(localState); + + expect(localState.replacedFiles.length).toBe(0); + }); + }); + describe('UPDATE_VIEWER', () => { it('sets viewer state', () => { mutations.UPDATE_VIEWER(localState, 'diff'); @@ -109,6 +119,62 @@ describe('Multi-file store mutations', () => { }); }); + describe('CREATE_TMP_ENTRY', () => { + beforeEach(() => { + localState.currentProjectId = 'gitlab-ce'; + localState.currentBranchId = 'master'; + localState.trees['gitlab-ce/master'] = { + tree: [], + }; + }); + + it('creates temp entry in the tree', () => { + const tmpFile = file('test'); + mutations.CREATE_TMP_ENTRY(localState, { + data: { + entries: { + test: { + ...tmpFile, + tempFile: true, + changed: true, + }, + }, + treeList: [tmpFile], + }, + projectId: 'gitlab-ce', + branchId: 'master', + }); + + expect(localState.trees['gitlab-ce/master'].tree.length).toEqual(1); + expect(localState.entries.test.tempFile).toEqual(true); + }); + + it('marks entry as replacing previous entry if the old one has been deleted', () => { + const tmpFile = file('test'); + localState.entries.test = { + ...tmpFile, + deleted: true, + }; + mutations.CREATE_TMP_ENTRY(localState, { + data: { + entries: { + test: { + ...tmpFile, + tempFile: true, + changed: true, + }, + }, + treeList: [tmpFile], + }, + projectId: 'gitlab-ce', + branchId: 'master', + }); + + expect(localState.trees['gitlab-ce/master'].tree.length).toEqual(1); + expect(localState.entries.test.replaces).toEqual(true); + }); + }); + describe('UPDATE_TEMP_FLAG', () => { beforeEach(() => { localState.entries.test = { @@ -252,6 +318,7 @@ describe('Multi-file store mutations', () => { permalink: `${gl.TEST_HOST}/testing-123`, commitsPath: `${gl.TEST_HOST}/testing-123`, blamePath: `${gl.TEST_HOST}/testing-123`, + replaces: true, }; localState.entries.test = f; localState.changedFiles.push(f); @@ -262,6 +329,7 @@ describe('Multi-file store mutations', () => { expect(f.permalink).toBe(`${gl.TEST_HOST}/test`); expect(f.commitsPath).toBe(`${gl.TEST_HOST}/test`); expect(f.blamePath).toBe(`${gl.TEST_HOST}/test`); + expect(f.replaces).toBe(false); }); }); diff --git a/spec/javascripts/ide/stores/utils_spec.js b/spec/javascripts/ide/stores/utils_spec.js index e3bf6d40245..bceb3a8db91 100644 --- a/spec/javascripts/ide/stores/utils_spec.js +++ b/spec/javascripts/ide/stores/utils_spec.js @@ -92,6 +92,16 @@ describe('Multi-file store utils', () => { path: 'deletedFile', deleted: true, }, + { + ...file('renamedFile'), + path: 'renamedFile', + prevPath: 'prevPath', + }, + { + ...file('replacingFile'), + path: 'replacingFile', + replaces: true, + }, ], currentBranchId: 'master', }; @@ -131,6 +141,22 @@ describe('Multi-file store utils', () => { last_commit_id: undefined, previous_path: undefined, }, + { + action: commitActionTypes.move, + file_path: 'renamedFile', + content: null, + encoding: 'text', + last_commit_id: undefined, + previous_path: 'prevPath', + }, + { + action: commitActionTypes.update, + file_path: 'replacingFile', + content: undefined, + encoding: 'text', + last_commit_id: undefined, + previous_path: undefined, + }, ], start_sha: undefined, }); |