diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/frontend/filtered_search/filtered_search_manager_spec.js | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/frontend/filtered_search/filtered_search_manager_spec.js')
-rw-r--r-- | spec/frontend/filtered_search/filtered_search_manager_spec.js | 46 |
1 files changed, 40 insertions, 6 deletions
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')} |