BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
89204c22
Commit
89204c22
authored
Dec 15, 2016
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for addWordToInput
parent
78dd92b7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
15 deletions
+49
-15
filtered_search_dropdown_manager_spec.js.es6
...tered_search/filtered_search_dropdown_manager_spec.js.es6
+49
-15
No files found.
spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6
View file @
89204c22
...
...
@@ -4,17 +4,11 @@
(() => {
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(() => {
spyOn(gl.FilteredSearchTokenizer, 'processTokens')
.and.callFake(() => ({
lastToken: {},
}));
const input = document.createElement('input');
input.classList.add('filtered-search');
document.body.appendChild(input);
...
...
@@ -26,29 +20,69 @@
document.querySelector('.filtered-search').outerHTML = '';
});
describe('input has no existing value', () => {
beforeEach(() => {
spyOn(gl.FilteredSearchTokenizer, 'processTokens')
.and.callFake(() => ({
lastToken: {},
}));
});
it('should add word', () => {
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
expect(getInput
().value
).toBe('firstWord');
expect(getInput
Value()
).toBe('firstWord');
});
it('should not add space before first word', () => {
gl.FilteredSearchDropdownManager.addWordToInput('firstWord', true);
expect(getInput
().value
).toBe('firstWord');
expect(getInput
Value()
).toBe('firstWord');
});
it('should not add space before second word by default', () => {
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
expect(getInput
().value
).toBe('firstWord');
expect(getInput
Value()
).toBe('firstWord');
gl.FilteredSearchDropdownManager.addWordToInput('secondWord');
expect(getInput
().value
).toBe('firstWordsecondWord');
expect(getInput
Value()
).toBe('firstWordsecondWord');
});
it('should add space before new word when addSpace is passed', () => {
expect(getInput
().value
).toBe('');
expect(getInput
Value()
).toBe('');
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
expect(getInput
().value
).toBe('firstWord');
expect(getInput
Value()
).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"\'');
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment