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', () => {
|
|
|
|
describe('get', () => {
|
|
|
|
let tokenKeys;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-02-04 19:25:52 +00:00
|
|
|
tokenKeys = FilteredSearchTokenKeys.get();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKeys', () => {
|
|
|
|
expect(tokenKeys !== null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKeys as an array', () => {
|
|
|
|
expect(tokenKeys instanceof Array).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-22 10:37:02 +00:00
|
|
|
describe('getKeys', () => {
|
|
|
|
it('should return keys', () => {
|
|
|
|
const getKeys = FilteredSearchTokenKeys.getKeys();
|
|
|
|
const keys = FilteredSearchTokenKeys.get().map(i => i.key);
|
|
|
|
|
|
|
|
keys.forEach((key, i) => {
|
|
|
|
expect(key).toEqual(getKeys[i]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-17 07:01:11 +00:00
|
|
|
describe('getConditions', () => {
|
|
|
|
let conditions;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-02-04 19:25:52 +00:00
|
|
|
conditions = FilteredSearchTokenKeys.getConditions();
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return conditions', () => {
|
|
|
|
expect(conditions !== null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return conditions as an array', () => {
|
|
|
|
expect(conditions instanceof Array).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchByKey', () => {
|
|
|
|
it('should return null when key not found', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKey = FilteredSearchTokenKeys.searchByKey('notakey');
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(tokenKey === null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by key', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKeys = FilteredSearchTokenKeys.get();
|
|
|
|
const result = FilteredSearchTokenKeys.searchByKey(tokenKeys[0].key);
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchBySymbol', () => {
|
|
|
|
it('should return null when symbol not found', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKey = FilteredSearchTokenKeys.searchBySymbol('notasymbol');
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(tokenKey === null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by symbol', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKeys = FilteredSearchTokenKeys.get();
|
|
|
|
const result = FilteredSearchTokenKeys.searchBySymbol(tokenKeys[0].symbol);
|
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-02-04 19:25:52 +00:00
|
|
|
const tokenKey = FilteredSearchTokenKeys.searchByKeyParam('notakeyparam');
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(tokenKey === null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return tokenKey when found by key param', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKeys = FilteredSearchTokenKeys.get();
|
|
|
|
const result = FilteredSearchTokenKeys.searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`);
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(result).toEqual(tokenKeys[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return alternative tokenKey when found by key param', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const tokenKeys = FilteredSearchTokenKeys.getAlternatives();
|
|
|
|
const result = FilteredSearchTokenKeys.searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`);
|
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-02-04 19:25:52 +00:00
|
|
|
const condition = FilteredSearchTokenKeys.searchByConditionUrl(null);
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(condition === null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return condition when found by url', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const conditions = FilteredSearchTokenKeys.getConditions();
|
|
|
|
const result = FilteredSearchTokenKeys.searchByConditionUrl(conditions[0].url);
|
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-02-04 19:25:52 +00:00
|
|
|
const condition = FilteredSearchTokenKeys.searchByConditionKeyValue(null, null);
|
2017-04-17 07:01:11 +00:00
|
|
|
expect(condition === null).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return condition when found by tokenKey and value', () => {
|
2018-02-04 19:25:52 +00:00
|
|
|
const conditions = FilteredSearchTokenKeys.getConditions();
|
|
|
|
const result = FilteredSearchTokenKeys
|
2017-04-17 07:01:11 +00:00
|
|
|
.searchByConditionKeyValue(conditions[0].tokenKey, conditions[0].value);
|
|
|
|
expect(result).toEqual(conditions[0]);
|
2016-12-15 18:54:24 +00:00
|
|
|
});
|
|
|
|
});
|
2017-04-17 07:01:11 +00:00
|
|
|
});
|