grafana/public/test/mocks/workers.ts
Andrej Ocenas 5cc9ff8b28
Tempo: Add filtering for service graph query (#41162)
* Add filter based on AdHocFilter element

* Add tests

* Cancel layout in case we have have new data or we unmount node graph

* Fix typing

* Fix test
2021-11-11 14:27:59 +01:00

34 lines
875 B
TypeScript

const { layout } = jest.requireActual('../../app/plugins/panel/nodeGraph/layout.worker.js');
class LayoutMockWorker {
timeout: number | undefined;
constructor() {}
postMessage(data: any) {
const { nodes, edges, config } = data;
this.timeout = setTimeout(() => {
this.timeout = undefined;
layout(nodes, edges, config);
// @ts-ignore
this.onmessage({ data: { nodes, edges } });
}, 1) as any;
}
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);