2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-01-17 18:32:42 -05:00
|
|
|
import Api from '~/api';
|
|
|
|
import Search from '~/pages/search/show/search';
|
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
jest.mock('~/api');
|
|
|
|
|
2018-01-17 18:32:42 -05:00
|
|
|
describe('Search', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
const fixturePath = 'search/show.html';
|
2018-01-17 18:32:42 -05:00
|
|
|
const searchTerm = 'some search';
|
2018-10-17 03:13:26 -04:00
|
|
|
const fillDropdownInput = dropdownSelector => {
|
2018-01-17 18:32:42 -05:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
it('requests groups from backend when filtering', () => {
|
|
|
|
jest.spyOn(Api, 'groups').mockImplementation(term => {
|
2018-01-17 18:32:42 -05:00
|
|
|
expect(term).toBe(searchTerm);
|
|
|
|
});
|
2020-03-03 10:08:08 -05:00
|
|
|
|
2018-01-17 18:32:42 -05:00
|
|
|
const inputElement = fillDropdownInput('.js-search-group-dropdown');
|
|
|
|
|
|
|
|
$(inputElement).trigger('input');
|
|
|
|
});
|
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
it('requests projects from backend when filtering', () => {
|
|
|
|
jest.spyOn(Api, 'projects').mockImplementation(term => {
|
2018-01-17 18:32:42 -05:00
|
|
|
expect(term).toBe(searchTerm);
|
|
|
|
});
|
|
|
|
const inputElement = fillDropdownInput('.js-search-project-dropdown');
|
|
|
|
|
|
|
|
$(inputElement).trigger('input');
|
|
|
|
});
|
|
|
|
});
|