debian-mirror-gitlab/spec/frontend/search_spec.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2021-01-29 00:20:46 +05:30
import setHighlightClass from 'ee_else_ce/search/highlight_blob_search_result';
2018-03-17 18:26:18 +05:30
import Api from '~/api';
import Search from '~/pages/search/show/search';
2020-04-08 14:13:33 +05:30
jest.mock('~/api');
2021-01-29 00:20:46 +05:30
jest.mock('ee_else_ce/search/highlight_blob_search_result');
2020-04-08 14:13:33 +05:30
2018-03-17 18:26:18 +05:30
describe('Search', () => {
2019-07-07 11:18:12 +05:30
const fixturePath = 'search/show.html';
2018-03-17 18:26:18 +05:30
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);
2020-04-22 19:07:51 +05:30
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-03-17 18:26:18 +05:30
});
2020-04-22 19:07:51 +05:30
describe('dropdown behavior', () => {
beforeEach(() => {
loadFixtures(fixturePath);
new Search(); // eslint-disable-line no-new
2018-03-17 18:26:18 +05:30
});
2020-04-08 14:13:33 +05:30
2020-04-22 19:07:51 +05:30
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-03-17 18:26:18 +05:30
});
});