2023-11-06 11:28:44 +00:00
|
|
|
import { Config } from 'app/plugins/panel/nodeGraph/layout';
|
|
|
|
|
import { EdgeDatum, NodeDatum } from 'app/plugins/panel/nodeGraph/types';
|
|
|
|
|
|
2021-11-09 21:05:01 +04:00
|
|
|
const { layout } = jest.requireActual('../../app/plugins/panel/nodeGraph/layout.worker.js');
|
|
|
|
|
|
|
|
|
|
class LayoutMockWorker {
|
2021-11-11 14:27:59 +01:00
|
|
|
timeout: number | undefined;
|
2021-11-09 21:05:01 +04:00
|
|
|
constructor() {}
|
2023-11-06 11:28:44 +00:00
|
|
|
postMessage(data: { nodes: NodeDatum[]; edges: EdgeDatum[]; config: Config }) {
|
2021-11-09 21:05:01 +04:00
|
|
|
const { nodes, edges, config } = data;
|
2023-05-15 09:15:26 +01:00
|
|
|
this.timeout = window.setTimeout(() => {
|
2021-11-11 14:27:59 +01:00
|
|
|
this.timeout = undefined;
|
2021-11-09 21:05:01 +04:00
|
|
|
layout(nodes, edges, config);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
this.onmessage({ data: { nodes, edges } });
|
2023-05-15 09:15:26 +01:00
|
|
|
}, 1);
|
2021-11-11 14:27:59 +01:00
|
|
|
}
|
|
|
|
|
terminate() {
|
|
|
|
|
if (this.timeout) {
|
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
|
}
|
2021-11-09 21:05:01 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|