summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorClement Ho <ClemMakesApps@gmail.com>2016-12-15 12:19:03 -0600
committerClement Ho <ClemMakesApps@gmail.com>2017-01-09 16:01:29 -0600
commit89204c22f15720080f71e424e50bad9485a49172 (patch)
tree32662ff857d2743c417aa5bf0fbaa65ef198d6c4 /spec
parent78dd92b730063371742b6487ae2526d6cc0943b1 (diff)
downloadgitlab-ce-89204c22f15720080f71e424e50bad9485a49172.tar.gz
Add specs for addWordToInput
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es676
1 files changed, 55 insertions, 21 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 4a358bd43e3..17d414aaad1 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
@@ -4,51 +4,85 @@
(() => {
describe('Filtered Search Dropdown Manager', () => {
describe('addWordToInput', () => {
- describe('add word and when lastToken is an empty object', () => {
- function getInput() {
- return document.querySelector('.filtered-search');
- }
+ function getInputValue() {
+ return document.querySelector('.filtered-search').value;
+ }
+ beforeEach(() => {
+ const input = document.createElement('input');
+ input.classList.add('filtered-search');
+ document.body.appendChild(input);
+
+ expect(input.value).toBe('');
+ });
+
+ afterEach(() => {
+ document.querySelector('.filtered-search').outerHTML = '';
+ });
+
+ describe('input has no existing value', () => {
beforeEach(() => {
spyOn(gl.FilteredSearchTokenizer, 'processTokens')
.and.callFake(() => ({
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');
+ expect(getInputValue()).toBe('firstWord');
});
it('should not add space before first word', () => {
gl.FilteredSearchDropdownManager.addWordToInput('firstWord', true);
- expect(getInput().value).toBe('firstWord');
+ expect(getInputValue()).toBe('firstWord');
});
it('should not add space before second word by default', () => {
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
- expect(getInput().value).toBe('firstWord');
+ expect(getInputValue()).toBe('firstWord');
gl.FilteredSearchDropdownManager.addWordToInput('secondWord');
- expect(getInput().value).toBe('firstWordsecondWord');
+ expect(getInputValue()).toBe('firstWordsecondWord');
});
it('should add space before new word when addSpace is passed', () => {
- expect(getInput().value).toBe('');
+ expect(getInputValue()).toBe('');
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
- expect(getInput().value).toBe('firstWord');
+ expect(getInputValue()).toBe('firstWord');
gl.FilteredSearchDropdownManager.addWordToInput('secondWord', true);
- expect(getInput().value).toBe('firstWord secondWord');
+ expect(getInputValue()).toBe('firstWord secondWord');
+ });
+ });
+
+ describe('input has exsting value', () => {
+ it('should only add the remaining characters of the word', () => {
+ const lastToken = {
+ key: 'author',
+ value: 'roo',
+ };
+
+ spyOn(gl.FilteredSearchTokenizer, 'processTokens').and.callFake(() => ({
+ lastToken,
+ }));
+
+ document.querySelector('.filtered-search').value = `${lastToken.key}:${lastToken.value}`;
+ gl.FilteredSearchDropdownManager.addWordToInput('root');
+ expect(getInputValue()).toBe('author:root');
+ });
+
+ it('should only add the remaining characters of the word (contains space)', () => {
+ const lastToken = {
+ key: 'label',
+ value: 'test me',
+ };
+
+ spyOn(gl.FilteredSearchTokenizer, 'processTokens').and.callFake(() => ({
+ lastToken,
+ }));
+
+ document.querySelector('.filtered-search').value = `${lastToken.key}:"${lastToken.value}"`;
+ gl.FilteredSearchDropdownManager.addWordToInput('~\'"test me"\'');
+ expect(getInputValue()).toBe('label:~\'"test me"\'');
});
});
});