diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-10-17 10:13:26 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-10-17 19:18:17 +0300 |
commit | f666026d71ebefd70219d5078b1f0c83fa01f84d (patch) | |
tree | ce43feb99c12c21dd266d25de24b1768bac1d459 /spec/javascripts/filtered_search | |
parent | 5a6fffcffca3dc8e4f52c90d3d18eaefd9e48aef (diff) |
Prettify all spec files
Diffstat (limited to 'spec/javascripts/filtered_search')
10 files changed, 271 insertions, 190 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 23a03558b38..d1742dcedfa 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 @@ -3,7 +3,7 @@ import eventHub from '~/filtered_search/event_hub'; import RecentSearchesDropdownContent from '~/filtered_search/components/recent_searches_dropdown_content.vue'; import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; -const createComponent = (propsData) => { +const createComponent = propsData => { const Component = Vue.extend(RecentSearchesDropdownContent); return new Component({ @@ -21,10 +21,7 @@ describe('RecentSearchesDropdownContent', () => { allowedKeys: IssuableFilteredSearchTokenKeys.getKeys(), }; const propsDataWithItems = { - items: [ - 'foo', - 'author:@root label:~foo bar', - ], + items: ['foo', 'author:@root label:~foo bar'], allowedKeys: IssuableFilteredSearchTokenKeys.getKeys(), }; @@ -69,7 +66,11 @@ describe('RecentSearchesDropdownContent', () => { expect(items.length).toEqual(propsDataWithItems.items.length); - expect(trimMarkupWhitespace(items[0].querySelector('.filtered-search-history-dropdown-search-token').textContent)).toEqual('foo'); + expect( + trimMarkupWhitespace( + items[0].querySelector('.filtered-search-history-dropdown-search-token').textContent, + ), + ).toEqual('foo'); const item1Tokens = items[1].querySelectorAll('.filtered-search-history-dropdown-token'); @@ -78,7 +79,11 @@ describe('RecentSearchesDropdownContent', () => { expect(item1Tokens[0].querySelector('.value').textContent).toEqual('@root'); expect(item1Tokens[1].querySelector('.name').textContent).toEqual('label:'); expect(item1Tokens[1].querySelector('.value').textContent).toEqual('~foo'); - expect(trimMarkupWhitespace(items[1].querySelector('.filtered-search-history-dropdown-search-token').textContent)).toEqual('bar'); + expect( + trimMarkupWhitespace( + items[1].querySelector('.filtered-search-history-dropdown-search-token').textContent, + ), + ).toEqual('bar'); }); }); diff --git a/spec/javascripts/filtered_search/dropdown_user_spec.js b/spec/javascripts/filtered_search/dropdown_user_spec.js index 9f4e8ab6234..e8fcc8592eb 100644 --- a/spec/javascripts/filtered_search/dropdown_user_spec.js +++ b/spec/javascripts/filtered_search/dropdown_user_spec.js @@ -28,14 +28,14 @@ describe('Dropdown User', () => { it('should not return the single quote found in value', () => { spyOn(FilteredSearchTokenizer, 'processTokens').and.returnValue({ - lastToken: '\'larry boy', + lastToken: "'larry boy", }); expect(dropdownUser.getSearchInput()).toBe('larry boy'); }); }); - describe('config AjaxFilter\'s endpoint', () => { + describe("config AjaxFilter's endpoint", () => { beforeEach(() => { spyOn(DropdownUser.prototype, 'bindEvents').and.callFake(() => {}); spyOn(DropdownUser.prototype, 'getProjectId').and.callFake(() => {}); @@ -88,7 +88,8 @@ describe('Dropdown User', () => { }); }); - const findCurrentUserElement = () => authorFilterDropdownElement.querySelector('.js-current-user'); + const findCurrentUserElement = () => + authorFilterDropdownElement.querySelector('.js-current-user'); it('hides the current user from dropdown', () => { const currentUserElement = findCurrentUserElement(); diff --git a/spec/javascripts/filtered_search/dropdown_utils_spec.js b/spec/javascripts/filtered_search/dropdown_utils_spec.js index 52b54973047..6605b0a30d7 100644 --- a/spec/javascripts/filtered_search/dropdown_utils_spec.js +++ b/spec/javascripts/filtered_search/dropdown_utils_spec.js @@ -19,7 +19,7 @@ describe('Dropdown Utils', () => { expect(escaped).toBe('"text with space"'); - escaped = DropdownUtils.getEscapedText('won\'t fix'); + escaped = DropdownUtils.getEscapedText("won't fix"); expect(escaped).toBe('"won\'t fix"'); }); @@ -27,13 +27,13 @@ describe('Dropdown Utils', () => { it('should escape with single quotes', () => { const escaped = DropdownUtils.getEscapedText('won"t fix'); - expect(escaped).toBe('\'won"t fix\''); + expect(escaped).toBe("'won\"t fix'"); }); it('should escape with single quotes by default', () => { const escaped = DropdownUtils.getEscapedText('won"t\' fix'); - expect(escaped).toBe('\'won"t\' fix\''); + expect(escaped).toBe("'won\"t' fix'"); }); }); @@ -105,7 +105,7 @@ describe('Dropdown Utils', () => { }); it('should filter with single quote', () => { - input.value = '\''; + input.value = "'"; const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); @@ -113,7 +113,7 @@ describe('Dropdown Utils', () => { }); it('should filter with single quote and symbol', () => { - input.value = '~\''; + input.value = "~'"; const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); @@ -121,7 +121,7 @@ describe('Dropdown Utils', () => { }); it('should filter with single quote and multiple words', () => { - input.value = '\'community con'; + input.value = "'community con"; const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); @@ -129,7 +129,7 @@ describe('Dropdown Utils', () => { }); it('should filter with single quote, symbol and multiple words', () => { - input.value = '~\'community con'; + input.value = "~'community con"; const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); @@ -246,23 +246,40 @@ describe('Dropdown Utils', () => { it('should linear-gradient 2 colors', () => { const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000']); - expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 50%, #000000 50%, #000000 100%)'); + expect(gradient).toEqual( + 'linear-gradient(#FFFFFF 0%, #FFFFFF 50%, #000000 50%, #000000 100%)', + ); }); it('should linear-gradient 3 colors', () => { const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333']); - expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 33%, #000000 33%, #000000 66%, #333333 66%, #333333 100%)'); + expect(gradient).toEqual( + 'linear-gradient(#FFFFFF 0%, #FFFFFF 33%, #000000 33%, #000000 66%, #333333 66%, #333333 100%)', + ); }); it('should linear-gradient 4 colors', () => { - const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD']); - - expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 25%, #000000 25%, #000000 50%, #333333 50%, #333333 75%, #DDDDDD 75%, #DDDDDD 100%)'); + const gradient = DropdownUtils.duplicateLabelColor([ + '#FFFFFF', + '#000000', + '#333333', + '#DDDDDD', + ]); + + expect(gradient).toEqual( + 'linear-gradient(#FFFFFF 0%, #FFFFFF 25%, #000000 25%, #000000 50%, #333333 50%, #333333 75%, #DDDDDD 75%, #DDDDDD 100%)', + ); }); it('should not linear-gradient more than 4 colors', () => { - const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD', '#EEEEEE']); + const gradient = DropdownUtils.duplicateLabelColor([ + '#FFFFFF', + '#000000', + '#333333', + '#DDDDDD', + '#EEEEEE', + ]); expect(gradient.indexOf('#EEEEEE')).toBe(-1); }); @@ -276,13 +293,16 @@ describe('Dropdown Utils', () => { }); it('should not mutate existing data if there are no duplicates', () => { - const data = [{ - title: 'label1', - color: '#FFFFFF', - }, { - title: 'label2', - color: '#000000', - }]; + const data = [ + { + title: 'label1', + color: '#FFFFFF', + }, + { + title: 'label2', + color: '#000000', + }, + ]; const results = DropdownUtils.duplicateLabelPreprocessing(data); expect(results.length).toEqual(2); @@ -291,13 +311,16 @@ describe('Dropdown Utils', () => { }); describe('duplicate labels', () => { - const data = [{ - title: 'label', - color: '#FFFFFF', - }, { - title: 'label', - color: '#000000', - }]; + const data = [ + { + title: 'label', + color: '#FFFFFF', + }, + { + title: 'label', + color: '#000000', + }, + ]; const results = DropdownUtils.duplicateLabelPreprocessing(data); it('should merge duplicate labels', () => { diff --git a/spec/javascripts/filtered_search/filtered_search_manager_spec.js b/spec/javascripts/filtered_search/filtered_search_manager_spec.js index 5a985e97a34..e076120f5cc 100644 --- a/spec/javascripts/filtered_search/filtered_search_manager_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_manager_spec.js @@ -9,7 +9,7 @@ import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dro import FilteredSearchManager from '~/filtered_search/filtered_search_manager'; import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; -describe('Filtered Search Manager', function () { +describe('Filtered Search Manager', function() { let input; let manager; let tokensContainer; @@ -97,7 +97,9 @@ describe('Filtered Search Manager', function () { }); it('should not instantiate Flash if an RecentSearchesServiceError is caught', () => { - spyOn(RecentSearchesService.prototype, 'fetch').and.callFake(() => Promise.reject(new RecentSearchesServiceError())); + spyOn(RecentSearchesService.prototype, 'fetch').and.callFake(() => + Promise.reject(new RecentSearchesServiceError()), + ); spyOn(window, 'Flash'); manager.setup(); @@ -162,10 +164,10 @@ describe('Filtered Search Manager', function () { initializeManager(); }); - it('should search with a single word', (done) => { + it('should search with a single word', done => { input.value = 'searchTerm'; - spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake((url) => { + spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake(url => { expect(url).toEqual(`${defaultParams}&search=searchTerm`); done(); }); @@ -173,10 +175,10 @@ describe('Filtered Search Manager', function () { manager.search(); }); - it('should search with multiple words', (done) => { + it('should search with multiple words', done => { input.value = 'awesome search terms'; - spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake((url) => { + spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake(url => { expect(url).toEqual(`${defaultParams}&search=awesome+search+terms`); done(); }); @@ -184,24 +186,26 @@ describe('Filtered Search Manager', function () { manager.search(); }); - it('should search with special characters', (done) => { + it('should search with special characters', done => { input.value = '~!@#$%^&*()_+{}:<>,.?/'; - spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake((url) => { - expect(url).toEqual(`${defaultParams}&search=~!%40%23%24%25%5E%26*()_%2B%7B%7D%3A%3C%3E%2C.%3F%2F`); + spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake(url => { + expect(url).toEqual( + `${defaultParams}&search=~!%40%23%24%25%5E%26*()_%2B%7B%7D%3A%3C%3E%2C.%3F%2F`, + ); done(); }); manager.search(); }); - it('removes duplicated tokens', (done) => { + it('removes duplicated tokens', done => { tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(` ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '~bug')} ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '~bug')} `); - spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake((url) => { + spyOnDependency(FilteredSearchManager, 'visitUrl').and.callFake(url => { expect(url).toEqual(`${defaultParams}&label_name[]=bug`); done(); }); @@ -441,13 +445,17 @@ describe('Filtered Search Manager', function () { it('toggles on focus', () => { input.focus(); - expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(true); + expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual( + true, + ); }); it('toggles on blur', () => { input.blur(); - expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(false); + expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual( + false, + ); }); }); @@ -459,9 +467,12 @@ describe('Filtered Search Manager', function () { }); it('correctly modifies params when custom modifier is passed', () => { - const modifedParams = manager.getAllParams.call({ - modifyUrlParams: paramsArr => paramsArr.reverse(), - }, [].concat(this.paramsArr)); + const modifedParams = manager.getAllParams.call( + { + modifyUrlParams: paramsArr => paramsArr.reverse(), + }, + [].concat(this.paramsArr), + ); expect(modifedParams[0]).toBe(this.paramsArr[1]); }); 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 20264caa5c4..d1fea18dea8 100644 --- a/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_token_keys_spec.js @@ -1,23 +1,26 @@ import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys'; describe('Filtered Search Token Keys', () => { - const tokenKeys = [{ - key: 'author', - type: 'string', - param: 'username', - symbol: '@', - icon: 'pencil', - tag: '@author', - }]; - - const conditions = [{ - url: 'assignee_id=0', - tokenKey: 'assignee', - value: 'none', - }]; + const tokenKeys = [ + { + key: 'author', + type: 'string', + param: 'username', + symbol: '@', + icon: 'pencil', + tag: '@author', + }, + ]; + + const conditions = [ + { + url: 'assignee_id=0', + tokenKey: 'assignee', + value: 'none', + }, + ]; describe('get', () => { - it('should return tokenKeys', () => { expect(new FilteredSearchTokenKeys().get()).not.toBeNull(); }); @@ -84,13 +87,17 @@ describe('Filtered Search Token Keys', () => { }); it('should return tokenKey when found by key param', () => { - const result = new FilteredSearchTokenKeys(tokenKeys).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 result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); + const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam( + `${tokenKeys[0].key}_${tokenKeys[0].param}`, + ); expect(result).toEqual(tokenKeys[0]); }); @@ -104,8 +111,9 @@ describe('Filtered Search Token Keys', () => { }); it('should return condition when found by url', () => { - const result = new FilteredSearchTokenKeys([], [], conditions) - .searchByConditionUrl(conditions[0].url); + const result = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl( + conditions[0].url, + ); expect(result).toBe(conditions[0]); }); @@ -113,15 +121,19 @@ describe('Filtered Search Token Keys', () => { describe('searchByConditionKeyValue', () => { it('should return null when condition tokenKey and value not found', () => { - const condition = new FilteredSearchTokenKeys([], [], conditions) - .searchByConditionKeyValue(null, null); + const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionKeyValue( + null, + null, + ); expect(condition).toBeNull(); }); it('should return condition when found by tokenKey and value', () => { - const result = new FilteredSearchTokenKeys([], [], conditions) - .searchByConditionKeyValue(conditions[0].tokenKey, conditions[0].value); + 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 d8eb75ec000..dec03e5ab93 100644 --- a/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js @@ -14,8 +14,10 @@ describe('Filtered Search Tokenizer', () => { }); it('returns for input containing only tokens', () => { - const results = FilteredSearchTokenizer - .processTokens('author:@root label:~"Very Important" milestone:%v1.0 assignee:none', allowedKeys); + const results = FilteredSearchTokenizer.processTokens( + 'author:@root label:~"Very Important" milestone:%v1.0 assignee:none', + allowedKeys, + ); expect(results.searchToken).toBe(''); expect(results.tokens.length).toBe(4); @@ -39,8 +41,10 @@ describe('Filtered Search Tokenizer', () => { }); it('returns for input starting with search value and ending with tokens', () => { - const results = FilteredSearchTokenizer - .processTokens('searchTerm anotherSearchTerm milestone:none', allowedKeys); + const results = FilteredSearchTokenizer.processTokens( + 'searchTerm anotherSearchTerm milestone:none', + allowedKeys, + ); expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); expect(results.tokens.length).toBe(1); @@ -51,8 +55,10 @@ describe('Filtered Search Tokenizer', () => { }); it('returns for input starting with tokens and ending with search value', () => { - const results = FilteredSearchTokenizer - .processTokens('assignee:@user searchTerm', allowedKeys); + const results = FilteredSearchTokenizer.processTokens( + 'assignee:@user searchTerm', + allowedKeys, + ); expect(results.searchToken).toBe('searchTerm'); expect(results.tokens.length).toBe(1); @@ -63,8 +69,10 @@ describe('Filtered Search Tokenizer', () => { }); it('returns for input containing search value wrapped between tokens', () => { - const results = FilteredSearchTokenizer - .processTokens('author:@root label:~"Won\'t fix" searchTerm anotherSearchTerm milestone:none', allowedKeys); + const results = FilteredSearchTokenizer.processTokens( + 'author:@root label:~"Won\'t fix" searchTerm anotherSearchTerm milestone:none', + allowedKeys, + ); expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); expect(results.tokens.length).toBe(3); @@ -84,8 +92,10 @@ describe('Filtered Search Tokenizer', () => { }); it('returns for input containing search value in between tokens', () => { - const results = FilteredSearchTokenizer - .processTokens('author:@root searchTerm assignee:none anotherSearchTerm label:~Doing', allowedKeys); + const results = FilteredSearchTokenizer.processTokens( + 'author:@root searchTerm assignee:none anotherSearchTerm label:~Doing', + allowedKeys, + ); expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); expect(results.tokens.length).toBe(3); diff --git a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js index b1fb474e755..9676055fbae 100644 --- a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js +++ b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js @@ -9,7 +9,7 @@ import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; describe('Filtered Search Visual Tokens', () => { const subject = FilteredSearchVisualTokens; - const findElements = (tokenElement) => { + const findElements = tokenElement => { const tokenNameElement = tokenElement.querySelector('.name'); const tokenValueContainer = tokenElement.querySelector('.value-container'); const tokenValueElement = tokenValueContainer.querySelector('.value'); @@ -34,8 +34,7 @@ describe('Filtered Search Visual Tokens', () => { describe('getLastVisualTokenBeforeInput', () => { it('returns when there are no visual tokens', () => { - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); expect(lastVisualToken).toEqual(null); expect(isLastVisualTokenValid).toEqual(true); @@ -47,8 +46,7 @@ describe('Filtered Search Visual Tokens', () => { bugLabelToken.outerHTML, ); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token')); expect(isLastVisualTokenValid).toEqual(true); @@ -59,8 +57,7 @@ describe('Filtered Search Visual Tokens', () => { FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('Author'), ); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token')); expect(isLastVisualTokenValid).toEqual(false); @@ -73,8 +70,7 @@ describe('Filtered Search Visual Tokens', () => { ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '@root')} `); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); const items = document.querySelectorAll('.tokens-container .js-visual-token'); expect(lastVisualToken.isEqualNode(items[items.length - 1])).toEqual(true); @@ -88,8 +84,7 @@ describe('Filtered Search Visual Tokens', () => { ${FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('assignee')} `); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); const items = document.querySelectorAll('.tokens-container .js-visual-token'); expect(lastVisualToken.isEqualNode(items[items.length - 1])).toEqual(true); @@ -105,8 +100,7 @@ describe('Filtered Search Visual Tokens', () => { ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '@root')} `); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token')); expect(isLastVisualTokenValid).toEqual(true); @@ -119,8 +113,7 @@ describe('Filtered Search Visual Tokens', () => { ${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '@root')} `); - const { lastVisualToken, isLastVisualTokenValid } - = subject.getLastVisualTokenBeforeInput(); + const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput(); expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token')); expect(isLastVisualTokenValid).toEqual(false); @@ -142,8 +135,12 @@ describe('Filtered Search Visual Tokens', () => { const singleQueryParams = '{"foo":"true"}'; const multipleQueryParams = '{"foo":"true","bar":"true"}'; - expect(subject.getEndpointWithQueryParams(endpoint, singleQueryParams)).toBe(`${endpoint}?foo=true`); - expect(subject.getEndpointWithQueryParams(endpoint, multipleQueryParams)).toBe(`${endpoint}?foo=true&bar=true`); + expect(subject.getEndpointWithQueryParams(endpoint, singleQueryParams)).toBe( + `${endpoint}?foo=true`, + ); + expect(subject.getEndpointWithQueryParams(endpoint, multipleQueryParams)).toBe( + `${endpoint}?foo=true&bar=true`, + ); }); }); @@ -275,7 +272,9 @@ describe('Filtered Search Visual Tokens', () => { describe('remove token', () => { it('contains remove-token button', () => { - expect(tokenElement.querySelector('.value-container .remove-token')).toEqual(jasmine.anything()); + expect(tokenElement.querySelector('.value-container .remove-token')).toEqual( + jasmine.anything(), + ); }); it('contains fa-close icon', () => { @@ -313,7 +312,9 @@ describe('Filtered Search Visual Tokens', () => { }); it('inserts visual token before input', () => { - tokensContainer.appendChild(FilteredSearchSpecHelper.createFilterVisualToken('assignee', '@root')); + tokensContainer.appendChild( + FilteredSearchSpecHelper.createFilterVisualToken('assignee', '@root'), + ); subject.addVisualTokenElement('label', 'Frontend'); const tokens = tokensContainer.querySelectorAll('.js-visual-token'); @@ -552,7 +553,7 @@ describe('Filtered Search Visual Tokens', () => { token = document.querySelector('.js-visual-token'); }); - it('tokenize\'s existing input', () => { + it("tokenize's existing input", () => { input.value = 'some text'; spyOn(subject, 'tokenizeInput').and.callThrough(); @@ -625,7 +626,7 @@ describe('Filtered Search Visual Tokens', () => { expect(subject.getLastVisualTokenBeforeInput).not.toHaveBeenCalled(); }); - it('tokenize\'s input', () => { + it("tokenize's input", () => { tokensContainer.innerHTML = ` ${FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('label')} ${FilteredSearchSpecHelper.createInputHTML()} @@ -684,7 +685,10 @@ describe('Filtered Search Visual Tokens', () => { describe('renderVisualTokenValue', () => { const keywordToken = FilteredSearchSpecHelper.createFilterVisualToken('search'); - const milestoneToken = FilteredSearchSpecHelper.createFilterVisualToken('milestone', 'upcoming'); + const milestoneToken = FilteredSearchSpecHelper.createFilterVisualToken( + 'milestone', + 'upcoming', + ); let updateLabelTokenColorSpy; let updateUserTokenAppearanceSpy; @@ -705,8 +709,9 @@ describe('Filtered Search Visual Tokens', () => { }); it('renders a author token value element', () => { - const { tokenNameElement, tokenValueContainer, tokenValueElement } = - findElements(authorToken); + const { tokenNameElement, tokenValueContainer, tokenValueElement } = findElements( + authorToken, + ); const tokenName = tokenNameElement.innerText; const tokenValue = 'new value'; @@ -721,8 +726,9 @@ describe('Filtered Search Visual Tokens', () => { }); it('renders a label token value element', () => { - const { tokenNameElement, tokenValueContainer, tokenValueElement } = - findElements(bugLabelToken); + const { tokenNameElement, tokenValueContainer, tokenValueElement } = findElements( + bugLabelToken, + ); const tokenName = tokenNameElement.innerText; const tokenValue = 'new value'; @@ -756,98 +762,103 @@ describe('Filtered Search Visual Tokens', () => { spyOn(UsersCache, 'retrieve').and.callFake(username => usersCacheSpy(username)); }); - it('ignores special value "none"', (done) => { - usersCacheSpy = (username) => { + it('ignores special value "none"', done => { + usersCacheSpy = username => { expect(username).toBe('none'); done.fail('Should not resolve "none"!'); }; const { tokenValueContainer, tokenValueElement } = findElements(authorToken); - subject.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, 'none') - .then(done) - .catch(done.fail); + subject + .updateUserTokenAppearance(tokenValueContainer, tokenValueElement, 'none') + .then(done) + .catch(done.fail); }); - it('ignores error if UsersCache throws', (done) => { + it('ignores error if UsersCache throws', done => { spyOn(window, 'Flash'); const dummyError = new Error('Earth rotated backwards'); const { tokenValueContainer, tokenValueElement } = findElements(authorToken); const tokenValue = tokenValueElement.innerText; - usersCacheSpy = (username) => { + usersCacheSpy = username => { expect(`@${username}`).toBe(tokenValue); return Promise.reject(dummyError); }; - subject.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) - .then(() => { - expect(window.Flash.calls.count()).toBe(0); - }) - .then(done) - .catch(done.fail); + subject + .updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) + .then(() => { + expect(window.Flash.calls.count()).toBe(0); + }) + .then(done) + .catch(done.fail); }); - it('does nothing if user cannot be found', (done) => { + it('does nothing if user cannot be found', done => { const { tokenValueContainer, tokenValueElement } = findElements(authorToken); const tokenValue = tokenValueElement.innerText; - usersCacheSpy = (username) => { + usersCacheSpy = username => { expect(`@${username}`).toBe(tokenValue); return Promise.resolve(undefined); }; - subject.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) - .then(() => { - expect(tokenValueElement.innerText).toBe(tokenValue); - }) - .then(done) - .catch(done.fail); + subject + .updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) + .then(() => { + expect(tokenValueElement.innerText).toBe(tokenValue); + }) + .then(done) + .catch(done.fail); }); - it('replaces author token with avatar and display name', (done) => { + it('replaces author token with avatar and display name', done => { const dummyUser = { name: 'Important Person', avatar_url: 'https://host.invalid/mypics/avatar.png', }; const { tokenValueContainer, tokenValueElement } = findElements(authorToken); const tokenValue = tokenValueElement.innerText; - usersCacheSpy = (username) => { + usersCacheSpy = username => { expect(`@${username}`).toBe(tokenValue); return Promise.resolve(dummyUser); }; - subject.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) - .then(() => { - expect(tokenValueContainer.dataset.originalValue).toBe(tokenValue); - expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); - const avatar = tokenValueElement.querySelector('img.avatar'); + subject + .updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) + .then(() => { + expect(tokenValueContainer.dataset.originalValue).toBe(tokenValue); + expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); + const avatar = tokenValueElement.querySelector('img.avatar'); - expect(avatar.src).toBe(dummyUser.avatar_url); - expect(avatar.alt).toBe(''); - }) - .then(done) - .catch(done.fail); + expect(avatar.src).toBe(dummyUser.avatar_url); + expect(avatar.alt).toBe(''); + }) + .then(done) + .catch(done.fail); }); - it('escapes user name when creating token', (done) => { + it('escapes user name when creating token', done => { const dummyUser = { name: '<script>', avatar_url: `${gl.TEST_HOST}/mypics/avatar.png`, }; const { tokenValueContainer, tokenValueElement } = findElements(authorToken); const tokenValue = tokenValueElement.innerText; - usersCacheSpy = (username) => { + usersCacheSpy = username => { expect(`@${username}`).toBe(tokenValue); return Promise.resolve(dummyUser); }; - subject.updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) - .then(() => { - expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); - tokenValueElement.querySelector('.avatar').remove(); + subject + .updateUserTokenAppearance(tokenValueContainer, tokenValueElement, tokenValue) + .then(() => { + expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); + tokenValueElement.querySelector('.avatar').remove(); - expect(tokenValueElement.innerHTML.trim()).toBe(_.escape(dummyUser.name)); - }) - .then(done) - .catch(done.fail); + expect(tokenValueElement.innerHTML.trim()).toBe(_.escape(dummyUser.name)); + }) + .then(done) + .catch(done.fail); }); }); @@ -867,7 +878,11 @@ describe('Filtered Search Visual Tokens', () => { }); it('should not set backgroundColor when it is a linear-gradient', () => { - const token = subject.setTokenStyle(bugLabelToken, 'linear-gradient(135deg, red, blue)', 'white'); + const token = subject.setTokenStyle( + bugLabelToken, + 'linear-gradient(135deg, red, blue)', + 'white', + ); expect(token.style.backgroundColor).toEqual(bugLabelToken.style.backgroundColor); }); @@ -933,8 +948,14 @@ describe('Filtered Search Visual Tokens', () => { labelData = getJSONFixture(jsonFixtureName); }); - const missingLabelToken = FilteredSearchSpecHelper.createFilterVisualToken('label', '~doesnotexist'); - const spaceLabelToken = FilteredSearchSpecHelper.createFilterVisualToken('label', '~"some space"'); + const missingLabelToken = FilteredSearchSpecHelper.createFilterVisualToken( + 'label', + '~doesnotexist', + ); + const spaceLabelToken = FilteredSearchSpecHelper.createFilterVisualToken( + 'label', + '~"some space"', + ); beforeEach(() => { tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(` @@ -946,11 +967,11 @@ describe('Filtered Search Visual Tokens', () => { const filteredSearchInput = document.querySelector('.filtered-search'); filteredSearchInput.dataset.baseEndpoint = dummyEndpoint; - AjaxCache.internalStorage = { }; + AjaxCache.internalStorage = {}; AjaxCache.internalStorage[`${dummyEndpoint}/labels.json`] = labelData; }); - const parseColor = (color) => { + const parseColor = color => { const dummyElement = document.createElement('div'); dummyElement.style.color = color; return dummyElement.style.color; @@ -962,16 +983,16 @@ describe('Filtered Search Visual Tokens', () => { expect(tokenValueContainer.style.color).toBe(parseColor(label.text_color)); }; - const findLabel = tokenValue => labelData.find( - label => tokenValue === `~${DropdownUtils.getEscapedText(label.title)}`, - ); + const findLabel = tokenValue => + labelData.find(label => tokenValue === `~${DropdownUtils.getEscapedText(label.title)}`); - it('updates the color of a label token', (done) => { + it('updates the color of a label token', done => { const { tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); const tokenValue = tokenValueElement.innerText; const matchingLabel = findLabel(tokenValue); - subject.updateLabelTokenColor(tokenValueContainer, tokenValue) + subject + .updateLabelTokenColor(tokenValueContainer, tokenValue) .then(() => { expectValueContainerStyle(tokenValueContainer, matchingLabel); }) @@ -979,12 +1000,13 @@ describe('Filtered Search Visual Tokens', () => { .catch(done.fail); }); - it('updates the color of a label token with spaces', (done) => { + it('updates the color of a label token with spaces', done => { const { tokenValueContainer, tokenValueElement } = findElements(spaceLabelToken); const tokenValue = tokenValueElement.innerText; const matchingLabel = findLabel(tokenValue); - subject.updateLabelTokenColor(tokenValueContainer, tokenValue) + subject + .updateLabelTokenColor(tokenValueContainer, tokenValue) .then(() => { expectValueContainerStyle(tokenValueContainer, matchingLabel); }) @@ -992,14 +1014,15 @@ describe('Filtered Search Visual Tokens', () => { .catch(done.fail); }); - it('does not change color of a missing label', (done) => { + it('does not change color of a missing label', done => { const { tokenValueContainer, tokenValueElement } = findElements(missingLabelToken); const tokenValue = tokenValueElement.innerText; const matchingLabel = findLabel(tokenValue); expect(matchingLabel).toBe(undefined); - subject.updateLabelTokenColor(tokenValueContainer, tokenValue) + subject + .updateLabelTokenColor(tokenValueContainer, tokenValue) .then(() => { expect(tokenValueContainer.getAttribute('style')).toBe(null); }) diff --git a/spec/javascripts/filtered_search/recent_searches_root_spec.js b/spec/javascripts/filtered_search/recent_searches_root_spec.js index d063fcf4f2d..70dd4e9570d 100644 --- a/spec/javascripts/filtered_search/recent_searches_root_spec.js +++ b/spec/javascripts/filtered_search/recent_searches_root_spec.js @@ -14,7 +14,7 @@ describe('RecentSearchesRoot', () => { }, }; - VueSpy = spyOnDependency(RecentSearchesRoot, 'Vue').and.callFake((options) => { + VueSpy = spyOnDependency(RecentSearchesRoot, 'Vue').and.callFake(options => { ({ data, template } = options); }); diff --git a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js b/spec/javascripts/filtered_search/services/recent_searches_service_spec.js index e8cb69aba7f..188f83eca16 100644 --- a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js +++ b/spec/javascripts/filtered_search/services/recent_searches_service_spec.js @@ -15,48 +15,49 @@ describe('RecentSearchesService', () => { spyOn(RecentSearchesService, 'isAvailable').and.returnValue(true); }); - it('should default to empty array', (done) => { + it('should default to empty array', done => { const fetchItemsPromise = service.fetch(); fetchItemsPromise - .then((items) => { + .then(items => { expect(items).toEqual([]); }) .then(done) .catch(done.fail); }); - it('should reject when unable to parse', (done) => { + it('should reject when unable to parse', done => { window.localStorage.setItem(service.localStorageKey, 'fail'); const fetchItemsPromise = service.fetch(); fetchItemsPromise .then(done.fail) - .catch((error) => { + .catch(error => { expect(error).toEqual(jasmine.any(SyntaxError)); }) .then(done) .catch(done.fail); }); - it('should reject when service is unavailable', (done) => { + it('should reject when service is unavailable', done => { RecentSearchesService.isAvailable.and.returnValue(false); - service.fetch() + service + .fetch() .then(done.fail) - .catch((error) => { + .catch(error => { expect(error).toEqual(jasmine.any(Error)); }) .then(done) .catch(done.fail); }); - it('should return items from localStorage', (done) => { + it('should return items from localStorage', done => { window.localStorage.setItem(service.localStorageKey, '["foo", "bar"]'); const fetchItemsPromise = service.fetch(); fetchItemsPromise - .then((items) => { + .then(items => { expect(items).toEqual(['foo', 'bar']); }) .then(done) @@ -70,10 +71,11 @@ describe('RecentSearchesService', () => { spyOn(window.localStorage, 'getItem'); }); - it('should not call .getItem', (done) => { - RecentSearchesService.prototype.fetch() + it('should not call .getItem', done => { + RecentSearchesService.prototype + .fetch() .then(done.fail) - .catch((err) => { + .catch(err => { expect(err).toEqual(new RecentSearchesServiceError()); expect(window.localStorage.getItem).not.toHaveBeenCalled(); }) diff --git a/spec/javascripts/filtered_search/stores/recent_searches_store_spec.js b/spec/javascripts/filtered_search/stores/recent_searches_store_spec.js index 1eebc6f2367..56bb82ae941 100644 --- a/spec/javascripts/filtered_search/stores/recent_searches_store_spec.js +++ b/spec/javascripts/filtered_search/stores/recent_searches_store_spec.js @@ -38,14 +38,8 @@ describe('RecentSearchesStore', () => { describe('setRecentSearches', () => { it('should override list', () => { - store.setRecentSearches([ - 'foo', - 'bar', - ]); - store.setRecentSearches([ - 'baz', - 'qux', - ]); + store.setRecentSearches(['foo', 'bar']); + store.setRecentSearches(['baz', 'qux']); expect(store.state.recentSearches).toEqual(['baz', 'qux']); }); |