gitlab-org--gitlab-foss/spec/frontend/search_spec.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

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