Commit 09514d4e authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ss/fix-base-token-double-fetch' into 'master'

Add guard to base token handleInput

See merge request gitlab-org/gitlab!71339
parents f0e2efc6 3d0c4092
...@@ -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,26 +206,50 @@ describe('BaseToken', () => { ...@@ -206,26 +206,50 @@ describe('BaseToken', () => {
describe('events', () => { describe('events', () => {
let wrapperWithNoStubs; let wrapperWithNoStubs;
beforeEach(() => {
wrapperWithNoStubs = createComponent({
stubs: { Portal: true },
});
});
afterEach(() => { afterEach(() => {
wrapperWithNoStubs.destroy(); wrapperWithNoStubs.destroy();
}); });
it('emits `fetch-suggestions` event on component after a delay when component emits `input` event', async () => { describe('when activeToken has been selected', () => {
jest.useFakeTimers(); 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();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' }); wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' });
await wrapperWithNoStubs.vm.$nextTick(); await wrapperWithNoStubs.vm.$nextTick();
jest.runAllTimers(); jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toBeTruthy(); expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toEqual([['']]);
expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']); });
});
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();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' });
await wrapperWithNoStubs.vm.$nextTick();
jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toBeTruthy();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']);
});
}); });
}); });
}); });
......
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