Commit 43f2004e authored by Miguel Rincon's avatar Miguel Rincon

Refactor to rename token values to suggestions

This change updates the name "token values" to "suggestions" to make
the gitlab and gitlab-ui terminology consistent.

This way author can more easily identify the features of base_token.vue
as opposed to GlFilteredToken from gitlab-ui.
parent d2580206
...@@ -215,35 +215,35 @@ export function urlQueryToFilter(query = '', options = {}) { ...@@ -215,35 +215,35 @@ export function urlQueryToFilter(query = '', options = {}) {
/** /**
* Returns array of token values from localStorage * Returns array of token values from localStorage
* based on provided recentTokenValuesStorageKey * based on provided recentSuggestionsStorageKey
* *
* @param {String} recentTokenValuesStorageKey * @param {String} recentSuggestionsStorageKey
* @returns * @returns
*/ */
export function getRecentlyUsedTokenValues(recentTokenValuesStorageKey) { export function getRecentlyUsedSuggestions(recentSuggestionsStorageKey) {
let recentlyUsedTokenValues = []; let recentlyUsedSuggestions = [];
if (AccessorUtilities.isLocalStorageAccessSafe()) { if (AccessorUtilities.isLocalStorageAccessSafe()) {
recentlyUsedTokenValues = JSON.parse(localStorage.getItem(recentTokenValuesStorageKey)) || []; recentlyUsedSuggestions = JSON.parse(localStorage.getItem(recentSuggestionsStorageKey)) || [];
} }
return recentlyUsedTokenValues; return recentlyUsedSuggestions;
} }
/** /**
* Sets provided token value to recently used array * Sets provided token value to recently used array
* within localStorage for provided recentTokenValuesStorageKey * within localStorage for provided recentSuggestionsStorageKey
* *
* @param {String} recentTokenValuesStorageKey * @param {String} recentSuggestionsStorageKey
* @param {Object} tokenValue * @param {Object} tokenValue
*/ */
export function setTokenValueToRecentlyUsed(recentTokenValuesStorageKey, tokenValue) { export function setTokenValueToRecentlyUsed(recentSuggestionsStorageKey, tokenValue) {
const recentlyUsedTokenValues = getRecentlyUsedTokenValues(recentTokenValuesStorageKey); const recentlyUsedSuggestions = getRecentlyUsedSuggestions(recentSuggestionsStorageKey);
recentlyUsedTokenValues.splice(0, 0, { ...tokenValue }); recentlyUsedSuggestions.splice(0, 0, { ...tokenValue });
if (AccessorUtilities.isLocalStorageAccessSafe()) { if (AccessorUtilities.isLocalStorageAccessSafe()) {
localStorage.setItem( localStorage.setItem(
recentTokenValuesStorageKey, recentSuggestionsStorageKey,
JSON.stringify(uniqWith(recentlyUsedTokenValues, isEqual).slice(0, MAX_RECENT_TOKENS_SIZE)), JSON.stringify(uniqWith(recentlyUsedSuggestions, isEqual).slice(0, MAX_RECENT_TOKENS_SIZE)),
); );
} }
} }
...@@ -74,13 +74,13 @@ export default { ...@@ -74,13 +74,13 @@ export default {
:config="config" :config="config"
:value="value" :value="value"
:active="active" :active="active"
:tokens-list-loading="loading" :suggestions-loading="loading"
:token-values="authors" :suggestions="authors"
:fn-active-token-value="getActiveAuthor" :fn-active-token-value="getActiveAuthor"
:default-token-values="defaultAuthors" :default-suggestions="defaultAuthors"
:preloaded-token-values="preloadedAuthors" :preloaded-suggestions="preloadedAuthors"
:recent-token-values-storage-key="config.recentTokenValuesStorageKey" :recent-suggestions-storage-key="config.recentSuggestionsStorageKey"
@fetch-token-values="fetchAuthorBySearchTerm" @fetch-suggestions="fetchAuthorBySearchTerm"
v-on="$listeners" v-on="$listeners"
> >
<template #view="{ viewTokenProps: { inputValue, activeTokenValue } }"> <template #view="{ viewTokenProps: { inputValue, activeTokenValue } }">
...@@ -93,9 +93,9 @@ export default { ...@@ -93,9 +93,9 @@ export default {
/> />
<span>{{ activeTokenValue ? activeTokenValue.name : inputValue }}</span> <span>{{ activeTokenValue ? activeTokenValue.name : inputValue }}</span>
</template> </template>
<template #token-values-list="{ tokenValues }"> <template #suggestions-list="{ suggestions }">
<gl-filtered-search-suggestion <gl-filtered-search-suggestion
v-for="author in tokenValues" v-for="author in suggestions"
:key="author.username" :key="author.username"
:value="author.username" :value="author.username"
> >
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import { DEBOUNCE_DELAY } from '../constants'; import { DEBOUNCE_DELAY } from '../constants';
import { getRecentlyUsedTokenValues, setTokenValueToRecentlyUsed } from '../filtered_search_utils'; import { getRecentlyUsedSuggestions, setTokenValueToRecentlyUsed } from '../filtered_search_utils';
export default { export default {
components: { components: {
...@@ -31,12 +31,12 @@ export default { ...@@ -31,12 +31,12 @@ export default {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
tokensListLoading: { suggestionsLoading: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
}, },
tokenValues: { suggestions: {
type: Array, type: Array,
required: false, required: false,
default: () => [], default: () => [],
...@@ -44,21 +44,21 @@ export default { ...@@ -44,21 +44,21 @@ export default {
fnActiveTokenValue: { fnActiveTokenValue: {
type: Function, type: Function,
required: false, required: false,
default: (tokenValues, currentTokenValue) => { default: (suggestions, currentTokenValue) => {
return tokenValues.find(({ value }) => value === currentTokenValue); return suggestions.find(({ value }) => value === currentTokenValue);
}, },
}, },
defaultTokenValues: { defaultSuggestions: {
type: Array, type: Array,
required: false, required: false,
default: () => [], default: () => [],
}, },
preloadedTokenValues: { preloadedSuggestions: {
type: Array, type: Array,
required: false, required: false,
default: () => [], default: () => [],
}, },
recentTokenValuesStorageKey: { recentSuggestionsStorageKey: {
type: String, type: String,
required: false, required: false,
default: '', default: '',
...@@ -77,21 +77,21 @@ export default { ...@@ -77,21 +77,21 @@ export default {
data() { data() {
return { return {
searchKey: '', searchKey: '',
recentTokenValues: this.recentTokenValuesStorageKey recentSuggestions: this.recentSuggestionsStorageKey
? getRecentlyUsedTokenValues(this.recentTokenValuesStorageKey) ? getRecentlyUsedSuggestions(this.recentSuggestionsStorageKey)
: [], : [],
loading: false, loading: false,
}; };
}, },
computed: { computed: {
isRecentTokenValuesEnabled() { isRecentSuggestionsEnabled() {
return Boolean(this.recentTokenValuesStorageKey); return Boolean(this.recentSuggestionsStorageKey);
}, },
recentTokenIds() { recentTokenIds() {
return this.recentTokenValues.map((tokenValue) => tokenValue[this.valueIdentifier]); return this.recentSuggestions.map((tokenValue) => tokenValue[this.valueIdentifier]);
}, },
preloadedTokenIds() { preloadedTokenIds() {
return this.preloadedTokenValues.map((tokenValue) => tokenValue[this.valueIdentifier]); return this.preloadedSuggestions.map((tokenValue) => tokenValue[this.valueIdentifier]);
}, },
currentTokenValue() { currentTokenValue() {
if (this.fnCurrentTokenValue) { if (this.fnCurrentTokenValue) {
...@@ -100,17 +100,17 @@ export default { ...@@ -100,17 +100,17 @@ export default {
return this.value.data.toLowerCase(); return this.value.data.toLowerCase();
}, },
activeTokenValue() { activeTokenValue() {
return this.fnActiveTokenValue(this.tokenValues, this.currentTokenValue); return this.fnActiveTokenValue(this.suggestions, this.currentTokenValue);
}, },
/** /**
* Return all the tokenValues when searchKey is present * Return all the suggestions when searchKey is present
* otherwise return only the tokenValues which aren't * otherwise return only the suggestions which aren't
* present in "Recently used" * present in "Recently used"
*/ */
availableTokenValues() { availableSuggestions() {
return this.searchKey return this.searchKey
? this.tokenValues ? this.suggestions
: this.tokenValues.filter( : this.suggestions.filter(
(tokenValue) => (tokenValue) =>
!this.recentTokenIds.includes(tokenValue[this.valueIdentifier]) && !this.recentTokenIds.includes(tokenValue[this.valueIdentifier]) &&
!this.preloadedTokenIds.includes(tokenValue[this.valueIdentifier]), !this.preloadedTokenIds.includes(tokenValue[this.valueIdentifier]),
...@@ -121,8 +121,8 @@ export default { ...@@ -121,8 +121,8 @@ export default {
active: { active: {
immediate: true, immediate: true,
handler(newValue) { handler(newValue) {
if (!newValue && !this.tokenValues.length) { if (!newValue && !this.suggestions.length) {
this.$emit('fetch-token-values', this.value.data); this.$emit('fetch-suggestions', this.value.data);
} }
}, },
}, },
...@@ -131,7 +131,7 @@ export default { ...@@ -131,7 +131,7 @@ export default {
handleInput({ data }) { handleInput({ data }) {
this.searchKey = data; this.searchKey = data;
setTimeout(() => { setTimeout(() => {
if (!this.tokensListLoading) this.$emit('fetch-token-values', data); if (!this.suggestionsLoading) this.$emit('fetch-suggestions', data);
}, DEBOUNCE_DELAY); }, DEBOUNCE_DELAY);
}, },
handleTokenValueSelected(activeTokenValue) { handleTokenValueSelected(activeTokenValue) {
...@@ -140,11 +140,11 @@ export default { ...@@ -140,11 +140,11 @@ export default {
// 2. User has actually selected a value // 2. User has actually selected a value
// 3. Selected value is not part of preloaded list. // 3. Selected value is not part of preloaded list.
if ( if (
this.isRecentTokenValuesEnabled && this.isRecentSuggestionsEnabled &&
activeTokenValue && activeTokenValue &&
!this.preloadedTokenIds.includes(activeTokenValue[this.valueIdentifier]) !this.preloadedTokenIds.includes(activeTokenValue[this.valueIdentifier])
) { ) {
setTokenValueToRecentlyUsed(this.recentTokenValuesStorageKey, activeTokenValue); setTokenValueToRecentlyUsed(this.recentSuggestionsStorageKey, activeTokenValue);
} }
}, },
}, },
...@@ -168,9 +168,9 @@ export default { ...@@ -168,9 +168,9 @@ export default {
<slot name="view" :view-token-props="{ ...viewTokenProps, activeTokenValue }"></slot> <slot name="view" :view-token-props="{ ...viewTokenProps, activeTokenValue }"></slot>
</template> </template>
<template #suggestions> <template #suggestions>
<template v-if="defaultTokenValues.length"> <template v-if="defaultSuggestions.length">
<gl-filtered-search-suggestion <gl-filtered-search-suggestion
v-for="token in defaultTokenValues" v-for="token in defaultSuggestions"
:key="token.value" :key="token.value"
:value="token.value" :value="token.value"
> >
...@@ -178,19 +178,19 @@ export default { ...@@ -178,19 +178,19 @@ export default {
</gl-filtered-search-suggestion> </gl-filtered-search-suggestion>
<gl-dropdown-divider /> <gl-dropdown-divider />
</template> </template>
<template v-if="isRecentTokenValuesEnabled && recentTokenValues.length && !searchKey"> <template v-if="isRecentSuggestionsEnabled && recentSuggestions.length && !searchKey">
<gl-dropdown-section-header>{{ __('Recently used') }}</gl-dropdown-section-header> <gl-dropdown-section-header>{{ __('Recently used') }}</gl-dropdown-section-header>
<slot name="token-values-list" :token-values="recentTokenValues"></slot> <slot name="suggestions-list" :suggestions="recentSuggestions"></slot>
<gl-dropdown-divider /> <gl-dropdown-divider />
</template> </template>
<slot <slot
v-if="preloadedTokenValues.length && !searchKey" v-if="preloadedSuggestions.length && !searchKey"
name="token-values-list" name="suggestions-list"
:token-values="preloadedTokenValues" :suggestions="preloadedSuggestions"
></slot> ></slot>
<gl-loading-icon v-if="tokensListLoading" /> <gl-loading-icon v-if="suggestionsLoading" />
<template v-else> <template v-else>
<slot name="token-values-list" :token-values="availableTokenValues"></slot> <slot name="suggestions-list" :suggestions="availableSuggestions"></slot>
</template> </template>
</template> </template>
</gl-filtered-search-token> </gl-filtered-search-token>
......
...@@ -96,12 +96,12 @@ export default { ...@@ -96,12 +96,12 @@ export default {
:config="config" :config="config"
:value="value" :value="value"
:active="active" :active="active"
:tokens-list-loading="loading" :suggestions-loading="loading"
:token-values="labels" :suggestions="labels"
:fn-active-token-value="getActiveLabel" :fn-active-token-value="getActiveLabel"
:default-token-values="defaultLabels" :default-suggestions="defaultLabels"
:recent-token-values-storage-key="config.recentTokenValuesStorageKey" :recent-suggestions-storage-key="config.recentSuggestionsStorageKey"
@fetch-token-values="fetchLabelBySearchTerm" @fetch-suggestions="fetchLabelBySearchTerm"
v-on="$listeners" v-on="$listeners"
> >
<template <template
...@@ -115,9 +115,9 @@ export default { ...@@ -115,9 +115,9 @@ export default {
>~{{ activeTokenValue ? getLabelName(activeTokenValue) : inputValue }}</gl-token >~{{ activeTokenValue ? getLabelName(activeTokenValue) : inputValue }}</gl-token
> >
</template> </template>
<template #token-values-list="{ tokenValues }"> <template #suggestions-list="{ suggestions }">
<gl-filtered-search-suggestion <gl-filtered-search-suggestion
v-for="label in tokenValues" v-for="label in suggestions"
:key="label.id" :key="label.id"
:value="getLabelName(label)" :value="getLabelName(label)"
> >
......
...@@ -65,7 +65,7 @@ export default { ...@@ -65,7 +65,7 @@ export default {
symbol: '@', symbol: '@',
token: AuthorToken, token: AuthorToken,
operators: OPERATOR_IS_ONLY, operators: OPERATOR_IS_ONLY,
recentTokenValuesStorageKey: `${this.groupFullPath}-epics-recent-tokens-author_username`, recentSuggestionsStorageKey: `${this.groupFullPath}-epics-recent-tokens-author_username`,
fetchAuthors: Api.users.bind(Api), fetchAuthors: Api.users.bind(Api),
preloadedAuthors, preloadedAuthors,
}, },
...@@ -77,7 +77,7 @@ export default { ...@@ -77,7 +77,7 @@ export default {
symbol: '~', symbol: '~',
token: LabelToken, token: LabelToken,
operators: OPERATOR_IS_ONLY, operators: OPERATOR_IS_ONLY,
recentTokenValuesStorageKey: `${this.groupFullPath}-epics-recent-tokens-label_name`, recentSuggestionsStorageKey: `${this.groupFullPath}-epics-recent-tokens-label_name`,
fetchLabels: (search = '') => { fetchLabels: (search = '') => {
const params = { const params = {
only_group_labels: true, only_group_labels: true,
......
...@@ -775,7 +775,7 @@ export const mockAuthorTokenConfig = { ...@@ -775,7 +775,7 @@ export const mockAuthorTokenConfig = {
symbol: '@', symbol: '@',
token: AuthorToken, token: AuthorToken,
operators: OPERATOR_IS_ONLY, operators: OPERATOR_IS_ONLY,
recentTokenValuesStorageKey: 'gitlab-org-epics-recent-tokens-author_username', recentSuggestionsStorageKey: 'gitlab-org-epics-recent-tokens-author_username',
fetchAuthors: expect.any(Function), fetchAuthors: expect.any(Function),
preloadedAuthors: [], preloadedAuthors: [],
}; };
...@@ -788,7 +788,7 @@ export const mockLabelTokenConfig = { ...@@ -788,7 +788,7 @@ export const mockLabelTokenConfig = {
symbol: '~', symbol: '~',
token: LabelToken, token: LabelToken,
operators: OPERATOR_IS_ONLY, operators: OPERATOR_IS_ONLY,
recentTokenValuesStorageKey: 'gitlab-org-epics-recent-tokens-label_name', recentSuggestionsStorageKey: 'gitlab-org-epics-recent-tokens-label_name',
fetchLabels: expect.any(Function), fetchLabels: expect.any(Function),
}; };
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
processFilters, processFilters,
filterToQueryObject, filterToQueryObject,
urlQueryToFilter, urlQueryToFilter,
getRecentlyUsedTokenValues, getRecentlyUsedSuggestions,
setTokenValueToRecentlyUsed, setTokenValueToRecentlyUsed,
} from '~/vue_shared/components/filtered_search_bar/filtered_search_utils'; } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils';
...@@ -328,32 +328,32 @@ describe('urlQueryToFilter', () => { ...@@ -328,32 +328,32 @@ describe('urlQueryToFilter', () => {
); );
}); });
describe('getRecentlyUsedTokenValues', () => { describe('getRecentlyUsedSuggestions', () => {
useLocalStorageSpy(); useLocalStorageSpy();
beforeEach(() => { beforeEach(() => {
localStorage.removeItem(mockStorageKey); localStorage.removeItem(mockStorageKey);
}); });
it('returns array containing recently used token values from provided recentTokenValuesStorageKey', () => { it('returns array containing recently used token values from provided recentSuggestionsStorageKey', () => {
setLocalStorageAvailability(true); setLocalStorageAvailability(true);
const mockExpectedArray = [{ foo: 'bar' }]; const mockExpectedArray = [{ foo: 'bar' }];
localStorage.setItem(mockStorageKey, JSON.stringify(mockExpectedArray)); localStorage.setItem(mockStorageKey, JSON.stringify(mockExpectedArray));
expect(getRecentlyUsedTokenValues(mockStorageKey)).toEqual(mockExpectedArray); expect(getRecentlyUsedSuggestions(mockStorageKey)).toEqual(mockExpectedArray);
}); });
it('returns empty array when provided recentTokenValuesStorageKey does not have anything in localStorage', () => { it('returns empty array when provided recentSuggestionsStorageKey does not have anything in localStorage', () => {
setLocalStorageAvailability(true); setLocalStorageAvailability(true);
expect(getRecentlyUsedTokenValues(mockStorageKey)).toEqual([]); expect(getRecentlyUsedSuggestions(mockStorageKey)).toEqual([]);
}); });
it('returns empty array when when access to localStorage is not available', () => { it('returns empty array when when access to localStorage is not available', () => {
setLocalStorageAvailability(false); setLocalStorageAvailability(false);
expect(getRecentlyUsedTokenValues(mockStorageKey)).toEqual([]); expect(getRecentlyUsedSuggestions(mockStorageKey)).toEqual([]);
}); });
}); });
...@@ -366,7 +366,7 @@ describe('setTokenValueToRecentlyUsed', () => { ...@@ -366,7 +366,7 @@ describe('setTokenValueToRecentlyUsed', () => {
localStorage.removeItem(mockStorageKey); localStorage.removeItem(mockStorageKey);
}); });
it('adds provided tokenValue to localStorage for recentTokenValuesStorageKey', () => { it('adds provided tokenValue to localStorage for recentSuggestionsStorageKey', () => {
setLocalStorageAvailability(true); setLocalStorageAvailability(true);
setTokenValueToRecentlyUsed(mockStorageKey, mockTokenValue1); setTokenValueToRecentlyUsed(mockStorageKey, mockTokenValue1);
......
...@@ -94,7 +94,7 @@ describe('AuthorToken', () => { ...@@ -94,7 +94,7 @@ describe('AuthorToken', () => {
it('calls `config.fetchAuthors` with provided searchTerm param', () => { it('calls `config.fetchAuthors` with provided searchTerm param', () => {
jest.spyOn(wrapper.vm.config, 'fetchAuthors'); jest.spyOn(wrapper.vm.config, 'fetchAuthors');
getBaseToken().vm.$emit('fetch-token-values', mockAuthors[0].username); getBaseToken().vm.$emit('fetch-suggestions', mockAuthors[0].username);
expect(wrapper.vm.config.fetchAuthors).toHaveBeenCalledWith( expect(wrapper.vm.config.fetchAuthors).toHaveBeenCalledWith(
mockAuthorToken.fetchPath, mockAuthorToken.fetchPath,
...@@ -105,17 +105,17 @@ describe('AuthorToken', () => { ...@@ -105,17 +105,17 @@ describe('AuthorToken', () => {
it('sets response to `authors` when request is succesful', () => { it('sets response to `authors` when request is succesful', () => {
jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockResolvedValue(mockAuthors); jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockResolvedValue(mockAuthors);
getBaseToken().vm.$emit('fetch-token-values', 'root'); getBaseToken().vm.$emit('fetch-suggestions', 'root');
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(getBaseToken().props('tokenValues')).toEqual(mockAuthors); expect(getBaseToken().props('suggestions')).toEqual(mockAuthors);
}); });
}); });
it('calls `createFlash` with flash error message when request fails', () => { it('calls `createFlash` with flash error message when request fails', () => {
jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({}); jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({});
getBaseToken().vm.$emit('fetch-token-values', 'root'); getBaseToken().vm.$emit('fetch-suggestions', 'root');
return waitForPromises().then(() => { return waitForPromises().then(() => {
expect(createFlash).toHaveBeenCalledWith({ expect(createFlash).toHaveBeenCalledWith({
...@@ -127,17 +127,17 @@ describe('AuthorToken', () => { ...@@ -127,17 +127,17 @@ describe('AuthorToken', () => {
it('sets `loading` to false when request completes', async () => { it('sets `loading` to false when request completes', async () => {
jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({}); jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({});
getBaseToken().vm.$emit('fetch-token-values', 'root'); getBaseToken().vm.$emit('fetch-suggestions', 'root');
await waitForPromises(); await waitForPromises();
expect(getBaseToken().props('tokensListLoading')).toBe(false); expect(getBaseToken().props('suggestionsLoading')).toBe(false);
}); });
}); });
}); });
describe('template', () => { describe('template', () => {
const activateTokenValuesList = async () => { const activateSuggestionsList = async () => {
const tokenSegments = wrapper.findAllComponents(GlFilteredSearchTokenSegment); const tokenSegments = wrapper.findAllComponents(GlFilteredSearchTokenSegment);
const suggestionsSegment = tokenSegments.at(2); const suggestionsSegment = tokenSegments.at(2);
suggestionsSegment.vm.$emit('activate'); suggestionsSegment.vm.$emit('activate');
...@@ -154,7 +154,7 @@ describe('AuthorToken', () => { ...@@ -154,7 +154,7 @@ describe('AuthorToken', () => {
expect(baseTokenEl.exists()).toBe(true); expect(baseTokenEl.exists()).toBe(true);
expect(baseTokenEl.props()).toMatchObject({ expect(baseTokenEl.props()).toMatchObject({
tokenValues: mockAuthors, suggestions: mockAuthors,
fnActiveTokenValue: wrapper.vm.getActiveAuthor, fnActiveTokenValue: wrapper.vm.getActiveAuthor,
}); });
}); });
...@@ -221,7 +221,7 @@ describe('AuthorToken', () => { ...@@ -221,7 +221,7 @@ describe('AuthorToken', () => {
stubs: { Portal: true }, stubs: { Portal: true },
}); });
await activateTokenValuesList(); await activateSuggestionsList();
const suggestions = wrapper.findAll(GlFilteredSearchSuggestion); const suggestions = wrapper.findAll(GlFilteredSearchSuggestion);
...@@ -252,7 +252,7 @@ describe('AuthorToken', () => { ...@@ -252,7 +252,7 @@ describe('AuthorToken', () => {
stubs: { Portal: true }, stubs: { Portal: true },
}); });
await activateTokenValuesList(); await activateSuggestionsList();
const suggestions = wrapper.findAll(GlFilteredSearchSuggestion); const suggestions = wrapper.findAll(GlFilteredSearchSuggestion);
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
import { DEFAULT_LABELS } from '~/vue_shared/components/filtered_search_bar/constants'; import { DEFAULT_LABELS } from '~/vue_shared/components/filtered_search_bar/constants';
import { import {
getRecentlyUsedTokenValues, getRecentlyUsedSuggestions,
setTokenValueToRecentlyUsed, setTokenValueToRecentlyUsed,
} from '~/vue_shared/components/filtered_search_bar/filtered_search_utils'; } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils';
import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue'; import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue';
...@@ -49,10 +49,10 @@ const mockProps = { ...@@ -49,10 +49,10 @@ const mockProps = {
config: mockLabelToken, config: mockLabelToken,
value: { data: '' }, value: { data: '' },
active: false, active: false,
tokenValues: [], suggestions: [],
tokensListLoading: false, suggestionsLoading: false,
defaultTokenValues: DEFAULT_LABELS, defaultSuggestions: DEFAULT_LABELS,
recentTokenValuesStorageKey: mockStorageKey, recentSuggestionsStorageKey: mockStorageKey,
fnCurrentTokenValue: jest.fn(), fnCurrentTokenValue: jest.fn(),
}; };
...@@ -83,7 +83,7 @@ describe('BaseToken', () => { ...@@ -83,7 +83,7 @@ describe('BaseToken', () => {
props: { props: {
...mockProps, ...mockProps,
value: { data: `"${mockRegularLabel.title}"` }, value: { data: `"${mockRegularLabel.title}"` },
tokenValues: mockLabels, suggestions: mockLabels,
}, },
}); });
}); });
...@@ -93,8 +93,8 @@ describe('BaseToken', () => { ...@@ -93,8 +93,8 @@ describe('BaseToken', () => {
}); });
describe('data', () => { describe('data', () => {
it('calls `getRecentlyUsedTokenValues` to populate `recentTokenValues` when `recentTokenValuesStorageKey` is defined', () => { it('calls `getRecentlyUsedSuggestions` to populate `recentSuggestions` when `recentSuggestionsStorageKey` is defined', () => {
expect(getRecentlyUsedTokenValues).toHaveBeenCalledWith(mockStorageKey); expect(getRecentlyUsedSuggestions).toHaveBeenCalledWith(mockStorageKey);
}); });
}); });
...@@ -147,15 +147,15 @@ describe('BaseToken', () => { ...@@ -147,15 +147,15 @@ describe('BaseToken', () => {
wrapperWithTokenActive.destroy(); wrapperWithTokenActive.destroy();
}); });
it('emits `fetch-token-values` event on the component when value of this prop is changed to false and `tokenValues` array is empty', async () => { it('emits `fetch-suggestions` event on the component when value of this prop is changed to false and `suggestions` array is empty', async () => {
wrapperWithTokenActive.setProps({ wrapperWithTokenActive.setProps({
active: false, active: false,
}); });
await wrapperWithTokenActive.vm.$nextTick(); await wrapperWithTokenActive.vm.$nextTick();
expect(wrapperWithTokenActive.emitted('fetch-token-values')).toBeTruthy(); expect(wrapperWithTokenActive.emitted('fetch-suggestions')).toBeTruthy();
expect(wrapperWithTokenActive.emitted('fetch-token-values')).toEqual([ expect(wrapperWithTokenActive.emitted('fetch-suggestions')).toEqual([
[`"${mockRegularLabel.title}"`], [`"${mockRegularLabel.title}"`],
]); ]);
}); });
...@@ -164,7 +164,7 @@ describe('BaseToken', () => { ...@@ -164,7 +164,7 @@ describe('BaseToken', () => {
describe('methods', () => { describe('methods', () => {
describe('handleTokenValueSelected', () => { describe('handleTokenValueSelected', () => {
it('calls `setTokenValueToRecentlyUsed` when `recentTokenValuesStorageKey` is defined', () => { it('calls `setTokenValueToRecentlyUsed` when `recentSuggestionsStorageKey` is defined', () => {
const mockTokenValue = { const mockTokenValue = {
id: 1, id: 1,
title: 'Foo', title: 'Foo',
...@@ -175,14 +175,14 @@ describe('BaseToken', () => { ...@@ -175,14 +175,14 @@ describe('BaseToken', () => {
expect(setTokenValueToRecentlyUsed).toHaveBeenCalledWith(mockStorageKey, mockTokenValue); expect(setTokenValueToRecentlyUsed).toHaveBeenCalledWith(mockStorageKey, mockTokenValue);
}); });
it('does not add token from preloadedTokenValues', async () => { it('does not add token from preloadedSuggestions', async () => {
const mockTokenValue = { const mockTokenValue = {
id: 1, id: 1,
title: 'Foo', title: 'Foo',
}; };
wrapper.setProps({ wrapper.setProps({
preloadedTokenValues: [mockTokenValue], preloadedSuggestions: [mockTokenValue],
}); });
await wrapper.vm.$nextTick(); await wrapper.vm.$nextTick();
...@@ -228,7 +228,7 @@ describe('BaseToken', () => { ...@@ -228,7 +228,7 @@ describe('BaseToken', () => {
wrapperWithNoStubs.destroy(); wrapperWithNoStubs.destroy();
}); });
it('emits `fetch-token-values` 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();
wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' }); wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' });
...@@ -236,8 +236,8 @@ describe('BaseToken', () => { ...@@ -236,8 +236,8 @@ describe('BaseToken', () => {
jest.runAllTimers(); jest.runAllTimers();
expect(wrapperWithNoStubs.emitted('fetch-token-values')).toBeTruthy(); expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toBeTruthy();
expect(wrapperWithNoStubs.emitted('fetch-token-values')[2]).toEqual(['foo']); expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']);
}); });
}); });
}); });
......
...@@ -159,7 +159,7 @@ describe('LabelToken', () => { ...@@ -159,7 +159,7 @@ describe('LabelToken', () => {
expect(baseTokenEl.exists()).toBe(true); expect(baseTokenEl.exists()).toBe(true);
expect(baseTokenEl.props()).toMatchObject({ expect(baseTokenEl.props()).toMatchObject({
tokenValues: mockLabels, suggestions: mockLabels,
fnActiveTokenValue: wrapper.vm.getActiveLabel, fnActiveTokenValue: wrapper.vm.getActiveLabel,
}); });
}); });
......
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