diff options
author | Phil Hughes <me@iamphill.com> | 2018-07-26 17:56:56 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-07-26 17:56:56 +0300 |
commit | cded268ca1d49fe93b8e0940586e9792347c88c3 (patch) | |
tree | 9d84a5e8ae38e53514b6ab1f4e99d38ddf2fe138 /spec/javascripts | |
parent | 8873840839811948b2f29175177b91bcf806a3f8 (diff) |
Enable deleting files in the Web IDE
Diffstat (limited to 'spec/javascripts')
11 files changed, 260 insertions, 27 deletions
diff --git a/spec/javascripts/ide/components/changed_file_icon_spec.js b/spec/javascripts/ide/components/changed_file_icon_spec.js index 541864e912e..7308219f705 100644 --- a/spec/javascripts/ide/components/changed_file_icon_spec.js +++ b/spec/javascripts/ide/components/changed_file_icon_spec.js @@ -33,14 +33,14 @@ describe('IDE changed file icon', () => { }); describe('changedIconClass', () => { - it('includes multi-file-modified when not a temp file', () => { - expect(vm.changedIconClass).toContain('multi-file-modified'); + it('includes ide-file-modified when not a temp file', () => { + expect(vm.changedIconClass).toContain('ide-file-modified'); }); - it('includes multi-file-addition when a temp file', () => { + it('includes ide-file-addition when a temp file', () => { vm.file.tempFile = true; - expect(vm.changedIconClass).toContain('multi-file-addition'); + expect(vm.changedIconClass).toContain('ide-file-addition'); }); }); }); diff --git a/spec/javascripts/ide/components/commit_sidebar/list_item_spec.js b/spec/javascripts/ide/components/commit_sidebar/list_item_spec.js index bf96170f703..41d8bfff7e7 100644 --- a/spec/javascripts/ide/components/commit_sidebar/list_item_spec.js +++ b/spec/javascripts/ide/components/commit_sidebar/list_item_spec.js @@ -76,17 +76,29 @@ describe('Multi-file editor commit sidebar list item', () => { expect(vm.iconName).toBe('file-addition'); }); + + it('returns deletion', () => { + f.deleted = true; + + expect(vm.iconName).toBe('file-deletion'); + }); }); describe('iconClass', () => { it('returns modified when not a tempFile', () => { - expect(vm.iconClass).toContain('multi-file-modified'); + expect(vm.iconClass).toContain('ide-file-modified'); }); it('returns addition when not a tempFile', () => { f.tempFile = true; - expect(vm.iconClass).toContain('multi-file-addition'); + expect(vm.iconClass).toContain('ide-file-addition'); + }); + + it('returns deletion', () => { + f.deleted = true; + + expect(vm.iconClass).toContain('ide-file-deletion'); }); }); }); diff --git a/spec/javascripts/ide/components/new_dropdown/index_spec.js b/spec/javascripts/ide/components/new_dropdown/index_spec.js index 4d704b80209..092c405a70b 100644 --- a/spec/javascripts/ide/components/new_dropdown/index_spec.js +++ b/spec/javascripts/ide/components/new_dropdown/index_spec.js @@ -14,6 +14,7 @@ describe('new dropdown component', () => { branch: 'master', path: '', mouseOver: false, + type: 'tree', }); vm.$store.state.currentProjectId = 'abcproject'; @@ -67,4 +68,14 @@ describe('new dropdown component', () => { }); }); }); + + describe('delete entry', () => { + it('calls delete action', () => { + spyOn(vm, 'deleteEntry'); + + vm.$el.querySelectorAll('.dropdown-menu button')[3].click(); + + expect(vm.deleteEntry).toHaveBeenCalledWith(''); + }); + }); }); diff --git a/spec/javascripts/ide/components/repo_editor_spec.js b/spec/javascripts/ide/components/repo_editor_spec.js index 2256deb7dac..0e2e246defd 100644 --- a/spec/javascripts/ide/components/repo_editor_spec.js +++ b/spec/javascripts/ide/components/repo_editor_spec.js @@ -1,5 +1,6 @@ import Vue from 'vue'; import MockAdapter from 'axios-mock-adapter'; +import '~/behaviors/markdown/render_gfm'; import axios from '~/lib/utils/axios_utils'; import store from '~/ide/stores'; import repoEditor from '~/ide/components/repo_editor.vue'; @@ -25,6 +26,8 @@ describe('RepoEditor', () => { vm.$store.state.openFiles.push(f); Vue.set(vm.$store.state.entries, f.path, f); + spyOn(vm, 'getFileData').and.returnValue(Promise.resolve()); + vm.$mount(); Vue.nextTick(() => setTimeout(done)); diff --git a/spec/javascripts/ide/components/repo_file_spec.js b/spec/javascripts/ide/components/repo_file_spec.js index 156233653ab..f99d1f9890a 100644 --- a/spec/javascripts/ide/components/repo_file_spec.js +++ b/spec/javascripts/ide/components/repo_file_spec.js @@ -91,25 +91,6 @@ describe('RepoFile', () => { done(); }); }); - - it('disables action dropdown', done => { - createComponent({ - file: { - ...file('t4'), - type: 'tree', - branchId: 'master', - projectId: 'project', - }, - level: 0, - disableActionDropdown: true, - }); - - setTimeout(() => { - expect(vm.$el.querySelector('.ide-new-btn')).toBeNull(); - - done(); - }); - }); }); describe('locked file', () => { diff --git a/spec/javascripts/ide/components/repo_tab_spec.js b/spec/javascripts/ide/components/repo_tab_spec.js index fc0695a4263..278a0753322 100644 --- a/spec/javascripts/ide/components/repo_tab_spec.js +++ b/spec/javascripts/ide/components/repo_tab_spec.js @@ -93,13 +93,13 @@ describe('RepoTab', () => { Vue.nextTick() .then(() => { - expect(vm.$el.querySelector('.multi-file-modified')).toBeNull(); + expect(vm.$el.querySelector('.ide-file-modified')).toBeNull(); vm.$el.dispatchEvent(new Event('mouseout')); }) .then(Vue.nextTick) .then(() => { - expect(vm.$el.querySelector('.multi-file-modified')).not.toBeNull(); + expect(vm.$el.querySelector('.ide-file-modified')).not.toBeNull(); done(); }) diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js index 8b665a6d79e..792a716565c 100644 --- a/spec/javascripts/ide/stores/actions_spec.js +++ b/spec/javascripts/ide/stores/actions_spec.js @@ -7,6 +7,7 @@ import actions, { updateActivityBarView, updateTempFlagForEntry, setErrorMessage, + deleteEntry, } from '~/ide/stores/actions'; import store from '~/ide/stores'; import * as types from '~/ide/stores/mutation_types'; @@ -457,4 +458,19 @@ describe('Multi-file store actions', () => { ); }); }); + + describe('deleteEntry', () => { + it('commits entry deletion', done => { + store.state.entries.path = 'testing'; + + testAction( + deleteEntry, + 'path', + store.state, + [{ type: types.DELETE_ENTRY, payload: 'path' }], + [{ type: 'burstUnusedSeal' }, { type: 'closeFile', payload: store.state.entries.path }], + done, + ); + }); + }); }); diff --git a/spec/javascripts/ide/stores/modules/commit/getters_spec.js b/spec/javascripts/ide/stores/modules/commit/getters_spec.js index 44c941d6dbb..3f4bf407a1f 100644 --- a/spec/javascripts/ide/stores/modules/commit/getters_spec.js +++ b/spec/javascripts/ide/stores/modules/commit/getters_spec.js @@ -123,6 +123,22 @@ describe('IDE commit module getters', () => { 'Update test-file, index.js files', ); }); + + it('returns commitMessage with deleted files', () => { + rootState[key].push( + { + path: 'test-file', + deleted: true, + }, + { + path: 'index.js', + }, + ); + + expect(getters.preBuiltCommitMessage(state, null, rootState)).toBe( + 'Update index.js\nDeleted test-file', + ); + }); }); }); }); diff --git a/spec/javascripts/ide/stores/mutations/file_spec.js b/spec/javascripts/ide/stores/mutations/file_spec.js index 52f83be8e8c..efd0d86552b 100644 --- a/spec/javascripts/ide/stores/mutations/file_spec.js +++ b/spec/javascripts/ide/stores/mutations/file_spec.js @@ -94,6 +94,35 @@ describe('IDE store file mutations', () => { expect(localFile.raw).toBe('testing'); }); + + it('adds raw data to open pending file', () => { + localState.openFiles.push({ + ...localFile, + pending: true, + }); + + mutations.SET_FILE_RAW_DATA(localState, { + file: localFile, + raw: 'testing', + }); + + expect(localState.openFiles[0].raw).toBe('testing'); + }); + + it('does not add raw data to open pending tempFile file', () => { + localState.openFiles.push({ + ...localFile, + pending: true, + tempFile: true, + }); + + mutations.SET_FILE_RAW_DATA(localState, { + file: localFile, + raw: 'testing', + }); + + expect(localState.openFiles[0].raw).not.toBe('testing'); + }); }); describe('SET_FILE_BASE_RAW_DATA', () => { @@ -205,6 +234,11 @@ describe('IDE store file mutations', () => { beforeEach(() => { localFile.content = 'test'; localFile.changed = true; + localState.currentProjectId = 'gitlab-ce'; + localState.currentBranchId = 'master'; + localState.trees['gitlab-ce/master'] = { + tree: [], + }; }); it('resets content and changed', () => { @@ -213,6 +247,36 @@ describe('IDE store file mutations', () => { expect(localFile.content).toBe(''); expect(localFile.changed).toBeFalsy(); }); + + it('adds to root tree if deleted', () => { + localFile.deleted = true; + + mutations.DISCARD_FILE_CHANGES(localState, localFile.path); + + expect(localState.trees['gitlab-ce/master'].tree).toEqual([ + { + ...localFile, + deleted: false, + }, + ]); + }); + + it('adds to parent tree if deleted', () => { + localFile.deleted = true; + localFile.parentPath = 'parentPath'; + localState.entries.parentPath = { + tree: [], + }; + + mutations.DISCARD_FILE_CHANGES(localState, localFile.path); + + expect(localState.entries.parentPath.tree).toEqual([ + { + ...localFile, + deleted: false, + }, + ]); + }); }); describe('ADD_FILE_TO_CHANGED', () => { diff --git a/spec/javascripts/ide/stores/mutations_spec.js b/spec/javascripts/ide/stores/mutations_spec.js index 98016f593aa..8b5f2d0bdfa 100644 --- a/spec/javascripts/ide/stores/mutations_spec.js +++ b/spec/javascripts/ide/stores/mutations_spec.js @@ -156,4 +156,61 @@ describe('Multi-file store mutations', () => { expect(localState.errorMessage).toBe('error'); }); }); + + describe('DELETE_ENTRY', () => { + beforeEach(() => { + localState.currentProjectId = 'gitlab-ce'; + localState.currentBranchId = 'master'; + localState.trees['gitlab-ce/master'] = { + tree: [], + }; + }); + + it('sets deleted flag', () => { + localState.entries.filePath = { + deleted: false, + }; + + mutations.DELETE_ENTRY(localState, 'filePath'); + + expect(localState.entries.filePath.deleted).toBe(true); + }); + + it('removes from root tree', () => { + localState.entries.filePath = { + path: 'filePath', + deleted: false, + }; + localState.trees['gitlab-ce/master'].tree.push(localState.entries.filePath); + + mutations.DELETE_ENTRY(localState, 'filePath'); + + expect(localState.trees['gitlab-ce/master'].tree).toEqual([]); + }); + + it('removes from parent tree', () => { + localState.entries.filePath = { + path: 'filePath', + deleted: false, + parentPath: 'parentPath', + }; + localState.entries.parentPath = { + tree: [localState.entries.filePath], + }; + + mutations.DELETE_ENTRY(localState, 'filePath'); + + expect(localState.entries.parentPath.tree).toEqual([]); + }); + + it('adds to changedFiles', () => { + localState.entries.filePath = { + deleted: false, + }; + + mutations.DELETE_ENTRY(localState, 'filePath'); + + expect(localState.changedFiles).toEqual([localState.entries.filePath]); + }); + }); }); diff --git a/spec/javascripts/ide/stores/utils_spec.js b/spec/javascripts/ide/stores/utils_spec.js index 6c5980cfae4..89db50b8874 100644 --- a/spec/javascripts/ide/stores/utils_spec.js +++ b/spec/javascripts/ide/stores/utils_spec.js @@ -86,6 +86,11 @@ describe('Multi-file store utils', () => { base64: true, lastCommitSha: '123456789', }, + { + ...file('deletedFile'), + path: 'deletedFile', + deleted: true, + }, ], currentBranchId: 'master', }; @@ -115,6 +120,13 @@ describe('Multi-file store utils', () => { encoding: 'base64', last_commit_id: '123456789', }, + { + action: 'delete', + file_path: 'deletedFile', + content: '', + encoding: 'text', + last_commit_id: undefined, + }, ], start_branch: undefined, }); @@ -173,4 +185,65 @@ describe('Multi-file store utils', () => { }); }); }); + + describe('commitActionForFile', () => { + it('returns deleted for deleted file', () => { + expect(utils.commitActionForFile({ deleted: true })).toBe('delete'); + }); + + it('returns create for tempFile', () => { + expect(utils.commitActionForFile({ tempFile: true })).toBe('create'); + }); + + it('returns update by default', () => { + expect(utils.commitActionForFile({})).toBe('update'); + }); + }); + + describe('getCommitFiles', () => { + it('returns flattened list of files and folders', () => { + const files = [ + { + path: 'a', + type: 'blob', + deleted: true, + }, + { + path: 'b', + type: 'tree', + deleted: true, + tree: [ + { + path: 'c', + type: 'blob', + }, + { + path: 'd', + type: 'blob', + }, + ], + }, + ]; + + const flattendFiles = utils.getCommitFiles(files); + + expect(flattendFiles).toEqual([ + { + path: 'a', + type: 'blob', + deleted: true, + }, + { + path: 'c', + type: 'blob', + deleted: true, + }, + { + path: 'd', + type: 'blob', + deleted: true, + }, + ]); + }); + }); }); |