2022-07-16 23:28:13 +05:30
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2018-03-27 19:54:05 +05:30
|
|
|
import DropdownUser from '~/filtered_search/dropdown_user';
|
2021-11-18 22:05:49 +05:30
|
|
|
import DropdownUtils from '~/filtered_search/dropdown_utils';
|
2018-03-27 19:54:05 +05:30
|
|
|
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', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
const fixtureTemplate = 'merge_requests/merge_request_list.html';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
let dropdown;
|
|
|
|
let authorFilterDropdownElement;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
loadHTMLFixture(fixtureTemplate);
|
2017-09-10 17:25:29 +05:30
|
|
|
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,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|