mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
d1e52d4788
* type fixes * couple more * just a couple more * small fixes to prometheus typings * improve some more datasource types
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { Config } from 'app/plugins/panel/nodeGraph/layout';
|
|
import { EdgeDatum, NodeDatum } from 'app/plugins/panel/nodeGraph/types';
|
|
|
|
const { layout } = jest.requireActual('../../app/plugins/panel/nodeGraph/layout.worker.js');
|
|
|
|
class LayoutMockWorker {
|
|
timeout: number | undefined;
|
|
constructor() {}
|
|
postMessage(data: { nodes: NodeDatum[]; edges: EdgeDatum[]; config: Config }) {
|
|
const { nodes, edges, config } = data;
|
|
this.timeout = window.setTimeout(() => {
|
|
this.timeout = undefined;
|
|
layout(nodes, edges, config);
|
|
// @ts-ignore
|
|
this.onmessage({ data: { nodes, edges } });
|
|
}, 1);
|
|
}
|
|
terminate() {
|
|
if (this.timeout) {
|
|
clearTimeout(this.timeout);
|
|
}
|
|
}
|
|
}
|
|
|
|
jest.mock('../../app/plugins/panel/nodeGraph/createLayoutWorker', () => ({
|
|
createWorker: () => new LayoutMockWorker(),
|
|
}));
|
|
|
|
class BasicMockWorker {
|
|
postMessage() {}
|
|
}
|
|
const mockCreateWorker = {
|
|
createWorker: () => new BasicMockWorker(),
|
|
};
|
|
|
|
jest.mock('../../app/features/live/centrifuge/createCentrifugeServiceWorker', () => mockCreateWorker);
|