diff options
author | Phil Hughes <me@iamphill.com> | 2019-01-16 15:17:10 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-02-05 11:29:49 +0000 |
commit | 6e5461d67f52cacc2c9ba408c8f6fddb1e9e417d (patch) | |
tree | 14fd11c8ca5dd257047f5c2997c33a9b36fe1931 /spec/javascripts/ide | |
parent | 55cb4bc9cafca0c838192b54f9daa4b2bc0b86b0 (diff) | |
download | gitlab-ce-6e5461d67f52cacc2c9ba408c8f6fddb1e9e417d.tar.gz |
Added fuzzy file finder to merge requests
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53304
Diffstat (limited to 'spec/javascripts/ide')
-rw-r--r-- | spec/javascripts/ide/components/file_finder/index_spec.js | 304 | ||||
-rw-r--r-- | spec/javascripts/ide/components/file_finder/item_spec.js | 140 | ||||
-rw-r--r-- | spec/javascripts/ide/components/ide_spec.js | 68 |
3 files changed, 0 insertions, 512 deletions
diff --git a/spec/javascripts/ide/components/file_finder/index_spec.js b/spec/javascripts/ide/components/file_finder/index_spec.js deleted file mode 100644 index 15ef8c31f91..00000000000 --- a/spec/javascripts/ide/components/file_finder/index_spec.js +++ /dev/null @@ -1,304 +0,0 @@ -import Vue from 'vue'; -import store from '~/ide/stores'; -import FindFileComponent from '~/ide/components/file_finder/index.vue'; -import { UP_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESC_KEY_CODE } from '~/lib/utils/keycodes'; -import router from '~/ide/ide_router'; -import { file, resetStore } from '../../helpers'; -import { mountComponentWithStore } from '../../../helpers/vue_mount_component_helper'; - -describe('IDE File finder item spec', () => { - const Component = Vue.extend(FindFileComponent); - let vm; - - beforeEach(done => { - setFixtures('<div id="app"></div>'); - - vm = mountComponentWithStore(Component, { - store, - el: '#app', - props: { - index: 0, - }, - }); - - setTimeout(done); - }); - - afterEach(() => { - vm.$destroy(); - - resetStore(vm.$store); - }); - - describe('with entries', () => { - beforeEach(done => { - Vue.set(vm.$store.state.entries, 'folder', { - ...file('folder'), - path: 'folder', - type: 'folder', - }); - - Vue.set(vm.$store.state.entries, 'index.js', { - ...file('index.js'), - path: 'index.js', - type: 'blob', - url: '/index.jsurl', - }); - - Vue.set(vm.$store.state.entries, 'component.js', { - ...file('component.js'), - path: 'component.js', - type: 'blob', - }); - - setTimeout(done); - }); - - it('renders list of blobs', () => { - expect(vm.$el.textContent).toContain('index.js'); - expect(vm.$el.textContent).not.toContain('folder'); - }); - - it('filters entries', done => { - vm.searchText = 'index'; - - vm.$nextTick(() => { - expect(vm.$el.textContent).toContain('index.js'); - expect(vm.$el.textContent).not.toContain('component.js'); - - done(); - }); - }); - - it('shows clear button when searchText is not empty', done => { - vm.searchText = 'index'; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.dropdown-input-clear').classList).toContain('show'); - expect(vm.$el.querySelector('.dropdown-input-search').classList).toContain('hidden'); - - done(); - }); - }); - - it('clear button resets searchText', done => { - vm.searchText = 'index'; - - vm.$nextTick() - .then(() => { - vm.$el.querySelector('.dropdown-input-clear').click(); - }) - .then(vm.$nextTick) - .then(() => { - expect(vm.searchText).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - - it('clear button focues search input', done => { - spyOn(vm.$refs.searchInput, 'focus'); - vm.searchText = 'index'; - - vm.$nextTick() - .then(() => { - vm.$el.querySelector('.dropdown-input-clear').click(); - }) - .then(vm.$nextTick) - .then(() => { - expect(vm.$refs.searchInput.focus).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - describe('listShowCount', () => { - it('returns 1 when no filtered entries exist', done => { - vm.searchText = 'testing 123'; - - vm.$nextTick(() => { - expect(vm.listShowCount).toBe(1); - - done(); - }); - }); - - it('returns entries length when not filtered', () => { - expect(vm.listShowCount).toBe(2); - }); - }); - - describe('listHeight', () => { - it('returns 55 when entries exist', () => { - expect(vm.listHeight).toBe(55); - }); - - it('returns 33 when entries dont exist', done => { - vm.searchText = 'testing 123'; - - vm.$nextTick(() => { - expect(vm.listHeight).toBe(33); - - done(); - }); - }); - }); - - describe('filteredBlobsLength', () => { - it('returns length of filtered blobs', done => { - vm.searchText = 'index'; - - vm.$nextTick(() => { - expect(vm.filteredBlobsLength).toBe(1); - - done(); - }); - }); - }); - - describe('watches', () => { - describe('searchText', () => { - it('resets focusedIndex when updated', done => { - vm.focusedIndex = 1; - vm.searchText = 'test'; - - vm.$nextTick(() => { - expect(vm.focusedIndex).toBe(0); - - done(); - }); - }); - }); - - describe('fileFindVisible', () => { - it('returns searchText when false', done => { - vm.searchText = 'test'; - vm.$store.state.fileFindVisible = true; - - vm.$nextTick() - .then(() => { - vm.$store.state.fileFindVisible = false; - }) - .then(vm.$nextTick) - .then(() => { - expect(vm.searchText).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - - describe('openFile', () => { - beforeEach(() => { - spyOn(router, 'push'); - spyOn(vm, 'toggleFileFinder'); - }); - - it('closes file finder', () => { - vm.openFile(vm.$store.state.entries['index.js']); - - expect(vm.toggleFileFinder).toHaveBeenCalled(); - }); - - it('pushes to router', () => { - vm.openFile(vm.$store.state.entries['index.js']); - - expect(router.push).toHaveBeenCalledWith('/project/index.jsurl'); - }); - }); - - describe('onKeyup', () => { - it('opens file on enter key', done => { - const event = new CustomEvent('keyup'); - event.keyCode = ENTER_KEY_CODE; - - spyOn(vm, 'openFile'); - - vm.$refs.searchInput.dispatchEvent(event); - - vm.$nextTick(() => { - expect(vm.openFile).toHaveBeenCalledWith(vm.$store.state.entries['index.js']); - - done(); - }); - }); - - it('closes file finder on esc key', done => { - const event = new CustomEvent('keyup'); - event.keyCode = ESC_KEY_CODE; - - spyOn(vm, 'toggleFileFinder'); - - vm.$refs.searchInput.dispatchEvent(event); - - vm.$nextTick(() => { - expect(vm.toggleFileFinder).toHaveBeenCalled(); - - done(); - }); - }); - }); - - describe('onKeyDown', () => { - let el; - - beforeEach(() => { - el = vm.$refs.searchInput; - }); - - describe('up key', () => { - const event = new CustomEvent('keydown'); - event.keyCode = UP_KEY_CODE; - - it('resets to last index when at top', () => { - el.dispatchEvent(event); - - expect(vm.focusedIndex).toBe(1); - }); - - it('minus 1 from focusedIndex', () => { - vm.focusedIndex = 1; - - el.dispatchEvent(event); - - expect(vm.focusedIndex).toBe(0); - }); - }); - - describe('down key', () => { - const event = new CustomEvent('keydown'); - event.keyCode = DOWN_KEY_CODE; - - it('resets to first index when at bottom', () => { - vm.focusedIndex = 1; - el.dispatchEvent(event); - - expect(vm.focusedIndex).toBe(0); - }); - - it('adds 1 to focusedIndex', () => { - el.dispatchEvent(event); - - expect(vm.focusedIndex).toBe(1); - }); - }); - }); - }); - - describe('without entries', () => { - it('renders loading text when loading', done => { - store.state.loading = true; - - vm.$nextTick(() => { - expect(vm.$el.textContent).toContain('Loading...'); - - done(); - }); - }); - - it('renders no files text', () => { - expect(vm.$el.textContent).toContain('No files found.'); - }); - }); -}); diff --git a/spec/javascripts/ide/components/file_finder/item_spec.js b/spec/javascripts/ide/components/file_finder/item_spec.js deleted file mode 100644 index 0f1116c6912..00000000000 --- a/spec/javascripts/ide/components/file_finder/item_spec.js +++ /dev/null @@ -1,140 +0,0 @@ -import Vue from 'vue'; -import ItemComponent from '~/ide/components/file_finder/item.vue'; -import { file } from '../../helpers'; -import createComponent from '../../../helpers/vue_mount_component_helper'; - -describe('IDE File finder item spec', () => { - const Component = Vue.extend(ItemComponent); - let vm; - let localFile; - - beforeEach(() => { - localFile = { - ...file(), - name: 'test file', - path: 'test/file', - }; - - vm = createComponent(Component, { - file: localFile, - focused: true, - searchText: '', - index: 0, - }); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('renders file name & path', () => { - expect(vm.$el.textContent).toContain('test file'); - expect(vm.$el.textContent).toContain('test/file'); - }); - - describe('focused', () => { - it('adds is-focused class', () => { - expect(vm.$el.classList).toContain('is-focused'); - }); - - it('does not have is-focused class when not focused', done => { - vm.focused = false; - - vm.$nextTick(() => { - expect(vm.$el.classList).not.toContain('is-focused'); - - done(); - }); - }); - }); - - describe('changed file icon', () => { - it('does not render when not a changed or temp file', () => { - expect(vm.$el.querySelector('.diff-changed-stats')).toBe(null); - }); - - it('renders when a changed file', done => { - vm.file.changed = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.diff-changed-stats')).not.toBe(null); - - done(); - }); - }); - - it('renders when a temp file', done => { - vm.file.tempFile = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.diff-changed-stats')).not.toBe(null); - - done(); - }); - }); - }); - - it('emits event when clicked', () => { - spyOn(vm, '$emit'); - - vm.$el.click(); - - expect(vm.$emit).toHaveBeenCalledWith('click', vm.file); - }); - - describe('path', () => { - let el; - - beforeEach(done => { - vm.searchText = 'file'; - - el = vm.$el.querySelector('.diff-changed-file-path'); - - vm.$nextTick(done); - }); - - it('highlights text', () => { - expect(el.querySelectorAll('.highlighted').length).toBe(4); - }); - - it('adds ellipsis to long text', done => { - vm.file.path = new Array(70) - .fill() - .map((_, i) => `${i}-`) - .join(''); - - vm.$nextTick(() => { - expect(el.textContent).toBe(`...${vm.file.path.substr(vm.file.path.length - 60)}`); - done(); - }); - }); - }); - - describe('name', () => { - let el; - - beforeEach(done => { - vm.searchText = 'file'; - - el = vm.$el.querySelector('.diff-changed-file-name'); - - vm.$nextTick(done); - }); - - it('highlights text', () => { - expect(el.querySelectorAll('.highlighted').length).toBe(4); - }); - - it('does not add ellipsis to long text', done => { - vm.file.name = new Array(70) - .fill() - .map((_, i) => `${i}-`) - .join(''); - - vm.$nextTick(() => { - expect(el.textContent).not.toBe(`...${vm.file.name.substr(vm.file.name.length - 60)}`); - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/ide/components/ide_spec.js b/spec/javascripts/ide/components/ide_spec.js index 55f40be0e4e..dc5790f6562 100644 --- a/spec/javascripts/ide/components/ide_spec.js +++ b/spec/javascripts/ide/components/ide_spec.js @@ -1,5 +1,4 @@ import Vue from 'vue'; -import Mousetrap from 'mousetrap'; import store from '~/ide/stores'; import ide from '~/ide/components/ide.vue'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; @@ -72,73 +71,6 @@ describe('ide component', () => { }); }); - describe('file finder', () => { - beforeEach(done => { - spyOn(vm, 'toggleFileFinder'); - - vm.$store.state.fileFindVisible = true; - - vm.$nextTick(done); - }); - - it('calls toggleFileFinder on `t` key press', done => { - Mousetrap.trigger('t'); - - vm.$nextTick() - .then(() => { - expect(vm.toggleFileFinder).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - it('calls toggleFileFinder on `command+p` key press', done => { - Mousetrap.trigger('command+p'); - - vm.$nextTick() - .then(() => { - expect(vm.toggleFileFinder).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - it('calls toggleFileFinder on `ctrl+p` key press', done => { - Mousetrap.trigger('ctrl+p'); - - vm.$nextTick() - .then(() => { - expect(vm.toggleFileFinder).toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - - it('always allows `command+p` to trigger toggleFileFinder', () => { - expect( - vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'command+p'), - ).toBe(false); - }); - - it('always allows `ctrl+p` to trigger toggleFileFinder', () => { - expect( - vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'ctrl+p'), - ).toBe(false); - }); - - it('onlys handles `t` when focused in input-field', () => { - expect( - vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'), - ).toBe(true); - }); - - it('stops callback in monaco editor', () => { - setFixtures('<div class="inputarea"></div>'); - - expect(vm.mousetrapStopCallback(null, document.querySelector('.inputarea'), 't')).toBe(true); - }); - }); - it('shows error message when set', done => { expect(vm.$el.querySelector('.flash-container')).toBe(null); |