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