diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/frontend/vue_shared/components/filtered_search_bar | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/frontend/vue_shared/components/filtered_search_bar')
6 files changed, 44 insertions, 41 deletions
diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_utils_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_utils_spec.js index 93cddff8421..1b97011bf7f 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_utils_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/filtered_search_utils_spec.js @@ -11,7 +11,7 @@ import { processFilters, filterToQueryObject, urlQueryToFilter, - getRecentlyUsedTokenValues, + getRecentlyUsedSuggestions, setTokenValueToRecentlyUsed, } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils'; @@ -328,32 +328,32 @@ describe('urlQueryToFilter', () => { ); }); -describe('getRecentlyUsedTokenValues', () => { +describe('getRecentlyUsedSuggestions', () => { useLocalStorageSpy(); beforeEach(() => { 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); const mockExpectedArray = [{ foo: 'bar' }]; 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); - expect(getRecentlyUsedTokenValues(mockStorageKey)).toEqual([]); + expect(getRecentlyUsedSuggestions(mockStorageKey)).toEqual([]); }); it('returns empty array when when access to localStorage is not available', () => { setLocalStorageAvailability(false); - expect(getRecentlyUsedTokenValues(mockStorageKey)).toEqual([]); + expect(getRecentlyUsedSuggestions(mockStorageKey)).toEqual([]); }); }); @@ -366,7 +366,7 @@ describe('setTokenValueToRecentlyUsed', () => { localStorage.removeItem(mockStorageKey); }); - it('adds provided tokenValue to localStorage for recentTokenValuesStorageKey', () => { + it('adds provided tokenValue to localStorage for recentSuggestionsStorageKey', () => { setLocalStorageAvailability(true); setTokenValueToRecentlyUsed(mockStorageKey, mockTokenValue1); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js index 951b050495c..74f579e77ed 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/author_token_spec.js @@ -94,7 +94,7 @@ describe('AuthorToken', () => { it('calls `config.fetchAuthors` with provided searchTerm param', () => { 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( mockAuthorToken.fetchPath, @@ -105,17 +105,17 @@ describe('AuthorToken', () => { it('sets response to `authors` when request is succesful', () => { jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockResolvedValue(mockAuthors); - getBaseToken().vm.$emit('fetch-token-values', 'root'); + getBaseToken().vm.$emit('fetch-suggestions', 'root'); 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', () => { jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({}); - getBaseToken().vm.$emit('fetch-token-values', 'root'); + getBaseToken().vm.$emit('fetch-suggestions', 'root'); return waitForPromises().then(() => { expect(createFlash).toHaveBeenCalledWith({ @@ -127,17 +127,17 @@ describe('AuthorToken', () => { it('sets `loading` to false when request completes', async () => { jest.spyOn(wrapper.vm.config, 'fetchAuthors').mockRejectedValue({}); - getBaseToken().vm.$emit('fetch-token-values', 'root'); + getBaseToken().vm.$emit('fetch-suggestions', 'root'); await waitForPromises(); - expect(getBaseToken().props('tokensListLoading')).toBe(false); + expect(getBaseToken().props('suggestionsLoading')).toBe(false); }); }); }); describe('template', () => { - const activateTokenValuesList = async () => { + const activateSuggestionsList = async () => { const tokenSegments = wrapper.findAllComponents(GlFilteredSearchTokenSegment); const suggestionsSegment = tokenSegments.at(2); suggestionsSegment.vm.$emit('activate'); @@ -154,7 +154,7 @@ describe('AuthorToken', () => { expect(baseTokenEl.exists()).toBe(true); expect(baseTokenEl.props()).toMatchObject({ - tokenValues: mockAuthors, + suggestions: mockAuthors, fnActiveTokenValue: wrapper.vm.getActiveAuthor, }); }); @@ -221,7 +221,7 @@ describe('AuthorToken', () => { stubs: { Portal: true }, }); - await activateTokenValuesList(); + await activateSuggestionsList(); const suggestions = wrapper.findAll(GlFilteredSearchSuggestion); @@ -252,7 +252,7 @@ describe('AuthorToken', () => { stubs: { Portal: true }, }); - await activateTokenValuesList(); + await activateSuggestionsList(); const suggestions = wrapper.findAll(GlFilteredSearchSuggestion); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js index 89c5cedc9b8..cd6ffd679d0 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/base_token_spec.js @@ -7,7 +7,7 @@ import { import { DEFAULT_LABELS } from '~/vue_shared/components/filtered_search_bar/constants'; import { - getRecentlyUsedTokenValues, + getRecentlyUsedSuggestions, setTokenValueToRecentlyUsed, } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils'; import BaseToken from '~/vue_shared/components/filtered_search_bar/tokens/base_token.vue'; @@ -49,10 +49,10 @@ const mockProps = { config: mockLabelToken, value: { data: '' }, active: false, - tokenValues: [], - tokensListLoading: false, - defaultTokenValues: DEFAULT_LABELS, - recentTokenValuesStorageKey: mockStorageKey, + suggestions: [], + suggestionsLoading: false, + defaultSuggestions: DEFAULT_LABELS, + recentSuggestionsStorageKey: mockStorageKey, fnCurrentTokenValue: jest.fn(), }; @@ -83,7 +83,7 @@ describe('BaseToken', () => { props: { ...mockProps, value: { data: `"${mockRegularLabel.title}"` }, - tokenValues: mockLabels, + suggestions: mockLabels, }, }); }); @@ -93,8 +93,8 @@ describe('BaseToken', () => { }); describe('data', () => { - it('calls `getRecentlyUsedTokenValues` to populate `recentTokenValues` when `recentTokenValuesStorageKey` is defined', () => { - expect(getRecentlyUsedTokenValues).toHaveBeenCalledWith(mockStorageKey); + it('calls `getRecentlyUsedSuggestions` to populate `recentSuggestions` when `recentSuggestionsStorageKey` is defined', () => { + expect(getRecentlyUsedSuggestions).toHaveBeenCalledWith(mockStorageKey); }); }); @@ -147,15 +147,15 @@ describe('BaseToken', () => { 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({ active: false, }); await wrapperWithTokenActive.vm.$nextTick(); - expect(wrapperWithTokenActive.emitted('fetch-token-values')).toBeTruthy(); - expect(wrapperWithTokenActive.emitted('fetch-token-values')).toEqual([ + expect(wrapperWithTokenActive.emitted('fetch-suggestions')).toBeTruthy(); + expect(wrapperWithTokenActive.emitted('fetch-suggestions')).toEqual([ [`"${mockRegularLabel.title}"`], ]); }); @@ -164,7 +164,7 @@ describe('BaseToken', () => { describe('methods', () => { describe('handleTokenValueSelected', () => { - it('calls `setTokenValueToRecentlyUsed` when `recentTokenValuesStorageKey` is defined', () => { + it('calls `setTokenValueToRecentlyUsed` when `recentSuggestionsStorageKey` is defined', () => { const mockTokenValue = { id: 1, title: 'Foo', @@ -175,14 +175,14 @@ describe('BaseToken', () => { expect(setTokenValueToRecentlyUsed).toHaveBeenCalledWith(mockStorageKey, mockTokenValue); }); - it('does not add token from preloadedTokenValues', async () => { + it('does not add token from preloadedSuggestions', async () => { const mockTokenValue = { id: 1, title: 'Foo', }; wrapper.setProps({ - preloadedTokenValues: [mockTokenValue], + preloadedSuggestions: [mockTokenValue], }); await wrapper.vm.$nextTick(); @@ -228,7 +228,7 @@ describe('BaseToken', () => { 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(); wrapperWithNoStubs.find(GlFilteredSearchToken).vm.$emit('input', { data: 'foo' }); @@ -236,8 +236,8 @@ describe('BaseToken', () => { jest.runAllTimers(); - expect(wrapperWithNoStubs.emitted('fetch-token-values')).toBeTruthy(); - expect(wrapperWithNoStubs.emitted('fetch-token-values')[2]).toEqual(['foo']); + expect(wrapperWithNoStubs.emitted('fetch-suggestions')).toBeTruthy(); + expect(wrapperWithNoStubs.emitted('fetch-suggestions')[2]).toEqual(['foo']); }); }); }); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/iteration_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/iteration_token_spec.js index ca5dc984ae0..bd654c5a9cb 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/iteration_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/iteration_token_spec.js @@ -7,7 +7,7 @@ import { mockIterationToken } from '../mock_data'; jest.mock('~/flash'); describe('IterationToken', () => { - const title = 'gitlab-org: #1'; + const id = 123; let wrapper; const createComponent = ({ config = mockIterationToken, value = { data: '' } } = {}) => @@ -28,14 +28,14 @@ describe('IterationToken', () => { }); it('renders iteration value', async () => { - wrapper = createComponent({ value: { data: title } }); + wrapper = createComponent({ value: { data: id } }); await wrapper.vm.$nextTick(); const tokenSegments = wrapper.findAllComponents(GlFilteredSearchTokenSegment); expect(tokenSegments).toHaveLength(3); // `Iteration` `=` `gitlab-org: #1` - expect(tokenSegments.at(2).text()).toBe(title); + expect(tokenSegments.at(2).text()).toBe(id.toString()); }); it('fetches initial values', () => { @@ -43,10 +43,10 @@ describe('IterationToken', () => { wrapper = createComponent({ config: { ...mockIterationToken, fetchIterations: fetchIterationsSpy }, - value: { data: title }, + value: { data: id }, }); - expect(fetchIterationsSpy).toHaveBeenCalledWith(title); + expect(fetchIterationsSpy).toHaveBeenCalledWith(id); }); it('fetches iterations on user input', () => { diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js index cc40ff96b65..ec9458f64d2 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/label_token_spec.js @@ -159,7 +159,7 @@ describe('LabelToken', () => { expect(baseTokenEl.exists()).toBe(true); expect(baseTokenEl.props()).toMatchObject({ - tokenValues: mockLabels, + suggestions: mockLabels, fnActiveTokenValue: wrapper.vm.getActiveLabel, }); }); diff --git a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/milestone_token_spec.js b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/milestone_token_spec.js index 9f550ac9afc..74ceb03bb96 100644 --- a/spec/frontend/vue_shared/components/filtered_search_bar/tokens/milestone_token_spec.js +++ b/spec/frontend/vue_shared/components/filtered_search_bar/tokens/milestone_token_spec.js @@ -9,6 +9,7 @@ import MockAdapter from 'axios-mock-adapter'; import waitForPromises from 'helpers/wait_for_promises'; import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; +import { sortMilestonesByDueDate } from '~/milestones/milestone_utils'; import { DEFAULT_MILESTONES } from '~/vue_shared/components/filtered_search_bar/constants'; import MilestoneToken from '~/vue_shared/components/filtered_search_bar/tokens/milestone_token.vue'; @@ -21,6 +22,7 @@ import { } from '../mock_data'; jest.mock('~/flash'); +jest.mock('~/milestones/milestone_utils'); const defaultStubs = { Portal: true, @@ -112,6 +114,7 @@ describe('MilestoneToken', () => { return waitForPromises().then(() => { expect(wrapper.vm.milestones).toEqual(mockMilestones); + expect(sortMilestonesByDueDate).toHaveBeenCalled(); }); }); |