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