diff options
author | Clement Ho <ClemMakesApps@gmail.com> | 2016-12-14 21:51:33 -0600 |
---|---|---|
committer | Clement Ho <ClemMakesApps@gmail.com> | 2017-01-09 16:01:27 -0600 |
commit | f7b6361124c3abb4380035eaf3b7625433686543 (patch) | |
tree | 1392eff8b220bb5cdc1674cf6628dce1ea468b97 /spec | |
parent | d93ccb8e0949e345efa9a1dcf874c73f8d1975bc (diff) | |
download | gitlab-ce-f7b6361124c3abb4380035eaf3b7625433686543.tar.gz |
Add jasmine tests for filtered search dropdown manager
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 b/spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 new file mode 100644 index 00000000000..11765d7d7ea --- /dev/null +++ b/spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 @@ -0,0 +1,57 @@ +//= require filtered_search/filtered_search_tokenizer +//= require filtered_search/filtered_search_dropdown_manager + +(() => { + describe('Filtered Search Dropdown Manager', () => { + describe('addWordToInput', () => { + describe('add word and when lastToken is an empty object', () => { + function getInput() { + return document.querySelector('.filtered-search'); + } + + beforeEach(() => { + spyOn(gl.FilteredSearchTokenizer, 'processTokens') + .and.callFake(query => ({ + lastToken: {} + }) + ); + + const input = document.createElement('input'); + input.classList.add('filtered-search'); + document.body.appendChild(input); + + expect(input.value).toBe(''); + }); + + afterEach(() => { + document.querySelector('.filtered-search').outerHTML = ''; + }); + + it('should add word', () => { + gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); + expect(getInput().value).toBe('firstWord'); + }); + + it('should not add space before first word', () => { + gl.FilteredSearchDropdownManager.addWordToInput('firstWord', true); + expect(getInput().value).toBe('firstWord'); + }); + + it('should not add space before second word by default', () => { + gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); + expect(getInput().value).toBe('firstWord'); + gl.FilteredSearchDropdownManager.addWordToInput('secondWord'); + expect(getInput().value).toBe('firstWordsecondWord'); + }); + + it('should add space before new word when addSpace is passed', () => { + expect(getInput().value).toBe(''); + gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); + expect(getInput().value).toBe('firstWord'); + gl.FilteredSearchDropdownManager.addWordToInput('secondWord', true); + expect(getInput().value).toBe('firstWord secondWord'); + }); + }); + }); + }); +})(); |