2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import Api from '~/api';
|
|
|
|
import Search from '~/pages/search/show/search';
|
|
|
|
|
|
|
|
describe('Search', () => {
|
|
|
|
const fixturePath = 'search/show.html.raw';
|
|
|
|
const searchTerm = 'some search';
|
2018-12-13 13:39:08 +05:30
|
|
|
const fillDropdownInput = dropdownSelector => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const dropdownElement = document.querySelector(dropdownSelector).parentNode;
|
|
|
|
const inputElement = dropdownElement.querySelector('.dropdown-input-field');
|
|
|
|
inputElement.value = searchTerm;
|
|
|
|
return inputElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
preloadFixtures(fixturePath);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixturePath);
|
|
|
|
new Search(); // eslint-disable-line no-new
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('requests groups from backend when filtering', done => {
|
|
|
|
spyOn(Api, 'groups').and.callFake(term => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(term).toBe(searchTerm);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
const inputElement = fillDropdownInput('.js-search-group-dropdown');
|
|
|
|
|
|
|
|
$(inputElement).trigger('input');
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('requests projects from backend when filtering', done => {
|
|
|
|
spyOn(Api, 'projects').and.callFake(term => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(term).toBe(searchTerm);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
const inputElement = fillDropdownInput('.js-search-project-dropdown');
|
|
|
|
|
|
|
|
$(inputElement).trigger('input');
|
|
|
|
});
|
|
|
|
});
|