2016-12-15 03:51:33 +00:00
|
|
|
//= require filtered_search/filtered_search_tokenizer
|
|
|
|
//= require filtered_search/filtered_search_dropdown_manager
|
|
|
|
|
|
|
|
(() => {
|
|
|
|
describe('Filtered Search Dropdown Manager', () => {
|
|
|
|
describe('addWordToInput', () => {
|
2016-12-15 18:19:03 +00:00
|
|
|
function getInputValue() {
|
|
|
|
return document.querySelector('.filtered-search').value;
|
|
|
|
}
|
2016-12-15 03:51:33 +00:00
|
|
|
|
2016-12-15 18:19:03 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
const input = document.createElement('input');
|
|
|
|
input.classList.add('filtered-search');
|
|
|
|
document.body.appendChild(input);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.querySelector('.filtered-search').outerHTML = '';
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('input has no existing value', () => {
|
2016-12-15 03:51:33 +00:00
|
|
|
it('should add word', () => {
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('firstWord');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add space before first word', () => {
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('firstWord', true);
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('firstWord');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add space before second word by default', () => {
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('firstWord');
|
2016-12-15 03:51:33 +00:00
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('secondWord');
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('firstWordsecondWord');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add space before new word when addSpace is passed', () => {
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('');
|
2016-12-15 03:51:33 +00:00
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('firstWord');
|
2016-12-15 18:19:03 +00:00
|
|
|
expect(getInputValue()).toBe('firstWord');
|
2016-12-15 03:51:33 +00:00
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('secondWord', true);
|
2016-12-15 18:19:03 +00:00
|
|
|
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',
|
|
|
|
};
|
|
|
|
|
|
|
|
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)', () => {
|
2016-12-17 19:22:00 +00:00
|
|
|
document.querySelector('.filtered-search').value = 'label:~"test';
|
2016-12-15 18:19:03 +00:00
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('~\'"test me"\'');
|
|
|
|
expect(getInputValue()).toBe('label:~\'"test me"\'');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|