2018-02-04 19:25:52 +00:00
|
|
|
import FilteredSearchTokenKeys from '~/filtered_search/filtered_search_token_keys';
|
2016-12-15 18:54:24 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
describe('Filtered Search Token Keys', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const tokenKeys = [
|
|
|
|
{
|
|
|
|
key: 'author',
|
|
|
|
type: 'string',
|
|
|
|
param: 'username',
|
|
|
|
symbol: '@',
|
|
|
|
icon: 'pencil',
|
|
|
|
tag: '@author',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const conditions = [
|
|
|
|
{
|
|
|
|
url: 'assignee_id=0',
|
|
|
|
tokenKey: 'assignee',
|
|
|
|
value: 'none',
|
|
|
|
},
|
|
|
|
];
|
2017-04-17 07:01:11 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
describe('get', () => {
|
2017-04-17 07:01:11 +00:00
|
|
|
it('should return tokenKeys', () => {
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(new FilteredSearchTokenKeys().get()).not.toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKeys as an array', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
expect(new FilteredSearchTokenKeys().get() instanceof Array).toBe(true);
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-22 10:37:02 +00:00
|
|
|
describe('getKeys', () => {
|
|
|
|
it('should return keys', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const getKeys = new FilteredSearchTokenKeys(tokenKeys).getKeys();
|
|
|
|
const keys = new FilteredSearchTokenKeys(tokenKeys).get().map(i => i.key);
|
2018-06-22 10:37:02 +00:00
|
|
|
|
|
|
|
keys.forEach((key, i) => {
|
|
|
|
expect(key).toEqual(getKeys[i]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
describe('getConditions', () => {
|
|
|
|
it('should return conditions', () => {
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(new FilteredSearchTokenKeys().getConditions()).not.toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return conditions as an array', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
expect(new FilteredSearchTokenKeys().getConditions() instanceof Array).toBe(true);
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchByKey', () => {
|
|
|
|
it('should return null when key not found', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKey('notakey');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(tokenKey).toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by key', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKey(tokenKeys[0].key);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchBySymbol', () => {
|
|
|
|
it('should return null when symbol not found', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol('notasymbol');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(tokenKey).toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by symbol', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const result = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol(tokenKeys[0].symbol);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchByKeyParam', () => {
|
|
|
|
it('should return null when key param not found', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam('notakeyparam');
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(tokenKey).toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by key param', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(
|
|
|
|
`${tokenKeys[0].key}_${tokenKeys[0].param}`,
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return alternative tokenKey when found by key param', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(
|
|
|
|
`${tokenKeys[0].key}_${tokenKeys[0].param}`,
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchByConditionUrl', () => {
|
|
|
|
it('should return null when condition url not found', () => {
|
2018-06-26 14:21:38 +00:00
|
|
|
const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl(null);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(condition).toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return condition when found by url', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const result = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl(
|
|
|
|
conditions[0].url,
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toBe(conditions[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchByConditionKeyValue', () => {
|
|
|
|
it('should return null when condition tokenKey and value not found', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionKeyValue(
|
|
|
|
null,
|
|
|
|
null,
|
2020-01-02 13:03:23 +00:00
|
|
|
null,
|
2018-10-17 07:13:26 +00:00
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-10-09 18:30:03 +00:00
|
|
|
expect(condition).toBeNull();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return condition when found by tokenKey and value', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
const result = new FilteredSearchTokenKeys([], [], conditions).searchByConditionKeyValue(
|
|
|
|
conditions[0].tokenKey,
|
2020-01-02 13:03:23 +00:00
|
|
|
conditions[0].operator,
|
2018-10-17 07:13:26 +00:00
|
|
|
conditions[0].value,
|
|
|
|
);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(conditions[0]);
|
2016-12-15 18:54:24 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|