diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-07 15:09:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-07 15:09:46 +0300 |
commit | 896b68514b43b9646d763e67f63fbe8f9ef2f723 (patch) | |
tree | b0b21f37cbbc809782532e6d6180677c7c4c9e30 /spec/javascripts | |
parent | d8803c7e40bd35d883ef007ddc56907bd837a748 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/javascripts')
11 files changed, 0 insertions, 1903 deletions
diff --git a/spec/javascripts/filtered_search/dropdown_utils_spec.js b/spec/javascripts/filtered_search/dropdown_utils_spec.js deleted file mode 100644 index 6eda4f391a4..00000000000 --- a/spec/javascripts/filtered_search/dropdown_utils_spec.js +++ /dev/null @@ -1,374 +0,0 @@ -import DropdownUtils from '~/filtered_search/dropdown_utils'; -import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager'; -import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; -import FilteredSearchSpecHelper from '../helpers/filtered_search_spec_helper'; - -describe('Dropdown Utils', () => { - const issueListFixture = 'issues/issue_list.html'; - preloadFixtures(issueListFixture); - - describe('getEscapedText', () => { - it('should return same word when it has no space', () => { - const escaped = DropdownUtils.getEscapedText('textWithoutSpace'); - - expect(escaped).toBe('textWithoutSpace'); - }); - - it('should escape with double quotes', () => { - let escaped = DropdownUtils.getEscapedText('text with space'); - - expect(escaped).toBe('"text with space"'); - - escaped = DropdownUtils.getEscapedText("won't fix"); - - expect(escaped).toBe('"won\'t fix"'); - }); - - it('should escape with single quotes', () => { - const escaped = DropdownUtils.getEscapedText('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'"); - }); - }); - - describe('filterWithSymbol', () => { - let input; - const item = { - title: '@root', - }; - - beforeEach(() => { - setFixtures(` - <input type="text" id="test" /> - `); - - input = document.getElementById('test'); - }); - - it('should filter without symbol', () => { - input.value = 'roo'; - - const updatedItem = DropdownUtils.filterWithSymbol('@', input, item); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with symbol', () => { - input.value = '@roo'; - - const updatedItem = DropdownUtils.filterWithSymbol('@', input, item); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - describe('filters multiple word title', () => { - const multipleWordItem = { - title: 'Community Contributions', - }; - - it('should filter with double quote', () => { - input.value = '"'; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with double quote and symbol', () => { - input.value = '~"'; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with double quote and multiple words', () => { - input.value = '"community con'; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with double quote, symbol and multiple words', () => { - input.value = '~"community con'; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with single quote', () => { - input.value = "'"; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with single quote and symbol', () => { - input.value = "~'"; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with single quote and multiple words', () => { - input.value = "'community con"; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should filter with single quote, symbol and multiple words', () => { - input.value = "~'community con"; - - const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - }); - }); - - describe('filterHint', () => { - let input; - let allowedKeys; - - beforeEach(() => { - setFixtures(` - <ul class="tokens-container"> - <li class="input-token"> - <input class="filtered-search" type="text" id="test" /> - </li> - </ul> - `); - - input = document.getElementById('test'); - allowedKeys = IssuableFilteredSearchTokenKeys.getKeys(); - }); - - function config() { - return { - input, - allowedKeys, - }; - } - - it('should filter', () => { - input.value = 'l'; - let updatedItem = DropdownUtils.filterHint(config(), { - hint: 'label', - }); - - expect(updatedItem.droplab_hidden).toBe(false); - - input.value = 'o'; - updatedItem = DropdownUtils.filterHint(config(), { - hint: 'label', - }); - - expect(updatedItem.droplab_hidden).toBe(true); - }); - - it('should return droplab_hidden false when item has no hint', () => { - const updatedItem = DropdownUtils.filterHint(config(), {}, ''); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should allow multiple if item.type is array', () => { - input.value = 'label:~first la'; - const updatedItem = DropdownUtils.filterHint(config(), { - hint: 'label', - type: 'array', - }); - - expect(updatedItem.droplab_hidden).toBe(false); - }); - - it('should prevent multiple if item.type is not array', () => { - input.value = 'milestone:~first mile'; - let updatedItem = DropdownUtils.filterHint(config(), { - hint: 'milestone', - }); - - expect(updatedItem.droplab_hidden).toBe(true); - - updatedItem = DropdownUtils.filterHint(config(), { - hint: 'milestone', - type: 'string', - }); - - expect(updatedItem.droplab_hidden).toBe(true); - }); - }); - - describe('setDataValueIfSelected', () => { - beforeEach(() => { - spyOn(FilteredSearchDropdownManager, 'addWordToInput').and.callFake(() => {}); - }); - - it('calls addWordToInput when dataValue exists', () => { - const selected = { - getAttribute: () => 'value', - hasAttribute: () => false, - }; - - DropdownUtils.setDataValueIfSelected(null, '=', selected); - - expect(FilteredSearchDropdownManager.addWordToInput.calls.count()).toEqual(1); - }); - - it('returns true when dataValue exists', () => { - const selected = { - getAttribute: () => 'value', - hasAttribute: () => false, - }; - - const result = DropdownUtils.setDataValueIfSelected(null, '=', selected); - const result2 = DropdownUtils.setDataValueIfSelected(null, '!=', selected); - - expect(result).toBe(true); - expect(result2).toBe(true); - }); - - it('returns false when dataValue does not exist', () => { - const selected = { - getAttribute: () => null, - }; - - const result = DropdownUtils.setDataValueIfSelected(null, '=', selected); - const result2 = DropdownUtils.setDataValueIfSelected(null, '!=', selected); - - expect(result).toBe(false); - expect(result2).toBe(false); - }); - }); - - describe('getInputSelectionPosition', () => { - describe('word with trailing spaces', () => { - const value = 'label:none '; - - it('should return selectionStart when cursor is at the trailing space', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 11, - value, - }); - - expect(left).toBe(11); - expect(right).toBe(11); - }); - - it('should return input when cursor is at the start of input', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 0, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(10); - }); - - it('should return input when cursor is at the middle of input', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 7, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(10); - }); - - it('should return input when cursor is at the end of input', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 10, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(10); - }); - }); - - describe('multiple words', () => { - const value = 'label:~"Community Contribution"'; - - it('should return input when cursor is after the first word', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 17, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(31); - }); - - it('should return input when cursor is before the second word', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 18, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(31); - }); - }); - - describe('incomplete multiple words', () => { - const value = 'label:~"Community Contribution'; - - it('should return entire input when cursor is at the start of input', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 0, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(30); - }); - - it('should return entire input when cursor is at the end of input', () => { - const { left, right } = DropdownUtils.getInputSelectionPosition({ - selectionStart: 30, - value, - }); - - expect(left).toBe(0); - expect(right).toBe(30); - }); - }); - }); - - describe('getSearchQuery', () => { - let authorToken; - - beforeEach(() => { - loadFixtures(issueListFixture); - - authorToken = FilteredSearchSpecHelper.createFilterVisualToken('author', '=', '@user'); - const searchTermToken = FilteredSearchSpecHelper.createSearchVisualToken('search term'); - - const tokensContainer = document.querySelector('.tokens-container'); - tokensContainer.appendChild(searchTermToken); - tokensContainer.appendChild(authorToken); - }); - - it('uses original value if present', () => { - const originalValue = 'original dance'; - const valueContainer = authorToken.querySelector('.value-container'); - valueContainer.dataset.originalValue = originalValue; - - const searchQuery = DropdownUtils.getSearchQuery(); - - expect(searchQuery).toBe(' search term author:=original dance'); - }); - }); -}); diff --git a/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js b/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js deleted file mode 100644 index dec03e5ab93..00000000000 --- a/spec/javascripts/filtered_search/filtered_search_tokenizer_spec.js +++ /dev/null @@ -1,152 +0,0 @@ -import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; -import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer'; - -describe('Filtered Search Tokenizer', () => { - const allowedKeys = IssuableFilteredSearchTokenKeys.getKeys(); - - describe('processTokens', () => { - it('returns for input containing only search value', () => { - const results = FilteredSearchTokenizer.processTokens('searchTerm', allowedKeys); - - expect(results.searchToken).toBe('searchTerm'); - expect(results.tokens.length).toBe(0); - expect(results.lastToken).toBe(results.searchToken); - }); - - it('returns for input containing only tokens', () => { - 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); - expect(results.tokens[3]).toBe(results.lastToken); - - expect(results.tokens[0].key).toBe('author'); - expect(results.tokens[0].value).toBe('root'); - expect(results.tokens[0].symbol).toBe('@'); - - expect(results.tokens[1].key).toBe('label'); - expect(results.tokens[1].value).toBe('"Very Important"'); - expect(results.tokens[1].symbol).toBe('~'); - - expect(results.tokens[2].key).toBe('milestone'); - expect(results.tokens[2].value).toBe('v1.0'); - expect(results.tokens[2].symbol).toBe('%'); - - expect(results.tokens[3].key).toBe('assignee'); - expect(results.tokens[3].value).toBe('none'); - expect(results.tokens[3].symbol).toBe(''); - }); - - it('returns for input starting with search value and ending with tokens', () => { - const results = FilteredSearchTokenizer.processTokens( - 'searchTerm anotherSearchTerm milestone:none', - allowedKeys, - ); - - expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); - expect(results.tokens.length).toBe(1); - expect(results.tokens[0]).toBe(results.lastToken); - expect(results.tokens[0].key).toBe('milestone'); - expect(results.tokens[0].value).toBe('none'); - expect(results.tokens[0].symbol).toBe(''); - }); - - it('returns for input starting with tokens and ending with search value', () => { - const results = FilteredSearchTokenizer.processTokens( - 'assignee:@user searchTerm', - allowedKeys, - ); - - expect(results.searchToken).toBe('searchTerm'); - expect(results.tokens.length).toBe(1); - expect(results.tokens[0].key).toBe('assignee'); - expect(results.tokens[0].value).toBe('user'); - expect(results.tokens[0].symbol).toBe('@'); - expect(results.lastToken).toBe(results.searchToken); - }); - - 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, - ); - - expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); - expect(results.tokens.length).toBe(3); - expect(results.tokens[2]).toBe(results.lastToken); - - expect(results.tokens[0].key).toBe('author'); - expect(results.tokens[0].value).toBe('root'); - expect(results.tokens[0].symbol).toBe('@'); - - expect(results.tokens[1].key).toBe('label'); - expect(results.tokens[1].value).toBe('"Won\'t fix"'); - expect(results.tokens[1].symbol).toBe('~'); - - expect(results.tokens[2].key).toBe('milestone'); - expect(results.tokens[2].value).toBe('none'); - expect(results.tokens[2].symbol).toBe(''); - }); - - it('returns for input containing search value in between tokens', () => { - 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); - expect(results.tokens[2]).toBe(results.lastToken); - - expect(results.tokens[0].key).toBe('author'); - expect(results.tokens[0].value).toBe('root'); - expect(results.tokens[0].symbol).toBe('@'); - - expect(results.tokens[1].key).toBe('assignee'); - expect(results.tokens[1].value).toBe('none'); - expect(results.tokens[1].symbol).toBe(''); - - expect(results.tokens[2].key).toBe('label'); - expect(results.tokens[2].value).toBe('Doing'); - expect(results.tokens[2].symbol).toBe('~'); - }); - - it('returns search value for invalid tokens', () => { - const results = FilteredSearchTokenizer.processTokens('fake:token', allowedKeys); - - expect(results.lastToken).toBe('fake:token'); - expect(results.searchToken).toBe('fake:token'); - expect(results.tokens.length).toEqual(0); - }); - - it('returns search value and token for mix of valid and invalid tokens', () => { - const results = FilteredSearchTokenizer.processTokens('label:real fake:token', allowedKeys); - - expect(results.tokens.length).toEqual(1); - expect(results.tokens[0].key).toBe('label'); - expect(results.tokens[0].value).toBe('real'); - expect(results.tokens[0].symbol).toBe(''); - expect(results.lastToken).toBe('fake:token'); - expect(results.searchToken).toBe('fake:token'); - }); - - it('returns search value for invalid symbols', () => { - const results = FilteredSearchTokenizer.processTokens('std::includes', allowedKeys); - - expect(results.lastToken).toBe('std::includes'); - expect(results.searchToken).toBe('std::includes'); - }); - - it('removes duplicated values', () => { - const results = FilteredSearchTokenizer.processTokens('label:~foo label:~foo', allowedKeys); - - expect(results.tokens.length).toBe(1); - expect(results.tokens[0].key).toBe('label'); - expect(results.tokens[0].value).toBe('foo'); - expect(results.tokens[0].symbol).toBe('~'); - }); - }); -}); diff --git a/spec/javascripts/filtered_search/issues_filtered_search_token_keys_spec.js b/spec/javascripts/filtered_search/issues_filtered_search_token_keys_spec.js deleted file mode 100644 index c7be900ba2c..00000000000 --- a/spec/javascripts/filtered_search/issues_filtered_search_token_keys_spec.js +++ /dev/null @@ -1,148 +0,0 @@ -import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys'; - -describe('Issues Filtered Search Token Keys', () => { - describe('get', () => { - let tokenKeys; - - beforeEach(() => { - tokenKeys = IssuableFilteredSearchTokenKeys.get(); - }); - - it('should return tokenKeys', () => { - expect(tokenKeys).not.toBeNull(); - }); - - it('should return tokenKeys as an array', () => { - expect(tokenKeys instanceof Array).toBe(true); - }); - - it('should always return the same array', () => { - const tokenKeys2 = IssuableFilteredSearchTokenKeys.get(); - - expect(tokenKeys).toEqual(tokenKeys2); - }); - - it('should return assignee as a string', () => { - const assignee = tokenKeys.find(tokenKey => tokenKey.key === 'assignee'); - - expect(assignee.type).toEqual('string'); - }); - }); - - describe('getKeys', () => { - it('should return keys', () => { - const getKeys = IssuableFilteredSearchTokenKeys.getKeys(); - const keys = IssuableFilteredSearchTokenKeys.get().map(i => i.key); - - keys.forEach((key, i) => { - expect(key).toEqual(getKeys[i]); - }); - }); - }); - - describe('getConditions', () => { - let conditions; - - beforeEach(() => { - conditions = IssuableFilteredSearchTokenKeys.getConditions(); - }); - - it('should return conditions', () => { - expect(conditions).not.toBeNull(); - }); - - it('should return conditions as an array', () => { - expect(conditions instanceof Array).toBe(true); - }); - }); - - describe('searchByKey', () => { - it('should return null when key not found', () => { - const tokenKey = IssuableFilteredSearchTokenKeys.searchByKey('notakey'); - - expect(tokenKey).toBeNull(); - }); - - it('should return tokenKey when found by key', () => { - const tokenKeys = IssuableFilteredSearchTokenKeys.get(); - const result = IssuableFilteredSearchTokenKeys.searchByKey(tokenKeys[0].key); - - expect(result).toEqual(tokenKeys[0]); - }); - }); - - describe('searchBySymbol', () => { - it('should return null when symbol not found', () => { - const tokenKey = IssuableFilteredSearchTokenKeys.searchBySymbol('notasymbol'); - - expect(tokenKey).toBeNull(); - }); - - it('should return tokenKey when found by symbol', () => { - const tokenKeys = IssuableFilteredSearchTokenKeys.get(); - const result = IssuableFilteredSearchTokenKeys.searchBySymbol(tokenKeys[0].symbol); - - expect(result).toEqual(tokenKeys[0]); - }); - }); - - describe('searchByKeyParam', () => { - it('should return null when key param not found', () => { - const tokenKey = IssuableFilteredSearchTokenKeys.searchByKeyParam('notakeyparam'); - - expect(tokenKey).toBeNull(); - }); - - it('should return tokenKey when found by key param', () => { - const tokenKeys = IssuableFilteredSearchTokenKeys.get(); - const result = IssuableFilteredSearchTokenKeys.searchByKeyParam( - `${tokenKeys[0].key}_${tokenKeys[0].param}`, - ); - - expect(result).toEqual(tokenKeys[0]); - }); - - it('should return alternative tokenKey when found by key param', () => { - const tokenKeys = IssuableFilteredSearchTokenKeys.getAlternatives(); - const result = IssuableFilteredSearchTokenKeys.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 = IssuableFilteredSearchTokenKeys.searchByConditionUrl(null); - - expect(condition).toBeNull(); - }); - - it('should return condition when found by url', () => { - const conditions = IssuableFilteredSearchTokenKeys.getConditions(); - const result = IssuableFilteredSearchTokenKeys.searchByConditionUrl(conditions[0].url); - - expect(result).toBe(conditions[0]); - }); - }); - - describe('searchByConditionKeyValue', () => { - it('should return null when condition tokenKey and value not found', () => { - const condition = IssuableFilteredSearchTokenKeys.searchByConditionKeyValue(null, null); - - expect(condition).toBeNull(); - }); - - it('should return condition when found by tokenKey and value', () => { - const conditions = IssuableFilteredSearchTokenKeys.getConditions(); - const result = IssuableFilteredSearchTokenKeys.searchByConditionKeyValue( - conditions[0].tokenKey, - conditions[0].operator, - conditions[0].value, - ); - - expect(result).toEqual(conditions[0]); - }); - }); -}); diff --git a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js b/spec/javascripts/filtered_search/services/recent_searches_service_spec.js deleted file mode 100644 index 188f83eca16..00000000000 --- a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js +++ /dev/null @@ -1,158 +0,0 @@ -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'; - -describe('RecentSearchesService', () => { - let service; - - beforeEach(() => { - service = new RecentSearchesService(); - window.localStorage.removeItem(service.localStorageKey); - }); - - describe('fetch', () => { - beforeEach(() => { - spyOn(RecentSearchesService, 'isAvailable').and.returnValue(true); - }); - - it('should default to empty array', done => { - const fetchItemsPromise = service.fetch(); - - fetchItemsPromise - .then(items => { - expect(items).toEqual([]); - }) - .then(done) - .catch(done.fail); - }); - - it('should reject when unable to parse', done => { - window.localStorage.setItem(service.localStorageKey, 'fail'); - const fetchItemsPromise = service.fetch(); - - fetchItemsPromise - .then(done.fail) - .catch(error => { - expect(error).toEqual(jasmine.any(SyntaxError)); - }) - .then(done) - .catch(done.fail); - }); - - it('should reject when service is unavailable', done => { - RecentSearchesService.isAvailable.and.returnValue(false); - - service - .fetch() - .then(done.fail) - .catch(error => { - expect(error).toEqual(jasmine.any(Error)); - }) - .then(done) - .catch(done.fail); - }); - - it('should return items from localStorage', done => { - window.localStorage.setItem(service.localStorageKey, '["foo", "bar"]'); - const fetchItemsPromise = service.fetch(); - - fetchItemsPromise - .then(items => { - expect(items).toEqual(['foo', 'bar']); - }) - .then(done) - .catch(done.fail); - }); - - describe('if .isAvailable returns `false`', () => { - beforeEach(() => { - RecentSearchesService.isAvailable.and.returnValue(false); - - spyOn(window.localStorage, 'getItem'); - }); - - it('should not call .getItem', done => { - RecentSearchesService.prototype - .fetch() - .then(done.fail) - .catch(err => { - expect(err).toEqual(new RecentSearchesServiceError()); - expect(window.localStorage.getItem).not.toHaveBeenCalled(); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - - describe('setRecentSearches', () => { - beforeEach(() => { - spyOn(RecentSearchesService, 'isAvailable').and.returnValue(true); - }); - - it('should save things in localStorage', () => { - const items = ['foo', 'bar']; - service.save(items); - const newLocalStorageValue = window.localStorage.getItem(service.localStorageKey); - - expect(JSON.parse(newLocalStorageValue)).toEqual(items); - }); - }); - - describe('save', () => { - beforeEach(() => { - spyOn(window.localStorage, 'setItem'); - spyOn(RecentSearchesService, 'isAvailable'); - }); - - describe('if .isAvailable returns `true`', () => { - const searchesString = 'searchesString'; - const localStorageKey = 'localStorageKey'; - const recentSearchesService = { - localStorageKey, - }; - - beforeEach(() => { - RecentSearchesService.isAvailable.and.returnValue(true); - - spyOn(JSON, 'stringify').and.returnValue(searchesString); - }); - - it('should call .setItem', () => { - RecentSearchesService.prototype.save.call(recentSearchesService); - - expect(window.localStorage.setItem).toHaveBeenCalledWith(localStorageKey, searchesString); - }); - }); - - describe('if .isAvailable returns `false`', () => { - beforeEach(() => { - RecentSearchesService.isAvailable.and.returnValue(false); - }); - - it('should not call .setItem', () => { - RecentSearchesService.prototype.save(); - - expect(window.localStorage.setItem).not.toHaveBeenCalled(); - }); - }); - }); - - describe('isAvailable', () => { - let isAvailable; - - beforeEach(() => { - spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.callThrough(); - - isAvailable = RecentSearchesService.isAvailable(); - }); - - it('should call .isLocalStorageAccessSafe', () => { - expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled(); - }); - - it('should return a boolean', () => { - expect(typeof isAvailable).toBe('boolean'); - }); - }); -}); diff --git a/spec/javascripts/filtered_search/visual_token_value_spec.js b/spec/javascripts/filtered_search/visual_token_value_spec.js deleted file mode 100644 index 51a9b01231f..00000000000 --- a/spec/javascripts/filtered_search/visual_token_value_spec.js +++ /dev/null @@ -1,389 +0,0 @@ -import { escape } from 'lodash'; -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'; - -describe('Filtered Search Visual Tokens', () => { - const findElements = tokenElement => { - const tokenNameElement = tokenElement.querySelector('.name'); - const tokenValueContainer = tokenElement.querySelector('.value-container'); - const tokenValueElement = tokenValueContainer.querySelector('.value'); - const tokenOperatorElement = tokenElement.querySelector('.operator'); - const tokenType = tokenNameElement.innerText.toLowerCase(); - const tokenValue = tokenValueElement.innerText; - const tokenOperator = tokenOperatorElement.innerText; - const subject = new VisualTokenValue(tokenValue, tokenType, tokenOperator); - return { subject, tokenValueContainer, tokenValueElement }; - }; - - let tokensContainer; - let authorToken; - let bugLabelToken; - - beforeEach(() => { - setFixtures(` - <ul class="tokens-container"> - ${FilteredSearchSpecHelper.createInputHTML()} - </ul> - `); - tokensContainer = document.querySelector('.tokens-container'); - - authorToken = FilteredSearchSpecHelper.createFilterVisualToken('author', '=', '@user'); - bugLabelToken = FilteredSearchSpecHelper.createFilterVisualToken('label', '=', '~bug'); - }); - - describe('updateUserTokenAppearance', () => { - let usersCacheSpy; - - beforeEach(() => { - spyOn(UsersCache, 'retrieve').and.callFake(username => usersCacheSpy(username)); - }); - - it('ignores error if UsersCache throws', done => { - spyOn(window, 'Flash'); - const dummyError = new Error('Earth rotated backwards'); - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - const tokenValue = tokenValueElement.innerText; - 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); - }); - - it('does nothing if user cannot be found', done => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - const tokenValue = tokenValueElement.innerText; - 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); - }); - - it('replaces author token with avatar and display name', done => { - const dummyUser = { - name: 'Important Person', - avatar_url: 'https://host.invalid/mypics/avatar.png', - }; - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - const tokenValue = tokenValueElement.innerText; - 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'); - - expect(avatar.src).toBe(dummyUser.avatar_url); - expect(avatar.alt).toBe(''); - }) - .then(done) - .catch(done.fail); - }); - - it('escapes user name when creating token', done => { - const dummyUser = { - name: '<script>', - avatar_url: `${gl.TEST_HOST}/mypics/avatar.png`, - }; - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - const tokenValue = tokenValueElement.innerText; - 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(); - - expect(tokenValueElement.innerHTML.trim()).toBe(escape(dummyUser.name)); - }) - .then(done) - .catch(done.fail); - }); - }); - - describe('updateLabelTokenColor', () => { - const jsonFixtureName = 'labels/project_labels.json'; - const dummyEndpoint = '/dummy/endpoint'; - - preloadFixtures(jsonFixtureName); - - let labelData; - - beforeAll(() => { - labelData = getJSONFixture(jsonFixtureName); - }); - - const missingLabelToken = FilteredSearchSpecHelper.createFilterVisualToken( - 'label', - '=', - '~doesnotexist', - ); - const spaceLabelToken = FilteredSearchSpecHelper.createFilterVisualToken( - 'label', - '=', - '~"some space"', - ); - - beforeEach(() => { - tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(` - ${bugLabelToken.outerHTML} - ${missingLabelToken.outerHTML} - ${spaceLabelToken.outerHTML} - `); - - const filteredSearchInput = document.querySelector('.filtered-search'); - filteredSearchInput.dataset.runnerTagsEndpoint = `${dummyEndpoint}/admin/runners/tag_list`; - filteredSearchInput.dataset.labelsEndpoint = `${dummyEndpoint}/-/labels`; - filteredSearchInput.dataset.milestonesEndpoint = `${dummyEndpoint}/-/milestones`; - - AjaxCache.internalStorage = {}; - AjaxCache.internalStorage[`${filteredSearchInput.dataset.labelsEndpoint}.json`] = labelData; - }); - - const parseColor = color => { - const dummyElement = document.createElement('div'); - dummyElement.style.color = color; - return dummyElement.style.color; - }; - - const expectValueContainerStyle = (tokenValueContainer, label) => { - expect(tokenValueContainer.getAttribute('style')).not.toBe(null); - expect(tokenValueContainer.style.backgroundColor).toBe(parseColor(label.color)); - expect(tokenValueContainer.style.color).toBe(parseColor(label.text_color)); - }; - - const findLabel = tokenValue => - labelData.find(label => tokenValue === `~${DropdownUtils.getEscapedText(label.title)}`); - - it('updates the color of a label token', done => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); - const tokenValue = tokenValueElement.innerText; - const matchingLabel = findLabel(tokenValue); - - subject - .updateLabelTokenColor(tokenValueContainer, tokenValue) - .then(() => { - expectValueContainerStyle(tokenValueContainer, matchingLabel); - }) - .then(done) - .catch(done.fail); - }); - - it('updates the color of a label token with spaces', done => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(spaceLabelToken); - const tokenValue = tokenValueElement.innerText; - const matchingLabel = findLabel(tokenValue); - - subject - .updateLabelTokenColor(tokenValueContainer, tokenValue) - .then(() => { - expectValueContainerStyle(tokenValueContainer, matchingLabel); - }) - .then(done) - .catch(done.fail); - }); - - it('does not change color of a missing label', done => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(missingLabelToken); - const tokenValue = tokenValueElement.innerText; - const matchingLabel = findLabel(tokenValue); - - expect(matchingLabel).toBe(undefined); - - subject - .updateLabelTokenColor(tokenValueContainer, tokenValue) - .then(() => { - expect(tokenValueContainer.getAttribute('style')).toBe(null); - }) - .then(done) - .catch(done.fail); - }); - }); - - describe('setTokenStyle', () => { - let originalTextColor; - - beforeEach(() => { - originalTextColor = bugLabelToken.style.color; - }); - - it('should set backgroundColor', () => { - const originalBackgroundColor = bugLabelToken.style.backgroundColor; - const token = VisualTokenValue.setTokenStyle(bugLabelToken, 'blue', 'white'); - - expect(token.style.backgroundColor).toEqual('blue'); - expect(token.style.backgroundColor).not.toEqual(originalBackgroundColor); - }); - - it('should set textColor', () => { - const token = VisualTokenValue.setTokenStyle(bugLabelToken, 'white', 'black'); - - expect(token.style.color).toEqual('black'); - expect(token.style.color).not.toEqual(originalTextColor); - }); - - it('should add inverted class when textColor is #FFFFFF', () => { - const token = VisualTokenValue.setTokenStyle(bugLabelToken, 'black', '#FFFFFF'); - - expect(token.style.color).toEqual('rgb(255, 255, 255)'); - expect(token.style.color).not.toEqual(originalTextColor); - expect(token.querySelector('.remove-token').classList.contains('inverted')).toEqual(true); - }); - }); - - describe('render', () => { - const setupSpies = subject => { - spyOn(subject, 'updateLabelTokenColor'); // eslint-disable-line jasmine/no-unsafe-spy - const updateLabelTokenColorSpy = subject.updateLabelTokenColor; - - spyOn(subject, 'updateUserTokenAppearance'); // eslint-disable-line jasmine/no-unsafe-spy - const updateUserTokenAppearanceSpy = subject.updateUserTokenAppearance; - - return { updateLabelTokenColorSpy, updateUserTokenAppearanceSpy }; - }; - - const keywordToken = FilteredSearchSpecHelper.createFilterVisualToken('search'); - const milestoneToken = FilteredSearchSpecHelper.createFilterVisualToken( - 'milestone', - 'upcoming', - ); - - beforeEach(() => { - tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(` - ${authorToken.outerHTML} - ${bugLabelToken.outerHTML} - ${keywordToken.outerHTML} - ${milestoneToken.outerHTML} - `); - }); - - it('renders a author token value element', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - - const { updateLabelTokenColorSpy, updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(1); - const expectedArgs = [tokenValueContainer, tokenValueElement]; - - expect(updateUserTokenAppearanceSpy.calls.argsFor(0)).toEqual(expectedArgs); - expect(updateLabelTokenColorSpy.calls.count()).toBe(0); - }); - - it('renders a label token value element', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); - - const { updateLabelTokenColorSpy, updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateLabelTokenColorSpy.calls.count()).toBe(1); - const expectedArgs = [tokenValueContainer]; - - expect(updateLabelTokenColorSpy.calls.argsFor(0)).toEqual(expectedArgs); - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); - }); - - it('renders a milestone token value element', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(milestoneToken); - - const { updateLabelTokenColorSpy, updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateLabelTokenColorSpy.calls.count()).toBe(0); - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); - }); - - it('does not update user token appearance for `none` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - - subject.tokenValue = 'none'; - - const { updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); - }); - - it('does not update user token appearance for `None` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - - subject.tokenValue = 'None'; - - const { updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); - }); - - it('does not update user token appearance for `any` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(authorToken); - - subject.tokenValue = 'any'; - - const { updateUserTokenAppearanceSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); - }); - - it('does not update label token color for `None` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); - - subject.tokenValue = 'None'; - - const { updateLabelTokenColorSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateLabelTokenColorSpy.calls.count()).toBe(0); - }); - - it('does not update label token color for `none` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); - - subject.tokenValue = 'none'; - - const { updateLabelTokenColorSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateLabelTokenColorSpy.calls.count()).toBe(0); - }); - - it('does not update label token color for `any` filter', () => { - const { subject, tokenValueContainer, tokenValueElement } = findElements(bugLabelToken); - - subject.tokenValue = 'any'; - - const { updateLabelTokenColorSpy } = setupSpies(subject); - subject.render(tokenValueContainer, tokenValueElement); - - expect(updateLabelTokenColorSpy.calls.count()).toBe(0); - }); - }); -}); diff --git a/spec/javascripts/ide/components/commit_sidebar/radio_group_spec.js b/spec/javascripts/ide/components/commit_sidebar/radio_group_spec.js deleted file mode 100644 index b30f0e6822b..00000000000 --- a/spec/javascripts/ide/components/commit_sidebar/radio_group_spec.js +++ /dev/null @@ -1,139 +0,0 @@ -import Vue from 'vue'; -import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; -import { resetStore } from 'spec/ide/helpers'; -import store from '~/ide/stores'; -import radioGroup from '~/ide/components/commit_sidebar/radio_group.vue'; - -describe('IDE commit sidebar radio group', () => { - let vm; - - beforeEach(done => { - const Component = Vue.extend(radioGroup); - - store.state.commit.commitAction = '2'; - - vm = createComponentWithStore(Component, store, { - value: '1', - label: 'test', - checked: true, - }); - - vm.$mount(); - - Vue.nextTick(done); - }); - - afterEach(() => { - vm.$destroy(); - - resetStore(vm.$store); - }); - - it('uses label if present', () => { - expect(vm.$el.textContent).toContain('test'); - }); - - it('uses slot if label is not present', done => { - vm.$destroy(); - - vm = new Vue({ - components: { - radioGroup, - }, - store, - template: ` - <radio-group - value="1" - > - Testing slot - </radio-group> - `, - }); - - vm.$mount(); - - Vue.nextTick(() => { - expect(vm.$el.textContent).toContain('Testing slot'); - - done(); - }); - }); - - it('updates store when changing radio button', done => { - vm.$el.querySelector('input').dispatchEvent(new Event('change')); - - Vue.nextTick(() => { - expect(store.state.commit.commitAction).toBe('1'); - - done(); - }); - }); - - describe('with input', () => { - beforeEach(done => { - vm.$destroy(); - - const Component = Vue.extend(radioGroup); - - store.state.commit.commitAction = '1'; - store.state.commit.newBranchName = 'test-123'; - - vm = createComponentWithStore(Component, store, { - value: '1', - label: 'test', - checked: true, - showInput: true, - }); - - vm.$mount(); - - Vue.nextTick(done); - }); - - it('renders input box when commitAction matches value', () => { - expect(vm.$el.querySelector('.form-control')).not.toBeNull(); - }); - - it('hides input when commitAction doesnt match value', done => { - store.state.commit.commitAction = '2'; - - Vue.nextTick(() => { - expect(vm.$el.querySelector('.form-control')).toBeNull(); - done(); - }); - }); - - it('updates branch name in store on input', done => { - const input = vm.$el.querySelector('.form-control'); - input.value = 'testing-123'; - input.dispatchEvent(new Event('input')); - - Vue.nextTick(() => { - expect(store.state.commit.newBranchName).toBe('testing-123'); - - done(); - }); - }); - - it('renders newBranchName if present', () => { - const input = vm.$el.querySelector('.form-control'); - - expect(input.value).toBe('test-123'); - }); - }); - - describe('tooltipTitle', () => { - it('returns title when disabled', () => { - vm.title = 'test title'; - vm.disabled = true; - - expect(vm.tooltipTitle).toBe('test title'); - }); - - it('returns blank when not disabled', () => { - vm.title = 'test title'; - - expect(vm.tooltipTitle).not.toBe('test title'); - }); - }); -}); diff --git a/spec/javascripts/ide/components/file_row_extra_spec.js b/spec/javascripts/ide/components/file_row_extra_spec.js deleted file mode 100644 index 9fd014b50ef..00000000000 --- a/spec/javascripts/ide/components/file_row_extra_spec.js +++ /dev/null @@ -1,170 +0,0 @@ -import Vue from 'vue'; -import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; -import { createStore } from '~/ide/stores'; -import FileRowExtra from '~/ide/components/file_row_extra.vue'; -import { file, resetStore } from '../helpers'; - -describe('IDE extra file row component', () => { - let Component; - let vm; - let unstagedFilesCount = 0; - let stagedFilesCount = 0; - let changesCount = 0; - - beforeAll(() => { - Component = Vue.extend(FileRowExtra); - }); - - beforeEach(() => { - vm = createComponentWithStore(Component, createStore(), { - file: { - ...file('test'), - }, - dropdownOpen: false, - }); - - spyOnProperty(vm, 'getUnstagedFilesCountForPath').and.returnValue(() => unstagedFilesCount); - spyOnProperty(vm, 'getStagedFilesCountForPath').and.returnValue(() => stagedFilesCount); - spyOnProperty(vm, 'getChangesInFolder').and.returnValue(() => changesCount); - - vm.$mount(); - }); - - afterEach(() => { - vm.$destroy(); - resetStore(vm.$store); - - stagedFilesCount = 0; - unstagedFilesCount = 0; - changesCount = 0; - }); - - describe('folderChangesTooltip', () => { - it('returns undefined when changes count is 0', () => { - changesCount = 0; - - expect(vm.folderChangesTooltip).toBe(undefined); - }); - - [{ input: 1, output: '1 changed file' }, { input: 2, output: '2 changed files' }].forEach( - ({ input, output }) => { - it('returns changed files count if changes count is not 0', () => { - changesCount = input; - - expect(vm.folderChangesTooltip).toBe(output); - }); - }, - ); - }); - - describe('show tree changes count', () => { - it('does not show for blobs', () => { - vm.file.type = 'blob'; - - expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null); - }); - - it('does not show when changes count is 0', () => { - vm.file.type = 'tree'; - - expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null); - }); - - it('does not show when tree is open', done => { - vm.file.type = 'tree'; - vm.file.opened = true; - changesCount = 1; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.ide-tree-changes')).toBe(null); - - done(); - }); - }); - - it('shows for trees with changes', done => { - vm.file.type = 'tree'; - vm.file.opened = false; - changesCount = 1; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.ide-tree-changes')).not.toBe(null); - - done(); - }); - }); - }); - - describe('changes file icon', () => { - it('hides when file is not changed', () => { - expect(vm.$el.querySelector('.file-changed-icon')).toBe(null); - }); - - it('shows when file is changed', done => { - vm.file.changed = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null); - - done(); - }); - }); - - it('shows when file is staged', done => { - vm.file.staged = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null); - - done(); - }); - }); - - it('shows when file is a tempFile', done => { - vm.file.tempFile = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null); - - done(); - }); - }); - - it('shows when file is renamed', done => { - vm.file.prevPath = 'original-file'; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.file-changed-icon')).not.toBe(null); - - done(); - }); - }); - - it('hides when file is renamed', done => { - vm.file.prevPath = 'original-file'; - vm.file.type = 'tree'; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.file-changed-icon')).toBe(null); - - done(); - }); - }); - }); - - describe('merge request icon', () => { - it('hides when not a merge request change', () => { - expect(vm.$el.querySelector('.ic-git-merge')).toBe(null); - }); - - it('shows when a merge request change', done => { - vm.file.mrChange = true; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.ic-git-merge')).not.toBe(null); - - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/ide/components/ide_review_spec.js b/spec/javascripts/ide/components/ide_review_spec.js deleted file mode 100644 index 396c5d282d4..00000000000 --- a/spec/javascripts/ide/components/ide_review_spec.js +++ /dev/null @@ -1,69 +0,0 @@ -import Vue from 'vue'; -import IdeReview from '~/ide/components/ide_review.vue'; -import store from '~/ide/stores'; -import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; -import { trimText } from '../../helpers/text_helper'; -import { resetStore, file } from '../helpers'; -import { projectData } from '../mock_data'; - -describe('IDE review mode', () => { - const Component = Vue.extend(IdeReview); - let vm; - - beforeEach(() => { - store.state.currentProjectId = 'abcproject'; - store.state.currentBranchId = 'master'; - store.state.projects.abcproject = Object.assign({}, projectData); - Vue.set(store.state.trees, 'abcproject/master', { - tree: [file('fileName')], - loading: false, - }); - - vm = createComponentWithStore(Component, store).$mount(); - }); - - afterEach(() => { - vm.$destroy(); - - resetStore(vm.$store); - }); - - it('renders list of files', () => { - expect(vm.$el.textContent).toContain('fileName'); - }); - - describe('merge request', () => { - beforeEach(done => { - store.state.currentMergeRequestId = '1'; - store.state.projects.abcproject.mergeRequests['1'] = { - iid: 123, - web_url: 'testing123', - }; - - vm.$nextTick(done); - }); - - it('renders edit dropdown', () => { - expect(vm.$el.querySelector('.btn')).not.toBe(null); - }); - - it('renders merge request link & IID', () => { - const link = vm.$el.querySelector('.ide-review-sub-header'); - - expect(link.querySelector('a').getAttribute('href')).toBe('testing123'); - expect(trimText(link.textContent)).toBe('Merge request (!123)'); - }); - - it('changes text to latest changes when viewer is not mrdiff', done => { - store.state.viewer = 'diff'; - - vm.$nextTick(() => { - expect(trimText(vm.$el.querySelector('.ide-review-sub-header').textContent)).toBe( - 'Latest changes', - ); - - done(); - }); - }); - }); -}); diff --git a/spec/javascripts/ide/components/ide_status_bar_spec.js b/spec/javascripts/ide/components/ide_status_bar_spec.js deleted file mode 100644 index 3facf1c266a..00000000000 --- a/spec/javascripts/ide/components/ide_status_bar_spec.js +++ /dev/null @@ -1,129 +0,0 @@ -import Vue from 'vue'; -import _ from 'lodash'; -import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; -import { TEST_HOST } from 'spec/test_constants'; -import { createStore } from '~/ide/stores'; -import IdeStatusBar from '~/ide/components/ide_status_bar.vue'; -import { rightSidebarViews } from '~/ide/constants'; -import { projectData } from '../mock_data'; - -const TEST_PROJECT_ID = 'abcproject'; -const TEST_MERGE_REQUEST_ID = '9001'; -const TEST_MERGE_REQUEST_URL = `${TEST_HOST}merge-requests/${TEST_MERGE_REQUEST_ID}`; - -describe('ideStatusBar', () => { - let store; - let vm; - - const createComponent = () => { - vm = createComponentWithStore(Vue.extend(IdeStatusBar), store).$mount(); - }; - const findMRStatus = () => vm.$el.querySelector('.js-ide-status-mr'); - - beforeEach(() => { - store = createStore(); - store.state.currentProjectId = TEST_PROJECT_ID; - store.state.projects[TEST_PROJECT_ID] = _.clone(projectData); - store.state.currentBranchId = 'master'; - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('default', () => { - beforeEach(() => { - createComponent(); - }); - - it('triggers a setInterval', () => { - expect(vm.intervalId).not.toBe(null); - }); - - it('renders the statusbar', () => { - expect(vm.$el.className).toBe('ide-status-bar'); - }); - - describe('commitAgeUpdate', () => { - beforeEach(function() { - jasmine.clock().install(); - spyOn(vm, 'commitAgeUpdate').and.callFake(() => {}); - vm.startTimer(); - }); - - afterEach(function() { - jasmine.clock().uninstall(); - }); - - it('gets called every second', () => { - expect(vm.commitAgeUpdate).not.toHaveBeenCalled(); - - jasmine.clock().tick(1100); - - expect(vm.commitAgeUpdate.calls.count()).toEqual(1); - - jasmine.clock().tick(1000); - - expect(vm.commitAgeUpdate.calls.count()).toEqual(2); - }); - }); - - describe('getCommitPath', () => { - it('returns the path to the commit details', () => { - expect(vm.getCommitPath('abc123de')).toBe('/commit/abc123de'); - }); - }); - - describe('pipeline status', () => { - it('opens right sidebar on clicking icon', done => { - spyOn(vm, 'openRightPane'); - Vue.set(vm.$store.state.pipelines, 'latestPipeline', { - details: { - status: { - text: 'success', - details_path: 'test', - icon: 'status_success', - }, - }, - commit: { - author_gravatar_url: 'www', - }, - }); - - vm.$nextTick() - .then(() => { - vm.$el.querySelector('.ide-status-pipeline button').click(); - - expect(vm.openRightPane).toHaveBeenCalledWith(rightSidebarViews.pipelines); - }) - .then(done) - .catch(done.fail); - }); - }); - - it('does not show merge request status', () => { - expect(findMRStatus()).toBe(null); - }); - }); - - describe('with merge request in store', () => { - beforeEach(() => { - store.state.projects[TEST_PROJECT_ID].mergeRequests = { - [TEST_MERGE_REQUEST_ID]: { - web_url: TEST_MERGE_REQUEST_URL, - references: { - short: `!${TEST_MERGE_REQUEST_ID}`, - }, - }, - }; - store.state.currentMergeRequestId = TEST_MERGE_REQUEST_ID; - - createComponent(); - }); - - it('shows merge request status', () => { - expect(findMRStatus().textContent.trim()).toEqual(`Merge request !${TEST_MERGE_REQUEST_ID}`); - expect(findMRStatus().querySelector('a').href).toEqual(TEST_MERGE_REQUEST_URL); - }); - }); -}); diff --git a/spec/javascripts/ide/components/merge_requests/item_spec.js b/spec/javascripts/ide/components/merge_requests/item_spec.js deleted file mode 100644 index 155a247defb..00000000000 --- a/spec/javascripts/ide/components/merge_requests/item_spec.js +++ /dev/null @@ -1,63 +0,0 @@ -import Vue from 'vue'; -import router from '~/ide/ide_router'; -import Item from '~/ide/components/merge_requests/item.vue'; -import mountCompontent from '../../../helpers/vue_mount_component_helper'; - -describe('IDE merge request item', () => { - const Component = Vue.extend(Item); - let vm; - - beforeEach(() => { - vm = mountCompontent(Component, { - item: { - iid: 1, - projectPathWithNamespace: 'gitlab-org/gitlab-ce', - title: 'Merge request title', - }, - currentId: '1', - currentProjectId: 'gitlab-org/gitlab-ce', - }); - }); - - afterEach(() => { - vm.$destroy(); - }); - - it('renders merge requests data', () => { - expect(vm.$el.textContent).toContain('Merge request title'); - expect(vm.$el.textContent).toContain('gitlab-org/gitlab-ce!1'); - }); - - it('renders link with href', () => { - const expectedHref = router.resolve( - `/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`, - ).href; - - expect(vm.$el).toMatch('a'); - expect(vm.$el).toHaveAttr('href', expectedHref); - }); - - it('renders icon if ID matches currentId', () => { - expect(vm.$el.querySelector('.ic-mobile-issue-close')).not.toBe(null); - }); - - it('does not render icon if ID does not match currentId', done => { - vm.currentId = '2'; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null); - - done(); - }); - }); - - it('does not render icon if project ID does not match', done => { - vm.currentProjectId = 'test/test'; - - vm.$nextTick(() => { - expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null); - - done(); - }); - }); -}); diff --git a/spec/javascripts/ide/components/new_dropdown/upload_spec.js b/spec/javascripts/ide/components/new_dropdown/upload_spec.js deleted file mode 100644 index 66ddf6c0ee6..00000000000 --- a/spec/javascripts/ide/components/new_dropdown/upload_spec.js +++ /dev/null @@ -1,112 +0,0 @@ -import Vue from 'vue'; -import createComponent from 'spec/helpers/vue_mount_component_helper'; -import upload from '~/ide/components/new_dropdown/upload.vue'; - -describe('new dropdown upload', () => { - let vm; - - beforeEach(() => { - const Component = Vue.extend(upload); - - vm = createComponent(Component, { - path: '', - }); - - vm.entryName = 'testing'; - - spyOn(vm, '$emit').and.callThrough(); - }); - - afterEach(() => { - vm.$destroy(); - }); - - describe('openFile', () => { - it('calls for each file', () => { - const files = ['test', 'test2', 'test3']; - - spyOn(vm, 'readFile'); - spyOnProperty(vm.$refs.fileUpload, 'files').and.returnValue(files); - - vm.openFile(); - - expect(vm.readFile.calls.count()).toBe(3); - - files.forEach((file, i) => { - expect(vm.readFile.calls.argsFor(i)).toEqual([file]); - }); - }); - }); - - describe('readFile', () => { - beforeEach(() => { - spyOn(FileReader.prototype, 'readAsDataURL'); - }); - - it('calls readAsDataURL for all files', () => { - const file = { - type: 'images/png', - }; - - vm.readFile(file); - - expect(FileReader.prototype.readAsDataURL).toHaveBeenCalledWith(file); - }); - }); - - describe('createFile', () => { - const textTarget = { - result: 'base64,cGxhaW4gdGV4dA==', - }; - const binaryTarget = { - result: 'base64,w4I=', - }; - const textFile = new File(['plain text'], 'textFile'); - - const binaryFile = { - name: 'binaryFile', - type: 'image/png', - }; - - beforeEach(() => { - spyOn(FileReader.prototype, 'readAsText').and.callThrough(); - }); - - it('calls readAsText and creates file in plain text (without encoding) if the file content is plain text', done => { - const waitForCreate = new Promise(resolve => vm.$on('create', resolve)); - - vm.createFile(textTarget, textFile); - - expect(FileReader.prototype.readAsText).toHaveBeenCalledWith(textFile); - - waitForCreate - .then(() => { - expect(vm.$emit).toHaveBeenCalledWith('create', { - name: textFile.name, - type: 'blob', - content: 'plain text', - base64: false, - binary: false, - rawPath: '', - }); - }) - .then(done) - .catch(done.fail); - }); - - it('splits content on base64 if binary', () => { - vm.createFile(binaryTarget, binaryFile); - - expect(FileReader.prototype.readAsText).not.toHaveBeenCalledWith(textFile); - - expect(vm.$emit).toHaveBeenCalledWith('create', { - name: binaryFile.name, - type: 'blob', - content: binaryTarget.result.split('base64,')[1], - base64: true, - binary: true, - rawPath: binaryTarget.result, - }); - }); - }); -}); |