Commit 3d0c4092 authored by Scott Stern's avatar Scott Stern Committed by Kushal Pandya

Add guard to base token handleInput

parent 55df8936
......@@ -148,7 +148,8 @@ export default {
methods: {
handleInput: debounce(function debouncedSearch({ data }) {
this.searchKey = data;
if (!this.suggestionsLoading) {
if (!this.suggestionsLoading && !this.activeTokenValue) {
this.$emit('fetch-suggestions', data);
}
}, DEBOUNCE_DELAY),
......
......@@ -206,16 +206,39 @@ describe('BaseToken', () => {
describe('events', () => {
let wrapperWithNoStubs;
afterEach(() => {
wrapperWithNoStubs.destroy();
});
describe('when activeToken has been selected', () => {
beforeEach(() => {
wrapperWithNoStubs = createComponent({
props: {
...mockProps,
getActiveTokenValue: () => ({ title: '' }),
suggestionsLoading: true,
},
stubs: { Portal: true },
});
});
it('does not emit `fetch-suggestions` event on component after a delay when component emits `input` event', async () => {
jest.useFakeTimers();
afterEach(() => {
wrapperWithNoStubs.destroy();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' });
await wrapperWithNoStubs.vm.$nextTick();
jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toEqual([['']]);
});
});
describe('when activeToken has not been selected', () => {
beforeEach(() => {
wrapperWithNoStubs = createComponent({
stubs: { Portal: true },
});
});
it('emits `fetch-suggestions` event on component after a delay when component emits `input` event', async () => {
jest.useFakeTimers();
......@@ -229,4 +252,5 @@ describe('BaseToken', () => {
});
});
});
});
});
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