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-23 05:09:42 -04:00
|
|
|
import setHighlightClass from '~/pages/search/show/highlight_blob_search_result';
|
2018-01-17 18:32:42 -05:00
|
|
|
|
2020-03-03 10:08:08 -05:00
|
|
|
jest.mock('~/api');
|
2020-03-23 05:09:42 -04:00
|
|
|
jest.mock('~/pages/search/show/highlight_blob_search_result');
|
2020-03-03 10:08:08 -05:00
|
|
|
|
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);
|
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
describe('constructor side effects', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('highlights lines with search terms in blob search results', () => {
|
|
|
|
new Search(); // eslint-disable-line no-new
|
|
|
|
|
|
|
|
expect(setHighlightClass).toHaveBeenCalled();
|
|
|
|
});
|
2018-01-17 18:32:42 -05:00
|
|
|
});
|
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
describe('dropdown behavior', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixturePath);
|
|
|
|
new Search(); // eslint-disable-line no-new
|
2018-01-17 18:32:42 -05:00
|
|
|
});
|
2020-03-03 10:08:08 -05:00
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
it('requests groups from backend when filtering', () => {
|
|
|
|
jest.spyOn(Api, 'groups').mockImplementation(term => {
|
|
|
|
expect(term).toBe(searchTerm);
|
|
|
|
});
|
2018-01-17 18:32:42 -05:00
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
const inputElement = fillDropdownInput('.js-search-group-dropdown');
|
2018-01-17 18:32:42 -05:00
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
$(inputElement).trigger('input');
|
2018-01-17 18:32:42 -05:00
|
|
|
});
|
|
|
|
|
2020-03-23 05:09:42 -04:00
|
|
|
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');
|
|
|
|
});
|
2018-01-17 18:32:42 -05:00
|
|
|
});
|
|
|
|
});
|