2018-02-21 20:22:56 +00:00
|
|
|
import DropdownUser from '~/filtered_search/dropdown_user';
|
2021-09-28 12:11:10 +00:00
|
|
|
import DropdownUtils from '~/filtered_search/dropdown_utils';
|
2018-02-21 20:22:56 +00:00
|
|
|
import FilteredSearchTokenizer from '~/filtered_search/filtered_search_tokenizer';
|
2018-08-29 12:14:54 +00:00
|
|
|
import IssuableFilteredTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
|
2018-02-04 19:25:52 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
describe('Dropdown User', () => {
|
|
|
|
describe('getSearchInput', () => {
|
|
|
|
let dropdownUser;
|
2017-01-27 19:22:12 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
beforeEach(() => {
|
2019-12-20 15:07:34 +00:00
|
|
|
jest.spyOn(DropdownUser.prototype, 'bindEvents').mockImplementation(() => {});
|
|
|
|
jest.spyOn(DropdownUser.prototype, 'getProjectId').mockImplementation(() => {});
|
|
|
|
jest.spyOn(DropdownUser.prototype, 'getGroupId').mockImplementation(() => {});
|
|
|
|
jest.spyOn(DropdownUtils, 'getSearchInput').mockImplementation(() => {});
|
2017-01-27 19:22:12 +00:00
|
|
|
|
2018-02-21 20:22:56 +00:00
|
|
|
dropdownUser = new DropdownUser({
|
2018-08-29 12:14:54 +00:00
|
|
|
tokenKeys: IssuableFilteredTokenKeys,
|
2017-07-20 19:17:34 +00:00
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-27 19:22:12 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should not return the double quote found in value', () => {
|
2019-12-20 15:07:34 +00:00
|
|
|
jest.spyOn(FilteredSearchTokenizer, 'processTokens').mockReturnValue({
|
2017-04-17 07:01:11 +00:00
|
|
|
lastToken: '"johnny appleseed',
|
2017-01-27 19:22:12 +00:00
|
|
|
});
|
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(dropdownUser.getSearchInput()).toBe('johnny appleseed');
|
|
|
|
});
|
2017-01-27 19:22:12 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should not return the single quote found in value', () => {
|
2019-12-20 15:07:34 +00:00
|
|
|
jest.spyOn(FilteredSearchTokenizer, 'processTokens').mockReturnValue({
|
2018-10-17 07:13:26 +00:00
|
|
|
lastToken: "'larry boy",
|
2017-01-27 19:22:12 +00:00
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
|
|
|
|
expect(dropdownUser.getSearchInput()).toBe('larry boy');
|
2017-01-27 19:22:12 +00:00
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
describe("config AjaxFilter's endpoint", () => {
|
2017-04-17 07:01:11 +00:00
|
|
|
beforeEach(() => {
|
2019-12-20 15:07:34 +00:00
|
|
|
jest.spyOn(DropdownUser.prototype, 'bindEvents').mockImplementation(() => {});
|
|
|
|
jest.spyOn(DropdownUser.prototype, 'getProjectId').mockImplementation(() => {});
|
|
|
|
jest.spyOn(DropdownUser.prototype, 'getGroupId').mockImplementation(() => {});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should return endpoint', () => {
|
|
|
|
window.gon = {
|
|
|
|
relative_url_root: '',
|
|
|
|
};
|
2018-02-21 20:22:56 +00:00
|
|
|
const dropdown = new DropdownUser();
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2020-06-18 15:08:45 +00:00
|
|
|
expect(dropdown.config.AjaxFilter.endpoint).toBe('/-/autocomplete/users.json');
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should return endpoint when relative_url_root is undefined', () => {
|
2018-02-21 20:22:56 +00:00
|
|
|
const dropdown = new DropdownUser();
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2020-06-18 15:08:45 +00:00
|
|
|
expect(dropdown.config.AjaxFilter.endpoint).toBe('/-/autocomplete/users.json');
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should return endpoint with relative url when available', () => {
|
|
|
|
window.gon = {
|
|
|
|
relative_url_root: '/gitlab_directory',
|
|
|
|
};
|
2018-02-21 20:22:56 +00:00
|
|
|
const dropdown = new DropdownUser();
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2020-06-18 15:08:45 +00:00
|
|
|
expect(dropdown.config.AjaxFilter.endpoint).toBe(
|
|
|
|
'/gitlab_directory/-/autocomplete/users.json',
|
|
|
|
);
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
2017-01-30 21:02:19 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
afterEach(() => {
|
|
|
|
window.gon = {};
|
2017-01-30 21:02:19 +00:00
|
|
|
});
|
2017-01-27 19:22:12 +00:00
|
|
|
});
|
2017-06-27 08:47:58 +00:00
|
|
|
|
|
|
|
describe('hideCurrentUser', () => {
|
2019-03-26 16:03:28 +00:00
|
|
|
const fixtureTemplate = 'issues/issue_list.html';
|
2017-06-27 08:47:58 +00:00
|
|
|
|
|
|
|
let dropdown;
|
|
|
|
let authorFilterDropdownElement;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixtureTemplate);
|
|
|
|
authorFilterDropdownElement = document.querySelector('#js-dropdown-author');
|
|
|
|
const dummyInput = document.createElement('div');
|
2018-02-21 20:22:56 +00:00
|
|
|
dropdown = new DropdownUser({
|
2017-07-20 19:17:34 +00:00
|
|
|
dropdown: authorFilterDropdownElement,
|
|
|
|
input: dummyInput,
|
|
|
|
});
|
2017-06-27 08:47:58 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
const findCurrentUserElement = () =>
|
|
|
|
authorFilterDropdownElement.querySelector('.js-current-user');
|
2017-06-27 08:47:58 +00:00
|
|
|
|
|
|
|
it('hides the current user from dropdown', () => {
|
|
|
|
const currentUserElement = findCurrentUserElement();
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-06-27 08:47:58 +00:00
|
|
|
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-10-09 18:03:09 +00:00
|
|
|
|
2017-06-27 08:47:58 +00:00
|
|
|
expect(findCurrentUserElement()).toBe(null);
|
|
|
|
|
|
|
|
dropdown.hideCurrentUser();
|
|
|
|
});
|
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|