2020-06-23 00:09:42 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-03-08 18:12:59 +05:30
|
|
|
import FilteredSearchSpecHelper from 'helpers/filtered_search_spec_helper';
|
2022-04-04 11:22:00 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2018-03-27 19:54:05 +05:30
|
|
|
import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe('Filtered Search Visual Tokens', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
let mock;
|
2018-03-27 19:54:05 +05:30
|
|
|
const subject = FilteredSearchVisualTokens;
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const findElements = (tokenElement) => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const tokenNameElement = tokenElement.querySelector('.name');
|
2020-03-13 15:44:24 +05:30
|
|
|
const tokenOperatorElement = tokenElement.querySelector('.operator');
|
2017-09-10 17:25:29 +05:30
|
|
|
const tokenValueContainer = tokenElement.querySelector('.value-container');
|
|
|
|
const tokenValueElement = tokenValueContainer.querySelector('.value');
|
2020-03-13 15:44:24 +05:30
|
|
|
return { tokenNameElement, tokenOperatorElement, tokenValueContainer, tokenValueElement };
|
2017-09-10 17:25:29 +05:30
|
|
|
};
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let tokensContainer;
|
2017-09-10 17:25:29 +05:30
|
|
|
let authorToken;
|
|
|
|
let bugLabelToken;
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
mock.onGet().reply(200);
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture(`
|
2017-08-17 22:00:37 +05:30
|
|
|
<ul class="tokens-container">
|
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
|
|
|
</ul>
|
|
|
|
`);
|
|
|
|
tokensContainer = document.querySelector('.tokens-container');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
authorToken = FilteredSearchSpecHelper.createFilterVisualToken('author', '=', '@user');
|
|
|
|
bugLabelToken = FilteredSearchSpecHelper.createFilterVisualToken('label', '=', '~bug');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('getLastVisualTokenBeforeInput', () => {
|
|
|
|
it('returns when there are no visual tokens', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(lastVisualToken).toEqual(null);
|
|
|
|
expect(isLastVisualTokenValid).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('input is the last item in tokensContainer', () => {
|
|
|
|
it('returns when there is one visual token', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2017-09-10 17:25:29 +05:30
|
|
|
bugLabelToken.outerHTML,
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token'));
|
|
|
|
expect(isLastVisualTokenValid).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns when there is an incomplete visual token', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('Author'),
|
|
|
|
);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token'));
|
|
|
|
expect(isLastVisualTokenValid).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns when there are multiple visual tokens', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search term')}
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
const items = document.querySelectorAll('.tokens-container .js-visual-token');
|
|
|
|
|
|
|
|
expect(lastVisualToken.isEqualNode(items[items.length - 1])).toEqual(true);
|
|
|
|
expect(isLastVisualTokenValid).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns when there are multiple visual tokens and an incomplete visual token', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search term')}
|
|
|
|
${FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('assignee')}
|
|
|
|
`);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
const items = document.querySelectorAll('.tokens-container .js-visual-token');
|
|
|
|
|
|
|
|
expect(lastVisualToken.isEqualNode(items[items.length - 1])).toEqual(true);
|
|
|
|
expect(isLastVisualTokenValid).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('input is a middle item in tokensContainer', () => {
|
|
|
|
it('returns last token before input', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token'));
|
|
|
|
expect(isLastVisualTokenValid).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns last partial token before input', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
|
|
|
${FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('label')}
|
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const { lastVisualToken, isLastVisualTokenValid } = subject.getLastVisualTokenBeforeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(lastVisualToken).toEqual(document.querySelector('.filtered-search-token'));
|
|
|
|
expect(isLastVisualTokenValid).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('getEndpointWithQueryParams', () => {
|
|
|
|
it('returns `endpoint` string as is when second param `endpointQueryParams` is undefined, null or empty string', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
const endpoint = 'foo/bar/-/labels.json';
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(subject.getEndpointWithQueryParams(endpoint)).toBe(endpoint);
|
|
|
|
expect(subject.getEndpointWithQueryParams(endpoint, null)).toBe(endpoint);
|
|
|
|
expect(subject.getEndpointWithQueryParams(endpoint, '')).toBe(endpoint);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns `endpoint` string with values of `endpointQueryParams`', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
const endpoint = 'foo/bar/-/labels.json';
|
2018-03-27 19:54:05 +05:30
|
|
|
const singleQueryParams = '{"foo":"true"}';
|
|
|
|
const multipleQueryParams = '{"foo":"true","bar":"true"}';
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(subject.getEndpointWithQueryParams(endpoint, singleQueryParams)).toBe(
|
|
|
|
`${endpoint}?foo=true`,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(subject.getEndpointWithQueryParams(endpoint, multipleQueryParams)).toBe(
|
|
|
|
`${endpoint}?foo=true&bar=true`,
|
|
|
|
);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('unselectTokens', () => {
|
|
|
|
it('does nothing when there are no tokens', () => {
|
|
|
|
const beforeHTML = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.unselectTokens();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.innerHTML).toEqual(beforeHTML);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the selected class from buttons', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@author')}
|
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', '%123', true)}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
|
|
|
const selected = tokensContainer.querySelector('.js-visual-token .selected');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(selected.classList.contains('selected')).toEqual(true);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.unselectTokens();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(selected.classList.contains('selected')).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('selectToken', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search term')}
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', '~awesome')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes the selected class if it has selected class', () => {
|
|
|
|
const firstTokenButton = tokensContainer.querySelector('.js-visual-token .selectable');
|
|
|
|
firstTokenButton.classList.add('selected');
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.selectToken(firstTokenButton);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(firstTokenButton.classList.contains('selected')).toEqual(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('has no selected class', () => {
|
|
|
|
it('adds selected class', () => {
|
|
|
|
const firstTokenButton = tokensContainer.querySelector('.js-visual-token .selectable');
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.selectToken(firstTokenButton);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(firstTokenButton.classList.contains('selected')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes selected class from other tokens', () => {
|
|
|
|
const tokenButtons = tokensContainer.querySelectorAll('.js-visual-token .selectable');
|
|
|
|
tokenButtons[1].classList.add('selected');
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.selectToken(tokenButtons[0]);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokenButtons[0].classList.contains('selected')).toEqual(true);
|
|
|
|
expect(tokenButtons[1].classList.contains('selected')).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeSelectedToken', () => {
|
|
|
|
it('does not remove when there are no selected tokens', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', 'none'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .selectable')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.removeSelectedToken();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .selectable')).not.toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes selected token', () => {
|
|
|
|
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
|
|
|
);
|
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .selectable')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.removeSelectedToken();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .selectable')).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createVisualTokenElementHTML', () => {
|
|
|
|
let tokenElement;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture(`
|
2017-08-17 22:00:37 +05:30
|
|
|
<div class="test-area">
|
2018-12-05 23:21:45 +05:30
|
|
|
${subject.createVisualTokenElementHTML('custom-token')}
|
2017-08-17 22:00:37 +05:30
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
tokenElement = document.querySelector('.test-area').firstElementChild;
|
|
|
|
});
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it('should add class name to token element', () => {
|
|
|
|
expect(document.querySelector('.test-area .custom-token')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it('contains name div', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(tokenElement.querySelector('.name')).toEqual(expect.anything());
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('contains value container div', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(tokenElement.querySelector('.value-container')).toEqual(expect.anything());
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('contains value div', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(tokenElement.querySelector('.value-container .value')).toEqual(expect.anything());
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('contains selectable class', () => {
|
|
|
|
expect(tokenElement.classList.contains('selectable')).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains button role', () => {
|
|
|
|
expect(tokenElement.getAttribute('role')).toEqual('button');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('remove token', () => {
|
|
|
|
it('contains remove-token button', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(tokenElement.querySelector('.value-container .remove-token')).toEqual(
|
2020-06-23 00:09:42 +05:30
|
|
|
expect.anything(),
|
2018-12-13 13:39:08 +05:30
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
it('contains close icon', () => {
|
|
|
|
expect(tokenElement.querySelector('.remove-token .close-icon')).toEqual(expect.anything());
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addVisualTokenElement', () => {
|
|
|
|
it('renders search visual tokens', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.addVisualTokenElement({
|
|
|
|
name: 'search term',
|
|
|
|
operator: '=',
|
|
|
|
value: null,
|
|
|
|
options: { isSearchTerm: true },
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(token.classList.contains('filtered-search-term')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('search term');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(token.querySelector('.operator').innerText).toEqual('=');
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders filter visual token name', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.addVisualTokenElement({ name: 'milestone' });
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(token.classList.contains('search-token-milestone')).toEqual(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('milestone');
|
|
|
|
expect(token.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it('renders filter visual token name, operator, and value', () => {
|
|
|
|
subject.addVisualTokenElement({ name: 'label', operator: '!=', value: 'Frontend' });
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(token.classList.contains('search-token-label')).toEqual(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('label');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(token.querySelector('.operator').innerText).toEqual('!=');
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value').innerText).toEqual('Frontend');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inserts visual token before input', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
tokensContainer.appendChild(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualToken('assignee', '=', '@root'),
|
2018-12-13 13:39:08 +05:30
|
|
|
);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.addVisualTokenElement({ name: 'label', operator: '!=', value: 'Frontend' });
|
2017-08-17 22:00:37 +05:30
|
|
|
const tokens = tokensContainer.querySelectorAll('.js-visual-token');
|
|
|
|
const labelToken = tokens[0];
|
|
|
|
const assigneeToken = tokens[1];
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(labelToken.classList.contains('search-token-label')).toEqual(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(labelToken.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(labelToken.querySelector('.name').innerText).toEqual('label');
|
|
|
|
expect(labelToken.querySelector('.value').innerText).toEqual('Frontend');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(labelToken.querySelector('.operator').innerText).toEqual('!=');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(assigneeToken.classList.contains('search-token-assignee')).toEqual(true);
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(assigneeToken.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(assigneeToken.querySelector('.name').innerText).toEqual('assignee');
|
|
|
|
expect(assigneeToken.querySelector('.value').innerText).toEqual('@root');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(assigneeToken.querySelector('.operator').innerText).toEqual('=');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addValueToPreviousVisualTokenElement', () => {
|
|
|
|
it('does not add when previous visual token element has no value', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const original = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addValueToPreviousVisualTokenElement('value');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(original).toEqual(tokensContainer.innerHTML);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add when previous visual token element is a search', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search term')}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const original = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addValueToPreviousVisualTokenElement('value');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(original).toEqual(tokensContainer.innerHTML);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds value to previous visual filter token', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createNameOperatorFilterVisualTokenHTML('label', '='),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const original = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addValueToPreviousVisualTokenElement('value');
|
2017-08-17 22:00:37 +05:30
|
|
|
const updatedToken = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(updatedToken.querySelector('.name').innerText).toEqual('label');
|
|
|
|
expect(updatedToken.querySelector('.value').innerText).toEqual('value');
|
|
|
|
expect(original).not.toEqual(tokensContainer.innerHTML);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addFilterVisualToken', () => {
|
|
|
|
it('creates visual token with just tokenName', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addFilterVisualToken('milestone');
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(token.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('milestone');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(token.querySelector('.operator')).toEqual(null);
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates visual token with just tokenValue', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.addFilterVisualToken('milestone', '=');
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addFilterVisualToken('%8.17');
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(token.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('milestone');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(token.querySelector('.operator').innerText).toEqual('=');
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value').innerText).toEqual('%8.17');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates full visual token', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
subject.addFilterVisualToken('assignee', '=', '@john');
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(token.classList.contains('filtered-search-token')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('assignee');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(token.querySelector('.operator').innerText).toEqual('=');
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value').innerText).toEqual('@john');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('addSearchVisualToken', () => {
|
|
|
|
it('creates search visual token', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addSearchVisualToken('search term');
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.js-visual-token');
|
|
|
|
|
|
|
|
expect(token.classList.contains('filtered-search-term')).toEqual(true);
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('search term');
|
|
|
|
expect(token.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('appends to previous search visual token if previous token was a search token', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('author', '=', '@root')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search term')}
|
|
|
|
`);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.addSearchVisualToken('append this');
|
2017-08-17 22:00:37 +05:30
|
|
|
const token = tokensContainer.querySelector('.filtered-search-term');
|
|
|
|
|
|
|
|
expect(token.querySelector('.name').innerText).toEqual('search term append this');
|
|
|
|
expect(token.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getLastTokenPartial', () => {
|
|
|
|
it('should get last token value', () => {
|
|
|
|
const value = '~bug';
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2017-09-10 17:25:29 +05:30
|
|
|
bugLabelToken.outerHTML,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(subject.getLastTokenPartial()).toEqual(value);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get last token original value if available', () => {
|
|
|
|
const originalValue = '@user';
|
|
|
|
const valueContainer = authorToken.querySelector('.value-container');
|
|
|
|
valueContainer.dataset.originalValue = originalValue;
|
|
|
|
const avatar = document.createElement('img');
|
|
|
|
const valueElement = valueContainer.querySelector('.value');
|
2020-06-23 00:09:42 +05:30
|
|
|
valueElement.appendChild(avatar);
|
2017-09-10 17:25:29 +05:30
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
authorToken.outerHTML,
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
const lastTokenValue = subject.getLastTokenPartial();
|
|
|
|
|
|
|
|
expect(lastTokenValue).toEqual(originalValue);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should get last token name if there is no value', () => {
|
|
|
|
const name = 'assignee';
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createNameFilterVisualTokenHTML(name),
|
|
|
|
);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.getLastTokenPartial()).toEqual(name);
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should return empty when there are no tokens', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.getLastTokenPartial()).toEqual('');
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeLastTokenPartial', () => {
|
|
|
|
it('should remove the last token value if it exists', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML(
|
|
|
|
'label',
|
|
|
|
'=',
|
|
|
|
'~"Community Contribution"',
|
|
|
|
),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .value')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.removeLastTokenPartial();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove the last token name if there is no value', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
|
|
|
FilteredSearchSpecHelper.createNameFilterVisualTokenHTML('milestone'),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .name')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.removeLastTokenPartial();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.js-visual-token .name')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not remove anything when there are no tokens', () => {
|
|
|
|
const html = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.removeLastTokenPartial();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.innerHTML).toEqual(html);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tokenizeInput', () => {
|
|
|
|
it('does not do anything if there is no input', () => {
|
|
|
|
const original = tokensContainer.innerHTML;
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.tokenizeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.innerHTML).toEqual(original);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds search visual token if previous visual token is valid', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('assignee', '=', 'none'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const input = document.querySelector('.filtered-search');
|
|
|
|
input.value = 'some value';
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.tokenizeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const newToken = tokensContainer.querySelector('.filtered-search-term');
|
|
|
|
|
|
|
|
expect(input.value).toEqual('');
|
|
|
|
expect(newToken.querySelector('.name').innerText).toEqual('some value');
|
|
|
|
expect(newToken.querySelector('.value')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds value to previous visual token element if previous visual token is invalid', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createNameOperatorFilterVisualTokenHTML('assignee', '='),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
const input = document.querySelector('.filtered-search');
|
|
|
|
input.value = '@john';
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.tokenizeInput();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const updatedToken = tokensContainer.querySelector('.filtered-search-token');
|
|
|
|
|
|
|
|
expect(input.value).toEqual('');
|
|
|
|
expect(updatedToken.querySelector('.name').innerText).toEqual('assignee');
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(updatedToken.querySelector('.operator').innerText).toEqual('=');
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(updatedToken.querySelector('.value').innerText).toEqual('@john');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('editToken', () => {
|
|
|
|
let input;
|
|
|
|
let token;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', 'none')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createSearchVisualTokenHTML('search')}
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('milestone', '=', 'upcoming')}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
|
|
|
|
|
|
|
input = document.querySelector('.filtered-search');
|
|
|
|
token = document.querySelector('.js-visual-token');
|
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it("tokenize's existing input", () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
input.value = 'some text';
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(subject, 'tokenizeInput');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.editToken(token);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.tokenizeInput).toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(input.value).not.toEqual('some text');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('moves input to the token position', () => {
|
|
|
|
expect(tokensContainer.children[3].querySelector('.filtered-search')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.editToken(token);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.children[1].querySelector('.filtered-search')).not.toEqual(null);
|
|
|
|
expect(tokensContainer.children[3].querySelector('.filtered-search')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('input contains the visual token value', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.editToken(token);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(input.value).toEqual('none');
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it('input contains the original value if present', () => {
|
|
|
|
const originalValue = '@user';
|
|
|
|
const valueContainer = token.querySelector('.value-container');
|
|
|
|
valueContainer.dataset.originalValue = originalValue;
|
|
|
|
|
|
|
|
subject.editToken(token);
|
|
|
|
|
|
|
|
expect(input.value).toEqual(originalValue);
|
|
|
|
});
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe('selected token is a search term token', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
token = document.querySelector('.filtered-search-term');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('token is removed', () => {
|
|
|
|
expect(tokensContainer.querySelector('.filtered-search-term')).not.toEqual(null);
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.editToken(token);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.querySelector('.filtered-search-term')).toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('input has the same value as removed token', () => {
|
|
|
|
expect(input.value).toEqual('');
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.editToken(token);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(input.value).toEqual('search');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('moveInputTotheRight', () => {
|
|
|
|
it('does nothing if the input is already the right most element', () => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(
|
2020-03-13 15:44:24 +05:30
|
|
|
FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', 'none'),
|
2017-08-17 22:00:37 +05:30
|
|
|
);
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(subject, 'tokenizeInput').mockImplementation(() => {});
|
|
|
|
jest.spyOn(subject, 'getLastVisualTokenBeforeInput');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.moveInputToTheRight();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(subject.tokenizeInput).toHaveBeenCalled();
|
|
|
|
expect(subject.getLastVisualTokenBeforeInput).not.toHaveBeenCalled();
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it("tokenize's input", () => {
|
2017-08-17 22:00:37 +05:30
|
|
|
tokensContainer.innerHTML = `
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createNameOperatorFilterVisualTokenHTML('label', '=')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
`;
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
tokensContainer.querySelector('.filtered-search').value = 'none';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.moveInputToTheRight();
|
2017-08-17 22:00:37 +05:30
|
|
|
const value = tokensContainer.querySelector('.js-visual-token .value');
|
|
|
|
|
|
|
|
expect(value.innerText).toEqual('none');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts input into search term token if last token is valid', () => {
|
|
|
|
tokensContainer.innerHTML = `
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', 'none')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
`;
|
|
|
|
|
|
|
|
document.querySelector('.filtered-search').value = 'test';
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.moveInputToTheRight();
|
2017-08-17 22:00:37 +05:30
|
|
|
const searchValue = tokensContainer.querySelector('.filtered-search-term .name');
|
|
|
|
|
|
|
|
expect(searchValue.innerText).toEqual('test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('moves the input to the right most element', () => {
|
|
|
|
tokensContainer.innerHTML = `
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', 'none')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createInputHTML()}
|
2017-09-10 17:25:29 +05:30
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
`;
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.moveInputToTheRight();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(tokensContainer.children[2].querySelector('.filtered-search')).not.toEqual(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('tokenizes input even if input is the right most element', () => {
|
|
|
|
tokensContainer.innerHTML = `
|
2020-03-13 15:44:24 +05:30
|
|
|
${FilteredSearchSpecHelper.createFilterVisualTokenHTML('label', '=', 'none')}
|
|
|
|
${FilteredSearchSpecHelper.createNameOperatorFilterVisualTokenHTML('label')}
|
2017-08-17 22:00:37 +05:30
|
|
|
${FilteredSearchSpecHelper.createInputHTML('', '~bug')}
|
|
|
|
`;
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
subject.moveInputToTheRight();
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
const token = tokensContainer.children[1];
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(token.querySelector('.value').innerText).toEqual('~bug');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renderVisualTokenValue', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
tokensContainer.innerHTML = FilteredSearchSpecHelper.createTokensContainerHTML(`
|
2017-09-10 17:25:29 +05:30
|
|
|
${authorToken.outerHTML}
|
|
|
|
${bugLabelToken.outerHTML}
|
2017-08-17 22:00:37 +05:30
|
|
|
`);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders a author token value element', async () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const { tokenNameElement, tokenValueElement } = findElements(authorToken);
|
2020-06-23 00:09:42 +05:30
|
|
|
const tokenName = tokenNameElement.textContent;
|
2017-09-10 17:25:29 +05:30
|
|
|
const tokenValue = 'new value';
|
|
|
|
|
|
|
|
subject.renderVisualTokenValue(authorToken, tokenName, tokenValue);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await waitForPromises();
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(tokenValueElement.textContent).toBe(tokenValue);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|