summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorClement Ho <ClemMakesApps@gmail.com>2017-01-05 13:56:23 -0600
committerClement Ho <ClemMakesApps@gmail.com>2017-01-09 16:01:36 -0600
commitc349bb15b628039340054eb132201fdf4a740411 (patch)
tree95b5aa449adff7bb4b2e2f30c58fd76c4cbc598c /spec
parent8f77b3177f1c342cc0a05c79e45e88bcda04040a (diff)
downloadgitlab-ce-c349bb15b628039340054eb132201fdf4a740411.tar.gz
Refactor addWordToInput
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es657
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"\'');
});
});