Commit a35391c9 authored by Phil Hughes's avatar Phil Hughes

added specs to store

added clear button to search input
parent 066aa5b3
...@@ -42,6 +42,9 @@ export default { ...@@ -42,6 +42,9 @@ export default {
listHeight() { listHeight() {
return this.filteredBlobsLength ? 55 : 33; return this.filteredBlobsLength ? 55 : 33;
}, },
showClearInputButton() {
return this.searchText.trim() !== '';
},
}, },
watch: { watch: {
fileFindVisible() { fileFindVisible() {
...@@ -61,6 +64,13 @@ export default { ...@@ -61,6 +64,13 @@ export default {
}, },
methods: { methods: {
...mapActions(['toggleFileFinder']), ...mapActions(['toggleFileFinder']),
clearSearchInput() {
this.searchText = '';
this.$nextTick(() => {
this.$refs.searchInput.focus();
});
},
onKeydown(e) { onKeydown(e) {
switch (e.keyCode) { switch (e.keyCode) {
case 38: case 38:
...@@ -129,6 +139,18 @@ export default { ...@@ -129,6 +139,18 @@ export default {
<i <i
aria-hidden="true" aria-hidden="true"
class="fa fa-search dropdown-input-search" class="fa fa-search dropdown-input-search"
:class="{
hidden: showClearInputButton
}"
></i>
<i
role="button"
aria-hidden="true"
class="fa fa-times dropdown-input-clear"
:class="{
show: showClearInputButton
}"
@click="clearSearchInput"
></i> ></i>
</div> </div>
<div> <div>
......
<script> <script>
import { escape } from 'underscore';
import fuzzaldrinPlus from 'fuzzaldrin-plus'; import fuzzaldrinPlus from 'fuzzaldrin-plus';
import FileIcon from '../../../vue_shared/components/file_icon.vue'; import FileIcon from '../../../vue_shared/components/file_icon.vue';
import ChangedFileIcon from '../changed_file_icon.vue'; import ChangedFileIcon from '../changed_file_icon.vue';
...@@ -29,10 +30,11 @@ export default { ...@@ -29,10 +30,11 @@ export default {
this.$emit('click', this.file); this.$emit('click', this.file);
}, },
highlightText(text, addEllipsis) { highlightText(text, addEllipsis) {
const escapedText = escape(text);
const maxText = const maxText =
text.length < MAX_PATH_LENGTH || !addEllipsis escapedText.length < MAX_PATH_LENGTH || !addEllipsis
? text ? escapedText
: `...${text.substr(text.length - MAX_PATH_LENGTH)}`; : `...${escapedText.substr(escapedText.length - MAX_PATH_LENGTH)}`;
const occurrences = fuzzaldrinPlus.match(maxText, this.searchText); const occurrences = fuzzaldrinPlus.match(maxText, this.searchText);
return maxText return maxText
......
...@@ -54,4 +54,4 @@ export const UPDATE_DELAY_VIEWER_CHANGE = 'UPDATE_DELAY_VIEWER_CHANGE'; ...@@ -54,4 +54,4 @@ export const UPDATE_DELAY_VIEWER_CHANGE = 'UPDATE_DELAY_VIEWER_CHANGE';
export const ADD_PENDING_TAB = 'ADD_PENDING_TAB'; export const ADD_PENDING_TAB = 'ADD_PENDING_TAB';
export const REMOVE_PENDING_TAB = 'REMOVE_PENDING_TAB'; export const REMOVE_PENDING_TAB = 'REMOVE_PENDING_TAB';
export const TOGGLE_FILE_FINDER = 'SHOW_FILE_FINDER'; export const TOGGLE_FILE_FINDER = 'TOGGLE_FILE_FINDER';
---
title: Added fuzzy file finder to web IDE
merge_request:
author:
type: added
...@@ -67,6 +67,50 @@ describe('IDE File finder item spec', () => { ...@@ -67,6 +67,50 @@ describe('IDE File finder item spec', () => {
}); });
}); });
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', () => { describe('listShowCount', () => {
it('returns 1 when no filtered entries exist', done => { it('returns 1 when no filtered entries exist', done => {
vm.searchText = 'testing 123'; vm.searchText = 'testing 123';
......
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
import store from '~/ide/stores'; import store from '~/ide/stores';
import * as actions from '~/ide/stores/actions';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
import { resetStore, file } from '../helpers'; import { resetStore, file } from '../helpers';
import testAction from '../../helpers/vuex_action_helper';
describe('Multi-file store actions', () => { describe('Multi-file store actions', () => {
beforeEach(() => { beforeEach(() => {
...@@ -191,9 +193,7 @@ describe('Multi-file store actions', () => { ...@@ -191,9 +193,7 @@ describe('Multi-file store actions', () => {
}) })
.then(f => { .then(f => {
expect(f.tempFile).toBeTruthy(); expect(f.tempFile).toBeTruthy();
expect(store.state.trees['abcproject/mybranch'].tree.length).toBe( expect(store.state.trees['abcproject/mybranch'].tree.length).toBe(1);
1,
);
done(); done();
}) })
...@@ -303,4 +303,17 @@ describe('Multi-file store actions', () => { ...@@ -303,4 +303,17 @@ describe('Multi-file store actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
}); });
describe('toggleFileFinder', () => {
it('commits TOGGLE_FILE_FINDER', done => {
testAction(
actions.toggleFileFinder,
true,
null,
[{ type: 'TOGGLE_FILE_FINDER', payload: true }],
[],
done,
);
});
});
}); });
...@@ -76,4 +76,12 @@ describe('Multi-file store mutations', () => { ...@@ -76,4 +76,12 @@ describe('Multi-file store mutations', () => {
expect(localState.viewer).toBe('diff'); expect(localState.viewer).toBe('diff');
}); });
}); });
describe('TOGGLE_FILE_FINDER', () => {
it('updates fileFindVisible', () => {
mutations.TOGGLE_FILE_FINDER(localState, true);
expect(localState.fileFindVisible).toBe(true);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment