2021-01-29 00:20:46 +05:30
|
|
|
import FilteredSearchManager from 'ee_else_ce/filtered_search/filtered_search_manager';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
import FilteredSearchSpecHelper from 'helpers/filtered_search_spec_helper';
|
2018-03-27 19:54:05 +05:30
|
|
|
import DropdownUtils from '~/filtered_search/dropdown_utils';
|
|
|
|
import FilteredSearchDropdownManager from '~/filtered_search/filtered_search_dropdown_manager';
|
2021-03-11 19:13:27 +05:30
|
|
|
import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens';
|
|
|
|
import IssuableFilteredSearchTokenKeys from '~/filtered_search/issuable_filtered_search_token_keys';
|
|
|
|
import RecentSearchesRoot from '~/filtered_search/recent_searches_root';
|
|
|
|
import RecentSearchesService from '~/filtered_search/services/recent_searches_service';
|
|
|
|
import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error';
|
2021-09-30 23:02:18 +05:30
|
|
|
import createFlash from '~/flash';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { BACKSPACE_KEY_CODE, DELETE_KEY_CODE } from '~/lib/utils/keycodes';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { visitUrl, getParameterByName } from '~/lib/utils/url_utility';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
jest.mock('~/flash');
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.mock('~/lib/utils/url_utility', () => ({
|
|
|
|
...jest.requireActual('~/lib/utils/url_utility'),
|
2021-09-30 23:02:18 +05:30
|
|
|
getParameterByName: jest.fn(),
|
2020-05-24 23:13:21 +05:30
|
|
|
visitUrl: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('Filtered Search Manager', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
let input;
|
|
|
|
let manager;
|
|
|
|
let tokensContainer;
|
2018-03-17 18:26:18 +05:30
|
|
|
const page = 'issues';
|
2017-08-17 22:00:37 +05:30
|
|
|
const placeholder = 'Search or filter results...';
|
|
|
|
|
|
|
|
function dispatchBackspaceEvent(element, eventType) {
|
|
|
|
const event = new Event(eventType);
|
2020-04-22 19:07:51 +05:30
|
|
|
event.keyCode = BACKSPACE_KEY_CODE;
|
2017-08-17 22:00:37 +05:30
|
|
|
element.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchDeleteEvent(element, eventType) {
|
|
|
|
const event = new Event(eventType);
|
2020-04-22 19:07:51 +05:30
|
|
|
event.keyCode = DELETE_KEY_CODE;
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchAltBackspaceEvent(element, eventType) {
|
|
|
|
const event = new Event(eventType);
|
|
|
|
event.altKey = true;
|
|
|
|
event.keyCode = BACKSPACE_KEY_CODE;
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchCtrlBackspaceEvent(element, eventType) {
|
|
|
|
const event = new Event(eventType);
|
|
|
|
event.ctrlKey = true;
|
|
|
|
event.keyCode = BACKSPACE_KEY_CODE;
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchMetaBackspaceEvent(element, eventType) {
|
|
|
|
const event = new Event(eventType);
|
|
|
|
event.metaKey = true;
|
|
|
|
event.keyCode = BACKSPACE_KEY_CODE;
|
2017-08-17 22:00:37 +05:30
|
|
|
element.dispatchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVisualTokens() {
|
|
|
|
return tokensContainer.querySelectorAll('.js-visual-token');
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures(`
|
|
|
|
<div class="filtered-search-box">
|
|
|
|
<form>
|
|
|
|
<ul class="tokens-container list-unstyled">
|
|
|
|
${FilteredSearchSpecHelper.createInputHTML(placeholder)}
|
|
|
|
</ul>
|
|
|
|
<button class="clear-search" type="button">
|
2021-02-22 17:27:13 +05:30
|
|
|
<svg class="s16 clear-search-icon" data-testid="close-icon"><use xlink:href="icons.svg#close" /></svg>
|
2017-08-17 22:00:37 +05:30
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchDropdownManager.prototype, 'setDropdown').mockImplementation();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
const initializeManager = ({ useDefaultState } = {}) => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'loadSearchParamsFromURL').mockImplementation();
|
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'tokenChange').mockImplementation();
|
|
|
|
jest
|
|
|
|
.spyOn(FilteredSearchDropdownManager.prototype, 'updateDropdownOffset')
|
|
|
|
.mockImplementation();
|
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'unselectTokens');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
getParameterByName.mockReturnValue(null);
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
input = document.querySelector('.filtered-search');
|
|
|
|
tokensContainer = document.querySelector('.tokens-container');
|
2020-10-24 23:57:45 +05:30
|
|
|
manager = new FilteredSearchManager({ page, useDefaultState });
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.setup();
|
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
manager.cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('class constructor', () => {
|
|
|
|
const isLocalStorageAvailable = 'isLocalStorageAvailable';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(RecentSearchesService, 'isAvailable').mockReturnValue(isLocalStorageAvailable);
|
|
|
|
jest.spyOn(RecentSearchesRoot.prototype, 'render').mockImplementation();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should instantiate RecentSearchesStore with isLocalStorageAvailable', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
manager = new FilteredSearchManager({ page });
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(RecentSearchesService.isAvailable).toHaveBeenCalled();
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(manager.recentSearchesStore.state).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
isLocalStorageAvailable,
|
|
|
|
allowedKeys: IssuableFilteredSearchTokenKeys.getKeys(),
|
|
|
|
}),
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('setup', () => {
|
|
|
|
beforeEach(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
manager = new FilteredSearchManager({ page });
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
it('should not instantiate Flash if an RecentSearchesServiceError is caught', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest
|
|
|
|
.spyOn(RecentSearchesService.prototype, 'fetch')
|
|
|
|
.mockImplementation(() => Promise.reject(new RecentSearchesServiceError()));
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.setup();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(createFlash).not.toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('searchState', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'search').mockImplementation();
|
2017-09-10 17:25:29 +05:30
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should blur button', () => {
|
|
|
|
const e = {
|
|
|
|
preventDefault: () => {},
|
|
|
|
currentTarget: {
|
|
|
|
blur: () => {},
|
|
|
|
},
|
|
|
|
};
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(e.currentTarget, 'blur');
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.searchState(e);
|
|
|
|
|
|
|
|
expect(e.currentTarget.blur).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call search if there is no state', () => {
|
|
|
|
const e = {
|
|
|
|
preventDefault: () => {},
|
|
|
|
currentTarget: {
|
|
|
|
blur: () => {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
manager.searchState(e);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchManager.prototype.search).not.toHaveBeenCalled();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should call search when there is state', () => {
|
|
|
|
const e = {
|
|
|
|
preventDefault: () => {},
|
|
|
|
currentTarget: {
|
|
|
|
blur: () => {},
|
|
|
|
dataset: {
|
|
|
|
state: 'opened',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
manager.searchState(e);
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchManager.prototype.search).toHaveBeenCalledWith('opened');
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('search', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
const defaultParams = '?scope=all';
|
2020-10-24 23:57:45 +05:30
|
|
|
const defaultState = '&state=opened';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should search with a single word', (done) => {
|
2017-09-10 17:25:29 +05:30
|
|
|
initializeManager();
|
2020-10-24 23:57:45 +05:30
|
|
|
input.value = 'searchTerm';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(url).toEqual(`${defaultParams}&search=searchTerm`);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.search();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('sets default state', (done) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeManager({ useDefaultState: true });
|
2017-08-17 22:00:37 +05:30
|
|
|
input.value = 'searchTerm';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(url).toEqual(`${defaultParams}${defaultState}&search=searchTerm`);
|
2017-08-17 22:00:37 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.search();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should search with multiple words', (done) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
input.value = 'awesome search terms';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(url).toEqual(`${defaultParams}&search=awesome+search+terms`);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.search();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should search with special characters', (done) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
input.value = '~!@#$%^&*()_+{}:<>,.?/';
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(url).toEqual(
|
|
|
|
`${defaultParams}&search=~!%40%23%24%25%5E%26*()_%2B%7B%7D%3A%3C%3E%2C.%3F%2F`,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.search();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should use replacement URL for condition', (done) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeManager();
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', '13', true),
|
|
|
|
);
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(url).toEqual(`${defaultParams}&milestone_title=replaced`);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.filteredSearchTokenKeys.conditions.push({
|
|
|
|
url: 'milestone_title=13',
|
|
|
|
replacementUrl: 'milestone_title=replaced',
|
|
|
|
tokenKey: 'milestone',
|
|
|
|
value: '13',
|
|
|
|
operator: '=',
|
|
|
|
});
|
|
|
|
manager.search();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('removes duplicated tokens', (done) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug')}
|
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
visitUrl.mockImplementation((url) => {
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(url).toEqual(`${defaultParams}&label_name[]=bug`);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
manager.search();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('handleInputPlaceholder', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it('should render placeholder when there is no input', () => {
|
|
|
|
expect(input.placeholder).toEqual(placeholder);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render placeholder when there is input', () => {
|
|
|
|
input.value = 'test words';
|
|
|
|
|
|
|
|
const event = new Event('input');
|
|
|
|
input.dispatchEvent(event);
|
|
|
|
|
|
|
|
expect(input.placeholder).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render placeholder when there are tokens and no input', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const event = new Event('input');
|
|
|
|
input.dispatchEvent(event);
|
|
|
|
|
|
|
|
expect(input.placeholder).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkForBackspace', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('tokens and no input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes last token', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'removeLastTokenPartial');
|
2017-08-17 22:00:37 +05:30
|
|
|
dispatchBackspaceEvent(input, 'keyup');
|
2018-03-17 18:26:18 +05:30
|
|
|
dispatchBackspaceEvent(input, 'keyup');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('sets the input', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'getLastTokenPartial');
|
2017-08-17 22:00:37 +05:30
|
|
|
dispatchDeleteEvent(input, 'keyup');
|
2018-03-17 18:26:18 +05:30
|
|
|
dispatchDeleteEvent(input, 'keyup');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchVisualTokens.getLastTokenPartial).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(input.value).toEqual('~bug');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not remove token or change input when there is existing input', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'removeLastTokenPartial');
|
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'getLastTokenPartial');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
input.value = 'text';
|
|
|
|
dispatchDeleteEvent(input, 'keyup');
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).not.toHaveBeenCalled();
|
|
|
|
expect(FilteredSearchVisualTokens.getLastTokenPartial).not.toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(input.value).toEqual('text');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it('does not remove previous token on single backspace press', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'removeLastTokenPartial');
|
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'getLastTokenPartial');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
input.value = 't';
|
|
|
|
dispatchDeleteEvent(input, 'keyup');
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).not.toHaveBeenCalled();
|
|
|
|
expect(FilteredSearchVisualTokens.getLastTokenPartial).not.toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(input.value).toEqual('t');
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
describe('checkForAltOrCtrlBackspace', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'removeLastTokenPartial');
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('tokens and no input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug'),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes last token via alt-backspace', () => {
|
|
|
|
dispatchAltBackspaceEvent(input, 'keydown');
|
|
|
|
|
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes last token via ctrl-backspace', () => {
|
|
|
|
dispatchCtrlBackspaceEvent(input, 'keydown');
|
|
|
|
|
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tokens and input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug'),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not remove token or change input via alt-backspace when there is existing input', () => {
|
|
|
|
input = manager.filteredSearchInput;
|
|
|
|
input.value = 'text';
|
|
|
|
dispatchAltBackspaceEvent(input, 'keydown');
|
|
|
|
|
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).not.toHaveBeenCalled();
|
|
|
|
expect(input.value).toEqual('text');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not remove token or change input via ctrl-backspace when there is existing input', () => {
|
|
|
|
input = manager.filteredSearchInput;
|
|
|
|
input.value = 'text';
|
|
|
|
dispatchCtrlBackspaceEvent(input, 'keydown');
|
|
|
|
|
|
|
|
expect(FilteredSearchVisualTokens.removeLastTokenPartial).not.toHaveBeenCalled();
|
|
|
|
expect(input.value).toEqual('text');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkForMetaBackspace', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~bug'),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes all tokens and input', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'clearSearch');
|
2020-04-22 19:07:51 +05:30
|
|
|
dispatchMetaBackspaceEvent(input, 'keydown');
|
|
|
|
|
|
|
|
expect(manager.clearSearch).toHaveBeenCalled();
|
|
|
|
expect(manager.filteredSearchInput.value).toEqual('');
|
|
|
|
expect(DropdownUtils.getSearchQuery()).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('removeToken', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it('removes token even when it is already selected', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', 'none', true),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
tokensContainer.querySelector('.js-visual-token .remove-token').click();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(tokensContainer.querySelector('.js-visual-token')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('unselected token', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'removeSelectedToken');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', 'none'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
tokensContainer.querySelector('.js-visual-token .remove-token').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes token when remove button is selected', () => {
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls removeSelectedToken', () => {
|
|
|
|
expect(manager.removeSelectedToken).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeSelectedTokenKeydown', () => {
|
|
|
|
beforeEach(() => {
|
2017-09-10 17:25:29 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', 'none', true),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes selected token when the backspace key is pressed', () => {
|
|
|
|
expect(getVisualTokens().length).toEqual(1);
|
|
|
|
|
|
|
|
dispatchBackspaceEvent(document, 'keydown');
|
|
|
|
|
|
|
|
expect(getVisualTokens().length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes selected token when the delete key is pressed', () => {
|
|
|
|
expect(getVisualTokens().length).toEqual(1);
|
|
|
|
|
|
|
|
dispatchDeleteEvent(document, 'keydown');
|
|
|
|
|
|
|
|
expect(getVisualTokens().length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the input placeholder after removal', () => {
|
|
|
|
manager.handleInputPlaceholder();
|
|
|
|
|
|
|
|
expect(input.placeholder).toEqual('');
|
|
|
|
expect(getVisualTokens().length).toEqual(1);
|
|
|
|
|
|
|
|
dispatchBackspaceEvent(document, 'keydown');
|
|
|
|
|
|
|
|
expect(input.placeholder).not.toEqual('');
|
|
|
|
expect(getVisualTokens().length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the clear button after removal', () => {
|
|
|
|
manager.toggleClearSearchButton();
|
|
|
|
|
|
|
|
const clearButton = document.querySelector('.clear-search');
|
|
|
|
|
|
|
|
expect(clearButton.classList.contains('hidden')).toEqual(false);
|
|
|
|
expect(getVisualTokens().length).toEqual(1);
|
|
|
|
|
|
|
|
dispatchBackspaceEvent(document, 'keydown');
|
|
|
|
|
|
|
|
expect(clearButton.classList.contains('hidden')).toEqual(true);
|
|
|
|
expect(getVisualTokens().length).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeSelectedToken', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.spyOn(FilteredSearchVisualTokens, 'removeSelectedToken');
|
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'handleInputPlaceholder');
|
|
|
|
jest.spyOn(FilteredSearchManager.prototype, 'toggleClearSearchButton');
|
2017-09-10 17:25:29 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls FilteredSearchVisualTokens.removeSelectedToken', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.removeSelectedToken();
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(FilteredSearchVisualTokens.removeSelectedToken).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('calls handleInputPlaceholder', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.removeSelectedToken();
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(manager.handleInputPlaceholder).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls toggleClearSearchButton', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.removeSelectedToken();
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(manager.toggleClearSearchButton).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls update dropdown offset', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
manager.removeSelectedToken();
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(manager.dropdownManager.updateDropdownOffset).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('Clearing search', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Clicking the "x" clear button, clears the input', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
const inputValue = 'label:=~bug';
|
2018-03-17 18:26:18 +05:30
|
|
|
manager.filteredSearchInput.value = inputValue;
|
|
|
|
manager.filteredSearchInput.dispatchEvent(new Event('input'));
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(DropdownUtils.getSearchQuery()).toEqual(inputValue);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
manager.clearSearchButton.click();
|
|
|
|
|
|
|
|
expect(manager.filteredSearchInput.value).toEqual('');
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(DropdownUtils.getSearchQuery()).toEqual('');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('toggleInputContainerFocus', () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
beforeEach(() => {
|
2017-09-10 17:25:29 +05:30
|
|
|
initializeManager();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles on focus', () => {
|
|
|
|
input.focus();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(
|
|
|
|
true,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('toggles on blur', () => {
|
|
|
|
input.blur();
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(
|
|
|
|
false,
|
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe('getAllParams', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
let paramsArr;
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
paramsArr = ['key=value', 'otherkey=othervalue'];
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
initializeManager();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly modifies params when custom modifier is passed', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const modifedParams = manager.getAllParams.call(
|
|
|
|
{
|
2021-03-08 18:12:59 +05:30
|
|
|
modifyUrlParams: (params) => params.reverse(),
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
[].concat(paramsArr),
|
2018-12-13 13:39:08 +05:30
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(modifedParams[0]).toBe(paramsArr[1]);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not modify params when no custom modifier is passed', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
const modifedParams = manager.getAllParams.call({}, paramsArr);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(modifedParams[1]).toBe(paramsArr[1]);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|