Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
21 deletions
+55
-21
spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6
...tered_search/filtered_search_dropdown_manager_spec.js.es6
+55
-21
No files found.
spec/javascripts/filtered_search/filtered_search_dropdown_manager_spec.js.es6
View file @
89204c22
...
...
@@ -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(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