mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Update jest monorepo to v29 * update snapshots + wrap test in act * fix linting errors: jest.mocked now defaults to deep mocking Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { toDataFrame, FieldType } from '@grafana/data';
|
|
|
|
import { DummySearcher } from './dummy';
|
|
import { FrontendSearcher } from './frontend';
|
|
|
|
describe('FrontendSearcher', () => {
|
|
const upstream = new DummySearcher();
|
|
upstream.setExpectedSearchResult(
|
|
toDataFrame({
|
|
meta: {
|
|
custom: {
|
|
something: 8,
|
|
},
|
|
},
|
|
fields: [{ name: 'name', type: FieldType.string, values: ['foo cat', 'bar dog', 'cow baz'] }],
|
|
})
|
|
);
|
|
|
|
it('should call search api with correct query for general folder', async () => {
|
|
const frontendSearcher = new FrontendSearcher(upstream);
|
|
const query = {
|
|
query: '*',
|
|
kind: ['dashboard'],
|
|
location: 'General',
|
|
};
|
|
const results = await frontendSearcher.search(query);
|
|
|
|
expect(results.view.fields.name.values.toArray()).toMatchInlineSnapshot(`
|
|
[
|
|
"foo cat",
|
|
"bar dog",
|
|
"cow baz",
|
|
]
|
|
`);
|
|
});
|
|
|
|
it('should return correct results for single prefix', async () => {
|
|
const frontendSearcher = new FrontendSearcher(upstream);
|
|
const query = {
|
|
query: 'ba',
|
|
kind: ['dashboard'],
|
|
location: 'General',
|
|
};
|
|
const results = await frontendSearcher.search(query);
|
|
|
|
expect(results.view.fields.name.values.toArray()).toMatchInlineSnapshot(`
|
|
[
|
|
"bar dog",
|
|
"cow baz",
|
|
]
|
|
`);
|
|
});
|
|
|
|
it('should return correct results out-of-order prefixes', async () => {
|
|
const frontendSearcher = new FrontendSearcher(upstream);
|
|
const query = {
|
|
query: 'do ba',
|
|
kind: ['dashboard'],
|
|
location: 'General',
|
|
};
|
|
const results = await frontendSearcher.search(query);
|
|
|
|
expect(results.view.fields.name.values.toArray()).toMatchInlineSnapshot(`
|
|
[
|
|
"bar dog",
|
|
]
|
|
`);
|
|
});
|
|
|
|
it('should barf when attempting a custom sort strategy', async () => {
|
|
const frontendSearcher = new FrontendSearcher(upstream);
|
|
const query = {
|
|
query: 'ba',
|
|
kind: ['dashboard'],
|
|
location: 'General',
|
|
sort: 'name_sort',
|
|
};
|
|
|
|
await expect(frontendSearcher.search(query)).rejects.toThrow('custom sorting is not supported yet');
|
|
});
|
|
});
|