Files
Josh Hunt 52c4761218 Fix: Fix dashboards not showing in folders with search v2 enabled (#69638)
* Fix: Fix dashboards not showing in folders with search v2 enabled

* tests
2023-06-06 16:26:06 +00:00

50 lines
1.7 KiB
TypeScript

import { DataFrame, DataFrameView, FieldType } from '@grafana/data';
import { DashboardQueryResult, getGrafanaSearcher, QueryResponse } from 'app/features/search/service';
import { listDashboards } from './services';
describe('browse-dashboards services', () => {
describe('listDashboards', () => {
const searchData: DataFrame = {
fields: [
{ name: 'kind', type: FieldType.string, config: {}, values: [] },
{ name: 'name', type: FieldType.string, config: {}, values: [] },
{ name: 'uid', type: FieldType.string, config: {}, values: [] },
{ name: 'url', type: FieldType.string, config: {}, values: [] },
{ name: 'tags', type: FieldType.other, config: {}, values: [] },
{ name: 'location', type: FieldType.string, config: {}, values: [] },
],
length: 0,
};
const mockSearchResult: QueryResponse = {
isItemLoaded: jest.fn(),
loadMoreItems: jest.fn(),
totalRows: searchData.length,
view: new DataFrameView<DashboardQueryResult>(searchData),
};
const searchMock = jest.spyOn(getGrafanaSearcher(), 'search');
searchMock.mockResolvedValue(mockSearchResult);
const PAGE_SIZE = 50;
it.each([
{ page: undefined, expectedFrom: 0 },
{ page: 1, expectedFrom: 0 },
{ page: 2, expectedFrom: 50 },
{ page: 4, expectedFrom: 150 },
])('skips first $expectedFrom when listing page $page', async ({ page, expectedFrom }) => {
await listDashboards('abc-123', page, PAGE_SIZE);
expect(searchMock).toHaveBeenCalledWith({
kind: ['dashboard'],
query: '*',
location: 'abc-123',
from: expectedFrom,
limit: PAGE_SIZE,
});
});
});
});