diff options
Diffstat (limited to 'spec/frontend/filtered_search')
5 files changed, 50 insertions, 12 deletions
diff --git a/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js b/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js index c0851096d8e..158f70f7d47 100644 --- a/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js +++ b/spec/frontend/filtered_search/components/recent_searches_dropdown_content_spec.js @@ -57,7 +57,11 @@ describe('Recent Searches Dropdown Content', () => { beforeEach(() => { createComponent({ - items: ['foo', 'author:@root label:~foo bar'], + items: [ + 'foo', + 'author:@root label:~foo bar', + [{ type: 'author_username', value: { data: 'toby', operator: '=' } }], + ], isLocalStorageAvailable: true, }); }); @@ -76,7 +80,7 @@ describe('Recent Searches Dropdown Content', () => { }); it('renders a correct amount of dropdown items', () => { - expect(findDropdownItems()).toHaveLength(2); + expect(findDropdownItems()).toHaveLength(2); // Ignore non-string recent item }); it('expect second dropdown to have 2 tokens', () => { diff --git a/spec/frontend/filtered_search/filtered_search_manager_spec.js b/spec/frontend/filtered_search/filtered_search_manager_spec.js index 70e8b339d4b..53c726a6cea 100644 --- a/spec/frontend/filtered_search/filtered_search_manager_spec.js +++ b/spec/frontend/filtered_search/filtered_search_manager_spec.js @@ -77,7 +77,7 @@ describe('Filtered Search Manager', () => { jest.spyOn(FilteredSearchDropdownManager.prototype, 'setDropdown').mockImplementation(); }); - const initializeManager = () => { + const initializeManager = ({ useDefaultState } = {}) => { jest.spyOn(FilteredSearchManager.prototype, 'loadSearchParamsFromURL').mockImplementation(); jest.spyOn(FilteredSearchManager.prototype, 'tokenChange').mockImplementation(); jest @@ -88,7 +88,7 @@ describe('Filtered Search Manager', () => { input = document.querySelector('.filtered-search'); tokensContainer = document.querySelector('.tokens-container'); - manager = new FilteredSearchManager({ page }); + manager = new FilteredSearchManager({ page, useDefaultState }); manager.setup(); }; @@ -184,17 +184,27 @@ describe('Filtered Search Manager', () => { }); describe('search', () => { - const defaultParams = '?scope=all&utf8=%E2%9C%93&state=opened'; + const defaultParams = '?scope=all&utf8=%E2%9C%93'; + const defaultState = '&state=opened'; - beforeEach(() => { + it('should search with a single word', done => { initializeManager(); + input.value = 'searchTerm'; + + visitUrl.mockImplementation(url => { + expect(url).toEqual(`${defaultParams}&search=searchTerm`); + done(); + }); + + manager.search(); }); - it('should search with a single word', done => { + it('sets default state', done => { + initializeManager({ useDefaultState: true }); input.value = 'searchTerm'; visitUrl.mockImplementation(url => { - expect(url).toEqual(`${defaultParams}&search=searchTerm`); + expect(url).toEqual(`${defaultParams}${defaultState}&search=searchTerm`); done(); }); @@ -202,6 +212,7 @@ describe('Filtered Search Manager', () => { }); it('should search with multiple words', done => { + initializeManager(); input.value = 'awesome search terms'; visitUrl.mockImplementation(url => { @@ -213,6 +224,7 @@ describe('Filtered Search Manager', () => { }); it('should search with special characters', done => { + initializeManager(); input.value = '~!@#$%^&*()_+{}:<>,.?/'; visitUrl.mockImplementation(url => { @@ -225,7 +237,29 @@ describe('Filtered Search Manager', () => { manager.search(); }); + it('should use replacement URL for condition', done => { + initializeManager(); + tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML( + FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', '13', true), + ); + + visitUrl.mockImplementation(url => { + expect(url).toEqual(`${defaultParams}&milestone_title=replaced`); + done(); + }); + + manager.filteredSearchTokenKeys.conditions.push({ + url: 'milestone_title=13', + replacementUrl: 'milestone_title=replaced', + tokenKey: 'milestone', + value: '13', + operator: '=', + }); + manager.search(); + }); + it('removes duplicated tokens', done => { + initializeManager(); tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(` ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug')} ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug')} diff --git a/spec/frontend/filtered_search/filtered_search_visual_tokens_spec.js b/spec/frontend/filtered_search/filtered_search_visual_tokens_spec.js index e59ee925cc7..6a00065c9fe 100644 --- a/spec/frontend/filtered_search/filtered_search_visual_tokens_spec.js +++ b/spec/frontend/filtered_search/filtered_search_visual_tokens_spec.js @@ -280,8 +280,8 @@ describe('Filtered Search Visual Tokens', () => { ); }); - it('contains fa-close icon', () => { - expect(tokenElement.querySelector('.remove-token .fa-close')).toEqual(expect.anything()); + it('contains close icon', () => { + expect(tokenElement.querySelector('.remove-token .close-icon')).toEqual(expect.anything()); }); }); }); diff --git a/spec/frontend/filtered_search/services/recent_searches_service_spec.js b/spec/frontend/filtered_search/services/recent_searches_service_spec.js index a89d38b7a20..afeca54b949 100644 --- a/spec/frontend/filtered_search/services/recent_searches_service_spec.js +++ b/spec/frontend/filtered_search/services/recent_searches_service_spec.js @@ -1,7 +1,7 @@ +import { useLocalStorageSpy } from 'helpers/local_storage_helper'; import RecentSearchesService from '~/filtered_search/services/recent_searches_service'; import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error'; import AccessorUtilities from '~/lib/utils/accessor'; -import { useLocalStorageSpy } from 'helpers/local_storage_helper'; useLocalStorageSpy(); diff --git a/spec/frontend/filtered_search/visual_token_value_spec.js b/spec/frontend/filtered_search/visual_token_value_spec.js index 3a64b688c7a..e2855b29b70 100644 --- a/spec/frontend/filtered_search/visual_token_value_spec.js +++ b/spec/frontend/filtered_search/visual_token_value_spec.js @@ -1,10 +1,10 @@ import { escape } from 'lodash'; +import { TEST_HOST } from 'jest/helpers/test_constants'; import VisualTokenValue from '~/filtered_search/visual_token_value'; import AjaxCache from '~/lib/utils/ajax_cache'; import UsersCache from '~/lib/utils/users_cache'; import DropdownUtils from '~/filtered_search//dropdown_utils'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; -import { TEST_HOST } from 'jest/helpers/test_constants'; describe('Filtered Search Visual Tokens', () => { const findElements = tokenElement => { |