Commit 322add9a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ss/fix-space-issue-tokens' into 'master'

Add space logic to base token

See merge request gitlab-org/gitlab!75948
parents 691d281a 8e99ddca
......@@ -10,7 +10,11 @@ import {
import { debounce } from 'lodash';
import { DEBOUNCE_DELAY, FILTER_NONE_ANY, OPERATOR_IS_NOT } from '../constants';
import { getRecentlyUsedSuggestions, setTokenValueToRecentlyUsed } from '../filtered_search_utils';
import {
getRecentlyUsedSuggestions,
setTokenValueToRecentlyUsed,
stripQuotes,
} from '../filtered_search_utils';
export default {
components: {
......@@ -163,7 +167,14 @@ export default {
this.searchKey = data;
if (!this.suggestionsLoading && !this.activeTokenValue) {
const search = this.searchTerm ? this.searchTerm : data;
let search = this.searchTerm ? this.searchTerm : data;
if (search.startsWith('"') && search.endsWith('"')) {
search = stripQuotes(search);
} else if (search.startsWith('"')) {
search = search.slice(1, search.length);
}
this.$emit('fetch-suggestions', search);
}
}, DEBOUNCE_DELAY),
......
......@@ -12,7 +12,7 @@ import { mockIterationToken, mockIterations } from '../mock_data';
jest.mock('~/flash');
describe('IterationToken', () => {
const id = 123;
const id = '123';
let wrapper;
const createComponent = ({
......
......@@ -14,7 +14,13 @@ import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_t
import { mockLabelToken } from '../mock_data';
jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils');
jest.mock('~/vue_shared/components/filtered_search_bar/filtered_search_utils', () => ({
getRecentlyUsedSuggestions: jest.fn(),
setTokenValueToRecentlyUsed: jest.fn(),
stripQuotes: jest.requireActual(
'~/vue_shared/components/filtered_search_bar/filtered_search_utils',
).stripQuotes,
}));
const mockStorageKey = 'recent-tokens-label_name';
......@@ -231,6 +237,7 @@ describe('BaseToken', () => {
stubs: { Portal: true },
});
});
it('emits `fetch-suggestions` event on component after a delay when component emits `input` event', async () => {
jest.useFakeTimers();
......@@ -242,6 +249,32 @@ describe('BaseToken', () => {
expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toBeTruthy();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']);
});
describe('when search is started with a quote', () => {
it('emits `fetch-suggestions` with filtered value', async () => {
jest.useFakeTimers();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: '"foo' });
await wrapperWithNoStubs.vm.$nextTick();
jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']);
});
});
describe('when search starts and ends with a quote', () => {
it('emits `fetch-suggestions` with filtered value', async () => {
jest.useFakeTimers();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: '"foo"' });
await wrapperWithNoStubs.vm.$nextTick();
jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']);
});
});
});
});
});
......
......@@ -8,7 +8,7 @@ import { mockReleaseToken } from '../mock_data';
jest.mock('~/flash');
describe('ReleaseToken', () => {
const id = 123;
const id = '123';
let wrapper;
const createComponent = ({ config = mockReleaseToken, value = { data: '' } } = {}) =>
......
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