mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { SearchQueryParams } from './types';
|
|
import { parseRouteParams } from './utils';
|
|
|
|
describe('Search utils', () => {
|
|
describe('parseRouteParams', () => {
|
|
it('should remove all undefined keys', () => {
|
|
const params: Partial<SearchQueryParams> = { sort: undefined, tag: undefined, query: 'test' };
|
|
|
|
expect(parseRouteParams(params)).toEqual({
|
|
query: 'test',
|
|
});
|
|
});
|
|
|
|
it('should return tag as array, if present', () => {
|
|
//@ts-ignore
|
|
const params = { sort: undefined, tag: 'test', query: 'test' };
|
|
expect(parseRouteParams(params)).toEqual({
|
|
query: 'test',
|
|
tag: ['test'],
|
|
});
|
|
|
|
const params2: Partial<SearchQueryParams> = { sort: undefined, tag: ['test'], query: 'test' };
|
|
expect(parseRouteParams(params2)).toEqual({
|
|
query: 'test',
|
|
tag: ['test'],
|
|
});
|
|
});
|
|
|
|
it('should return sort as a SelectableValue', () => {
|
|
const params: Partial<SearchQueryParams> = { sort: 'test' };
|
|
|
|
expect(parseRouteParams(params)).toEqual({
|
|
sort: { value: 'test' },
|
|
});
|
|
});
|
|
|
|
it('should prepend folder:{folder} to the query if folder is present', () => {
|
|
expect(parseRouteParams({ folder: 'current' })).toEqual({
|
|
folder: 'current',
|
|
query: 'folder:current ',
|
|
});
|
|
// Prepend to exiting query
|
|
const params: Partial<SearchQueryParams> = { query: 'test', folder: 'current' };
|
|
expect(parseRouteParams(params)).toEqual({
|
|
folder: 'current',
|
|
query: 'folder:current test',
|
|
});
|
|
});
|
|
});
|
|
});
|