debian-mirror-gitlab/spec/frontend/filtered_search/dropdown_user_spec.js

118 lines
3.8 KiB
JavaScript
Raw Normal View History

2018-03-27 19:54:05 +05:30
import DropdownUtils from '~/filtered_search/dropdown_utils';
2021-03-11 19:13:27 +05:30
// TODO: Moving this line up throws an error about `FilteredSearchDropdown`
// being undefined in test. See gitlab-org/gitlab#321476 for more info.
// eslint-disable-next-line import/order
2018-03-27 19:54:05 +05:30
import DropdownUser from '~/filtered_search/dropdown_user';
import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer';
2018-12-05 23:21:45 +05:30
import IssuableFilteredTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
2018-03-17 18:26:18 +05:30
2017-08-17 22:00:37 +05:30
describe('Dropdown User', () => {
describe('getSearchInput', () => {
let dropdownUser;
beforeEach(() => {
2020-03-13 15:44:24 +05:30
jest.spyOn(DropdownUser.prototype, 'bindEvents').mockImplementation(() => {});
jest.spyOn(DropdownUser.prototype, 'getProjectId').mockImplementation(() => {});
jest.spyOn(DropdownUser.prototype, 'getGroupId').mockImplementation(() => {});
jest.spyOn(DropdownUtils, 'getSearchInput').mockImplementation(() => {});
2017-08-17 22:00:37 +05:30
2018-03-27 19:54:05 +05:30
dropdownUser = new DropdownUser({
2018-12-05 23:21:45 +05:30
tokenKeys: IssuableFilteredTokenKeys,
2017-09-10 17:25:29 +05:30
});
2017-08-17 22:00:37 +05:30
});
it('should not return the double quote found in value', () => {
2020-03-13 15:44:24 +05:30
jest.spyOn(FilteredSearchTokenizer, 'processTokens').mockReturnValue({
2017-08-17 22:00:37 +05:30
lastToken: '"johnny appleseed',
});
expect(dropdownUser.getSearchInput()).toBe('johnny appleseed');
});
it('should not return the single quote found in value', () => {
2020-03-13 15:44:24 +05:30
jest.spyOn(FilteredSearchTokenizer, 'processTokens').mockReturnValue({
2018-12-13 13:39:08 +05:30
lastToken: "'larry boy",
2017-08-17 22:00:37 +05:30
});
expect(dropdownUser.getSearchInput()).toBe('larry boy');
});
});
2018-12-13 13:39:08 +05:30
describe("config AjaxFilter's endpoint", () => {
2017-08-17 22:00:37 +05:30
beforeEach(() => {
2020-03-13 15:44:24 +05:30
jest.spyOn(DropdownUser.prototype, 'bindEvents').mockImplementation(() => {});
jest.spyOn(DropdownUser.prototype, 'getProjectId').mockImplementation(() => {});
jest.spyOn(DropdownUser.prototype, 'getGroupId').mockImplementation(() => {});
2017-08-17 22:00:37 +05:30
});
it('should return endpoint', () => {
window.gon = {
relative_url_root: '',
};
2018-03-27 19:54:05 +05:30
const dropdown = new DropdownUser();
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
expect(dropdown.config.AjaxFilter.endpoint).toBe('/-/autocomplete/users.json');
2017-08-17 22:00:37 +05:30
});
it('should return endpoint when relative_url_root is undefined', () => {
2018-03-27 19:54:05 +05:30
const dropdown = new DropdownUser();
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
expect(dropdown.config.AjaxFilter.endpoint).toBe('/-/autocomplete/users.json');
2017-08-17 22:00:37 +05:30
});
it('should return endpoint with relative url when available', () => {
window.gon = {
relative_url_root: '/gitlab_directory',
};
2018-03-27 19:54:05 +05:30
const dropdown = new DropdownUser();
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
expect(dropdown.config.AjaxFilter.endpoint).toBe(
'/gitlab_directory/-/autocomplete/users.json',
);
2017-08-17 22:00:37 +05:30
});
afterEach(() => {
window.gon = {};
});
});
2017-09-10 17:25:29 +05:30
describe('hideCurrentUser', () => {
2019-07-07 11:18:12 +05:30
const fixtureTemplate = 'issues/issue_list.html';
2017-09-10 17:25:29 +05:30
let dropdown;
let authorFilterDropdownElement;
beforeEach(() => {
loadFixtures(fixtureTemplate);
authorFilterDropdownElement = document.querySelector('#js-dropdown-author');
const dummyInput = document.createElement('div');
2018-03-27 19:54:05 +05:30
dropdown = new DropdownUser({
2017-09-10 17:25:29 +05:30
dropdown: authorFilterDropdownElement,
input: dummyInput,
});
});
2018-12-13 13:39:08 +05:30
const findCurrentUserElement = () =>
authorFilterDropdownElement.querySelector('.js-current-user');
2017-09-10 17:25:29 +05:30
it('hides the current user from dropdown', () => {
const currentUserElement = findCurrentUserElement();
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(currentUserElement).not.toBe(null);
dropdown.hideCurrentUser();
expect(currentUserElement.classList).toContain('hidden');
});
it('does nothing if no user is logged in', () => {
const currentUserElement = findCurrentUserElement();
currentUserElement.parentNode.removeChild(currentUserElement);
2018-12-13 13:39:08 +05:30
2017-09-10 17:25:29 +05:30
expect(findCurrentUserElement()).toBe(null);
dropdown.hideCurrentUser();
});
});
2017-08-17 22:00:37 +05:30
});