kibana/x-pack/plugins/lens/public/editor_frame_service/service.test.tsx
Marco Liberati bd908c6ba3
[Lens] Integrate searchSessionId into Lens app (#86297)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2020-12-29 14:18:30 +01:00

89 lines
2.8 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { EditorFrameService } from './service';
import { coreMock } from 'src/core/public/mocks';
import {
MockedSetupDependencies,
MockedStartDependencies,
createMockSetupDependencies,
createMockStartDependencies,
} from './mocks';
import { CoreSetup } from 'kibana/public';
// mock away actual dependencies to prevent all of it being loaded
jest.mock('./embeddable/embeddable_factory', () => ({
EmbeddableFactory: class Mock {},
}));
describe('editor_frame service', () => {
let pluginInstance: EditorFrameService;
let mountpoint: Element;
let pluginSetupDependencies: MockedSetupDependencies;
let pluginStartDependencies: MockedStartDependencies;
beforeEach(() => {
pluginInstance = new EditorFrameService();
mountpoint = document.createElement('div');
pluginSetupDependencies = createMockSetupDependencies();
pluginStartDependencies = createMockStartDependencies();
});
afterEach(() => {
mountpoint.remove();
});
it('should create an editor frame instance which mounts and unmounts', async () => {
await expect(
(async () => {
pluginInstance.setup(
coreMock.createSetup() as CoreSetup<MockedStartDependencies>,
pluginSetupDependencies,
jest.fn()
);
const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies);
const instance = await publicAPI.createInstance();
instance.mount(mountpoint, {
onError: jest.fn(),
onChange: jest.fn(),
dateRange: { fromDate: '', toDate: '' },
query: { query: '', language: 'lucene' },
filters: [],
showNoDataPopover: jest.fn(),
initialContext: {
indexPatternId: '1',
fieldName: 'test',
},
searchSessionId: 'sessionId',
});
instance.unmount();
})()
).resolves.toBeUndefined();
});
it('should not have child nodes after unmount', async () => {
pluginInstance.setup(
coreMock.createSetup() as CoreSetup<MockedStartDependencies>,
pluginSetupDependencies,
jest.fn()
);
const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies);
const instance = await publicAPI.createInstance();
instance.mount(mountpoint, {
onError: jest.fn(),
onChange: jest.fn(),
dateRange: { fromDate: '', toDate: '' },
query: { query: '', language: 'lucene' },
filters: [],
showNoDataPopover: jest.fn(),
searchSessionId: 'sessionId',
});
instance.unmount();
expect(mountpoint.hasChildNodes()).toBe(false);
});
});