diff options
author | Alexis Reigel <alexis.reigel.ext@siemens.com> | 2018-06-26 17:21:38 +0300 |
---|---|---|
committer | Alexis Reigel <alexis.reigel.ext@siemens.com> | 2018-08-20 18:15:11 +0300 |
commit | d4387d88767d76666e32feaab9deb48d43b6249a (patch) | |
tree | fe267dbfe928bdc016203168aca3785deea44c76 /spec/javascripts/filtered_search | |
parent | 0a0350be00645f9774e419afd356006e15cb1a89 (diff) |
make FilteredSearchTokenKeys generic
for the current usage for the issues search bar a specific instance of
FilteredSearchTokenKeys is created, which contains the config for that
case.
Diffstat (limited to 'spec/javascripts/filtered_search')
6 files changed, 45 insertions, 45 deletions
diff --git a/spec/javascripts/filtered_search/components/recent_searches_dropdown_content_spec.js b/spec/javascripts/filtered_search/components/recent_searches_dropdown_content_spec.js index d926663fac0..824cdf4c14b 100644 --- a/spec/javascripts/filtered_search/components/recent_searches_dropdown_content_spec.js +++ b/spec/javascripts/filtered_search/components/recent_searches_dropdown_content_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import eventHub from '~/filtered_search/event_hub'; import RecentSearchesDropdownContent from '~/filtered_search/components/recent_searches_dropdown_content.vue'; -import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; +import IssuesFilteredSearchTokenKeys from '~/filtered_search/issues_filtered_search_token_keys'; const createComponent = (propsData) => { const Component = Vue.extend(RecentSearchesDropdownContent); @@ -18,14 +18,14 @@ const trimMarkupWhitespace = text => text.replace(/(\n|\s)+/gm, ' ').trim(); describe('RecentSearchesDropdownContent', () => { const propsDataWithoutItems = { items: [], - allowedKeys: FilteredSearchTokenKeys.getKeys(), + allowedKeys: IssuesFilteredSearchTokenKeys.getKeys(), }; const propsDataWithItems = { items: [ 'foo', 'author:@root label:~foo bar', ], - allowedKeys: FilteredSearchTokenKeys.getKeys(), + allowedKeys: IssuesFilteredSearchTokenKeys.getKeys(), }; let vm; diff --git a/spec/javascripts/filtered_search/dropdown_user_spec.js b/spec/javascripts/filtered_search/dropdown_user_spec.js index c37a964975d..06d91a6de57 100644 --- a/spec/javascripts/filtered_search/dropdown_user_spec.js +++ b/spec/javascripts/filtered_search/dropdown_user_spec.js @@ -1,7 +1,7 @@ import DropdownUtils from '~/filtered_search/dropdown_utils'; import DropdownUser from '~/filtered_search/dropdown_user'; import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer'; -import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; +import IssuesFilteredSearchTokenKeys from '~/filtered_search/issues_filtered_search_token_keys'; describe('Dropdown User', () => { describe('getSearchInput', () => { @@ -14,7 +14,7 @@ describe('Dropdown User', () => { spyOn(DropdownUtils, 'getSearchInput').and.callFake(() => {}); dropdownUser = new DropdownUser({ - tokenKeys: FilteredSearchTokenKeys, + tokenKeys: IssuesFilteredSearchTokenKeys, }); }); diff --git a/spec/javascripts/filtered_search/dropdown_utils_spec.js b/spec/javascripts/filtered_search/dropdown_utils_spec.js index 3d6dec19eca..11360d8bd19 100644 --- a/spec/javascripts/filtered_search/dropdown_utils_spec.js +++ b/spec/javascripts/filtered_search/dropdown_utils_spec.js @@ -1,6 +1,6 @@ import DropdownUtils from '~/filtered_search/dropdown_utils'; import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager'; -import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; +import IssuesFilteredSearchTokenKeys from '~/filtered_search/issues_filtered_search_token_keys'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; describe('Dropdown Utils', () => { @@ -137,7 +137,7 @@ describe('Dropdown Utils', () => { `); input = document.getElementById('test'); - allowedKeys = FilteredSearchTokenKeys.getKeys(); + allowedKeys = IssuesFilteredSearchTokenKeys.getKeys(); }); function config() { diff --git a/spec/javascripts/filtered_search/filtered_search_manager_spec.js b/spec/javascripts/filtered_search/filtered_search_manager_spec.js index 8fcee36beb8..63f2d2cfa0b 100644 --- a/spec/javascripts/filtered_search/filtered_search_manager_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_manager_spec.js @@ -1,7 +1,7 @@ import RecentSearchesService from '~/filtered_search/services/recent_searches_service'; import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error'; import RecentSearchesRoot from '~/filtered_search/recent_searches_root'; -import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; +import IssuesFilteredSearchTokenKeys from '~/filtered_search/issues_filtered_search_token_keys'; import '~/lib/utils/common_utils'; import DropdownUtils from '~/filtered_search/dropdown_utils'; import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens'; @@ -86,7 +86,7 @@ describe('Filtered Search Manager', function () { expect(RecentSearchesService.isAvailable).toHaveBeenCalled(); expect(RecentSearchesStoreSpy).toHaveBeenCalledWith({ isLocalStorageAvailable, - allowedKeys: FilteredSearchTokenKeys.getKeys(), + allowedKeys: IssuesFilteredSearchTokenKeys.getKeys(), }); }); }); diff --git a/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js b/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js index 68158cf52e4..ab0ab72720e 100644 --- a/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js @@ -1,26 +1,36 @@ import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; describe('Filtered Search Token Keys', () => { - describe('get', () => { - let tokenKeys; + const tokenKeys = [{ + key: 'author', + type: 'string', + param: 'username', + symbol: '@', + icon: 'pencil', + tag: '@author', + }]; + + const conditions = [{ + url: 'assignee_id=0', + tokenKey: 'assignee', + value: 'none', + }]; - beforeEach(() => { - tokenKeys = FilteredSearchTokenKeys.get(); - }); + describe('get', () => { it('should return tokenKeys', () => { - expect(tokenKeys !== null).toBe(true); + expect(new FilteredSearchTokenKeys().get() !== null).toBe(true); }); it('should return tokenKeys as an array', () => { - expect(tokenKeys instanceof Array).toBe(true); + expect(new FilteredSearchTokenKeys().get() instanceof Array).toBe(true); }); }); describe('getKeys', () => { it('should return keys', () => { - const getKeys = FilteredSearchTokenKeys.getKeys(); - const keys = FilteredSearchTokenKeys.get().map(i => i.key); + const getKeys = new FilteredSearchTokenKeys(tokenKeys).getKeys(); + const keys = new FilteredSearchTokenKeys(tokenKeys).get().map(i => i.key); keys.forEach((key, i) => { expect(key).toEqual(getKeys[i]); @@ -29,88 +39,78 @@ describe('Filtered Search Token Keys', () => { }); describe('getConditions', () => { - let conditions; - - beforeEach(() => { - conditions = FilteredSearchTokenKeys.getConditions(); - }); - it('should return conditions', () => { - expect(conditions !== null).toBe(true); + expect(new FilteredSearchTokenKeys().getConditions() !== null).toBe(true); }); it('should return conditions as an array', () => { - expect(conditions instanceof Array).toBe(true); + expect(new FilteredSearchTokenKeys().getConditions() instanceof Array).toBe(true); }); }); describe('searchByKey', () => { it('should return null when key not found', () => { - const tokenKey = FilteredSearchTokenKeys.searchByKey('notakey'); + const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKey('notakey'); expect(tokenKey === null).toBe(true); }); it('should return tokenKey when found by key', () => { - const tokenKeys = FilteredSearchTokenKeys.get(); - const result = FilteredSearchTokenKeys.searchByKey(tokenKeys[0].key); + const result = new FilteredSearchTokenKeys(tokenKeys).searchByKey(tokenKeys[0].key); expect(result).toEqual(tokenKeys[0]); }); }); describe('searchBySymbol', () => { it('should return null when symbol not found', () => { - const tokenKey = FilteredSearchTokenKeys.searchBySymbol('notasymbol'); + const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol('notasymbol'); expect(tokenKey === null).toBe(true); }); it('should return tokenKey when found by symbol', () => { - const tokenKeys = FilteredSearchTokenKeys.get(); - const result = FilteredSearchTokenKeys.searchBySymbol(tokenKeys[0].symbol); + const result = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol(tokenKeys[0].symbol); expect(result).toEqual(tokenKeys[0]); }); }); describe('searchByKeyParam', () => { it('should return null when key param not found', () => { - const tokenKey = FilteredSearchTokenKeys.searchByKeyParam('notakeyparam'); + const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam('notakeyparam'); expect(tokenKey === null).toBe(true); }); it('should return tokenKey when found by key param', () => { - const tokenKeys = FilteredSearchTokenKeys.get(); - const result = FilteredSearchTokenKeys.searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); + const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); expect(result).toEqual(tokenKeys[0]); }); it('should return alternative tokenKey when found by key param', () => { - const tokenKeys = FilteredSearchTokenKeys.getAlternatives(); - const result = FilteredSearchTokenKeys.searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); + const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); expect(result).toEqual(tokenKeys[0]); }); }); describe('searchByConditionUrl', () => { it('should return null when condition url not found', () => { - const condition = FilteredSearchTokenKeys.searchByConditionUrl(null); + const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl(null); expect(condition === null).toBe(true); }); it('should return condition when found by url', () => { - const conditions = FilteredSearchTokenKeys.getConditions(); - const result = FilteredSearchTokenKeys.searchByConditionUrl(conditions[0].url); + const result = new FilteredSearchTokenKeys([], [], conditions) + .searchByConditionUrl(conditions[0].url); expect(result).toBe(conditions[0]); }); }); describe('searchByConditionKeyValue', () => { it('should return null when condition tokenKey and value not found', () => { - const condition = FilteredSearchTokenKeys.searchByConditionKeyValue(null, null); + const condition = new FilteredSearchTokenKeys([], [], conditions) + .searchByConditionKeyValue(null, null); expect(condition === null).toBe(true); }); it('should return condition when found by tokenKey and value', () => { - const conditions = FilteredSearchTokenKeys.getConditions(); - const result = FilteredSearchTokenKeys + const result = new FilteredSearchTokenKeys([], [], conditions) .searchByConditionKeyValue(conditions[0].tokenKey, conditions[0].value); expect(result).toEqual(conditions[0]); }); diff --git a/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js b/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js index 465f5f79931..5bbba232300 100644 --- a/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js @@ -1,8 +1,8 @@ -import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; +import IssuesFilteredSearchTokenKeys from '~/filtered_search/issues_filtered_search_token_keys'; import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer'; describe('Filtered Search Tokenizer', () => { - const allowedKeys = FilteredSearchTokenKeys.getKeys(); + const allowedKeys = IssuesFilteredSearchTokenKeys.getKeys(); describe('processTokens', () => { it('returns for input containing only search value', () => { |