Skip to content

Commit a52c36b

Browse files
committed
[Discover] add locator test
1 parent 4481b90 commit a52c36b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/plugins/discover/public/locator.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { mockStorage } from '@kbn/kibana-utils-plugin/public/storage/hashed_item
1111
import { FilterStateStore } from '@kbn/es-query';
1212
import { DiscoverAppLocatorDefinition } from './locator';
1313
import { SerializableRecord } from '@kbn/utility-types';
14+
import { DiscoverStart, DiscoverStartPlugins } from './plugin';
15+
import { CoreSetup } from '@kbn/core/public';
16+
import { DataViewSpec } from '@kbn/data-views-plugin/public';
1417

1518
const dataViewId: string = 'c367b774-a4c2-11ea-bb37-0242ac130002';
1619
const savedSearchId: string = '571aaf70-4c88-11e8-b3d7-01146121b73d';
@@ -19,9 +22,18 @@ interface SetupParams {
1922
useHash?: boolean;
2023
}
2124

25+
const dataViewSpecMock = { id: 'mock-id' } as DataViewSpec;
26+
27+
const dataViewsMock = { create: jest.fn(() => dataViewSpecMock) };
28+
29+
const corePluginMock = {
30+
getStartServices: jest.fn(() => [{}, { data: { dataViews: dataViewsMock } }]),
31+
} as unknown as CoreSetup<DiscoverStartPlugins, DiscoverStart>;
32+
2233
const setup = async ({ useHash = false }: SetupParams = {}) => {
2334
const locator = new DiscoverAppLocatorDefinition({
2435
useHash,
36+
core: corePluginMock,
2537
});
2638

2739
return {
@@ -66,6 +78,17 @@ describe('Discover url generator', () => {
6678
expect(_g).toEqual({});
6779
});
6880

81+
test('can specify dataViewSpec', async () => {
82+
const { locator } = await setup();
83+
const { path } = await locator.getLocation({ dataViewSpec: dataViewSpecMock });
84+
const { _a, _g } = getStatesFromKbnUrl(path, ['_a', '_g']);
85+
86+
expect(_a).toEqual({
87+
index: dataViewSpecMock.id,
88+
});
89+
expect(_g).toEqual({});
90+
});
91+
6992
test('can specify specific time range', async () => {
7093
const { locator } = await setup();
7194
const { path } = await locator.getLocation({

0 commit comments

Comments
 (0)