diff options
author | Clement Ho <ClemMakesApps@gmail.com> | 2017-01-05 13:56:23 -0600 |
---|---|---|
committer | Clement Ho <ClemMakesApps@gmail.com> | 2017-01-09 16:01:36 -0600 |
commit | c349bb15b628039340054eb132201fdf4a740411 (patch) | |
tree | 95b5aa449adff7bb4b2e2f30c58fd76c4cbc598c /spec | |
parent | 8f77b3177f1c342cc0a05c79e45e88bcda04040a (diff) | |
download | gitlab-ce-c349bb15b628039340054eb132201fdf4a740411.tar.gz |
Refactor addWordToInput
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 | 57 |
1 files changed, 24 insertions, 33 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 index e9841e3c89e..d0d27ceb4a6 100644 --- a/spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 +++ b/spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6 @@ -1,3 +1,4 @@ +//= require extensions/array //= require filtered_search/filtered_search_tokenizer //= require filtered_search/filtered_search_dropdown_manager @@ -8,6 +9,10 @@ return document.querySelector('.filtered-search').value; } + function setInputValue(value) { + document.querySelector('.filtered-search').value = value; + } + beforeEach(() => { const input = document.createElement('input'); input.classList.add('filtered-search'); @@ -19,47 +24,33 @@ }); describe('input has no existing value', () => { - it('should add word', () => { - gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); - expect(getInputValue()).toBe('firstWord'); - }); - - it('should not add space before first word', () => { - gl.FilteredSearchDropdownManager.addWordToInput('firstWord', true); - expect(getInputValue()).toBe('firstWord'); + it('should add just tokenName', () => { + gl.FilteredSearchDropdownManager.addWordToInput('milestone'); + expect(getInputValue()).toBe('milestone:'); }); - it('should not add space before second word by default', () => { - gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); - expect(getInputValue()).toBe('firstWord'); - gl.FilteredSearchDropdownManager.addWordToInput('secondWord'); - expect(getInputValue()).toBe('firstWordsecondWord'); - }); - - it('should add space before new word when addSpace is passed', () => { - expect(getInputValue()).toBe(''); - gl.FilteredSearchDropdownManager.addWordToInput('firstWord'); - expect(getInputValue()).toBe('firstWord'); - gl.FilteredSearchDropdownManager.addWordToInput('secondWord', true); - expect(getInputValue()).toBe('firstWord secondWord'); + it('should add tokenName and tokenValue', () => { + gl.FilteredSearchDropdownManager.addWordToInput('label', 'none'); + expect(getInputValue()).toBe('label:none'); }); }); - describe('input has exsting value', () => { - it('should only add the remaining characters of the word', () => { - const lastToken = { - key: 'author', - value: 'roo', - }; + describe('input has existing value', () => { + it('should be able to just add tokenName', () => { + setInputValue('a'); + gl.FilteredSearchDropdownManager.addWordToInput('author'); + expect(getInputValue()).toBe('author:'); + }); - document.querySelector('.filtered-search').value = `${lastToken.key}:${lastToken.value}`; - gl.FilteredSearchDropdownManager.addWordToInput('root'); - expect(getInputValue()).toBe('author:root'); + it('should replace tokenValue', () => { + setInputValue('author:roo'); + gl.FilteredSearchDropdownManager.addWordToInput('author', '@root'); + expect(getInputValue()).toBe('author:@root'); }); - it('should only add the remaining characters of the word (contains space)', () => { - document.querySelector('.filtered-search').value = 'label:~"test'; - gl.FilteredSearchDropdownManager.addWordToInput('~\'"test me"\''); + it('should add tokenValues containing spaces', () => { + setInputValue('label:~"test'); + gl.FilteredSearchDropdownManager.addWordToInput('label', '~\'"test me"\''); expect(getInputValue()).toBe('label:~\'"test me"\''); }); }); |