gitlab-org--gitlab-foss/spec/javascripts/filtered_search/filtered_search_dropdown_ma...

60 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-01-05 19:56:23 +00:00
//= require extensions/array
//= 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;
}
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:');
});
2017-01-05 19:56:23 +00:00
it('should add tokenName and tokenValue', () => {
gl.FilteredSearchDropdownManager.addWordToInput('label', 'none');
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');
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"\'');
2016-12-15 18:19:03 +00:00
expect(getInputValue()).toBe('label:~\'"test me"\'');
});
});
});
});
})();