2017-01-13 16:27:19 +00:00
|
|
|
require('~/extensions/array');
|
|
|
|
require('~/filtered_search/filtered_search_tokenizer');
|
|
|
|
require('~/filtered_search/filtered_search_dropdown_manager');
|
2016-12-15 03:51:33 +00:00
|
|
|
|
|
|
|
(() => {
|
|
|
|
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
|
|
|
|
2017-01-05 19:56:23 +00:00
|
|
|
function setInputValue(value) {
|
|
|
|
document.querySelector('.filtered-search').value = value;
|
|
|
|
}
|
|
|
|
|
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', () => {
|
2017-01-05 19:56:23 +00:00
|
|
|
it('should add just tokenName', () => {
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('milestone');
|
|
|
|
expect(getInputValue()).toBe('milestone:');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
|
2017-01-05 19:56:23 +00:00
|
|
|
it('should add tokenName and tokenValue', () => {
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('label', 'none');
|
2017-01-22 05:28:37 +00:00
|
|
|
expect(getInputValue()).toBe('label:none ');
|
2016-12-15 18:19:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-05 19:56:23 +00:00
|
|
|
describe('input has existing value', () => {
|
|
|
|
it('should be able to just add tokenName', () => {
|
|
|
|
setInputValue('a');
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('author');
|
|
|
|
expect(getInputValue()).toBe('author:');
|
|
|
|
});
|
2016-12-15 18:19:03 +00:00
|
|
|
|
2017-01-05 19:56:23 +00:00
|
|
|
it('should replace tokenValue', () => {
|
|
|
|
setInputValue('author:roo');
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('author', '@root');
|
2017-01-22 05:28:37 +00:00
|
|
|
expect(getInputValue()).toBe('author:@root ');
|
2016-12-15 18:19:03 +00:00
|
|
|
});
|
|
|
|
|
2017-01-05 19:56:23 +00:00
|
|
|
it('should add tokenValues containing spaces', () => {
|
|
|
|
setInputValue('label:~"test');
|
|
|
|
gl.FilteredSearchDropdownManager.addWordToInput('label', '~\'"test me"\'');
|
2017-01-22 05:28:37 +00:00
|
|
|
expect(getInputValue()).toBe('label:~\'"test me"\' ');
|
2016-12-15 03:51:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|