From c9c7f55aa070d514f9bf96bfb98dcd30e6f27a2b Mon Sep 17 00:00:00 2001 From: JGerla Date: Thu, 22 Jan 2026 12:02:20 +0100 Subject: [PATCH] feat: removed usage of structuredClone inside the editorWarningSystem ref: N25B-450 --- .../components/EditorWarnings.tsx | 14 +++--- .../VisProgStores.test.tsx | 11 +++-- test/setupFlowTests.ts | 43 +++++++++++-------- test/test-utils/test-utils.tsx | 3 ++ 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/pages/VisProgPage/visualProgrammingUI/components/EditorWarnings.tsx b/src/pages/VisProgPage/visualProgrammingUI/components/EditorWarnings.tsx index c8c3a27..d222cd0 100644 --- a/src/pages/VisProgPage/visualProgrammingUI/components/EditorWarnings.tsx +++ b/src/pages/VisProgPage/visualProgrammingUI/components/EditorWarnings.tsx @@ -138,9 +138,8 @@ export function editorWarningRegistry(get: ZustandGet, set: ZustandSet) : Editor const { scope: {id, handleId}, type, severity } = warning; const warningKey = handleId ? `${type}:${handleId}` : type; const compositeKey = `${id}|${warningKey}`; - const wRegistry = structuredClone(get().editorWarningRegistry); - const sIndex = structuredClone(get().severityIndex); - console.log("register") + const wRegistry = get().editorWarningRegistry; + const sIndex = get().severityIndex; // add to warning registry if (!wRegistry.has(id)) { wRegistry.set(id, new Map()); @@ -160,9 +159,8 @@ export function editorWarningRegistry(get: ZustandGet, set: ZustandSet) : Editor }, unregisterWarning: (id, warningKey) => { - const wRegistry = structuredClone(get().editorWarningRegistry); - const sIndex = structuredClone(get().severityIndex); - console.log("unregister") + const wRegistry = get().editorWarningRegistry; + const sIndex = get().severityIndex; // verify if the warning was created already const warning = wRegistry.get(id)?.get(warningKey); if (!warning) return; @@ -181,8 +179,8 @@ export function editorWarningRegistry(get: ZustandGet, set: ZustandSet) : Editor }, unregisterWarningsForId: (id) => { - const wRegistry = structuredClone(get().editorWarningRegistry); - const sIndex = structuredClone(get().severityIndex); + const wRegistry = get().editorWarningRegistry; + const sIndex = get().severityIndex; const nodeWarnings = wRegistry.get(id); diff --git a/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx b/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx index fa98048..885916c 100644 --- a/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx +++ b/test/pages/visProgPage/visualProgrammingUI/VisProgStores.test.tsx @@ -1,5 +1,10 @@ import {act} from '@testing-library/react'; -import type {Connection, Edge, Node} from "@xyflow/react"; +import { + type Connection, + type Edge, + type Node, + useReactFlow +} from "@xyflow/react"; import type {HandleRule, RuleResult} from "../../../../src/pages/VisProgPage/visualProgrammingUI/HandleRuleLogic.ts"; import { NodeDisconnections } from "../../../../src/pages/VisProgPage/visualProgrammingUI/NodeRegistry.ts"; import type {PhaseNodeData} from "../../../../src/pages/VisProgPage/visualProgrammingUI/nodes/PhaseNode.tsx"; @@ -397,9 +402,9 @@ describe('FlowStore Functionality', () => { target: 'B' }] }); - + const {deleteElements} = useReactFlow(); act(()=> { - deleteNode(nodeId); + deleteNode(nodeId, deleteElements); }); const updatedState = useFlowStore.getState(); diff --git a/test/setupFlowTests.ts b/test/setupFlowTests.ts index e3382c6..fbf637b 100644 --- a/test/setupFlowTests.ts +++ b/test/setupFlowTests.ts @@ -1,5 +1,10 @@ import '@testing-library/jest-dom'; import { cleanup } from '@testing-library/react'; +import { + type CompositeWarningKey, + type SeverityIndex, + type WarningRegistry +} from "../src/pages/VisProgPage/visualProgrammingUI/components/EditorWarnings.tsx"; import useFlowStore from '../src/pages/VisProgPage/visualProgrammingUI/VisProgStores.tsx'; if (!globalThis.structuredClone) { @@ -69,31 +74,33 @@ export const mockReactFlow = () => { }; +const emptySeverityIndex : SeverityIndex = new Map([ + ['INFO', new Set()], + ['WARNING', new Set()], + ['ERROR', new Set()], +]); +const emptyWarningRegistry : WarningRegistry = new Map(); + +const defaultState = { + nodes: [], + edges: [], + past: [], + future: [], + isBatchAction: false, + edgeReconnectSuccessful: true, + ruleRegistry: new Map(), + editorWarningRegistry: emptyWarningRegistry, + severityIndex: emptySeverityIndex, +} beforeAll(() => { - useFlowStore.setState({ - nodes: [], - edges: [], - past: [], - future: [], - isBatchAction: false, - edgeReconnectSuccessful: true, - ruleRegistry: new Map() - }); + useFlowStore.setState(defaultState); }); afterEach(() => { cleanup(); - useFlowStore.setState({ - nodes: [], - edges: [], - past: [], - future: [], - isBatchAction: false, - edgeReconnectSuccessful: true, - ruleRegistry: new Map() - }); + useFlowStore.setState(defaultState); }); if (typeof HTMLDialogElement !== 'undefined') { diff --git a/test/test-utils/test-utils.tsx b/test/test-utils/test-utils.tsx index a39e01a..157ea19 100644 --- a/test/test-utils/test-utils.tsx +++ b/test/test-utils/test-utils.tsx @@ -2,6 +2,9 @@ import { render, type RenderOptions } from '@testing-library/react'; import { type ReactElement, type ReactNode } from 'react'; import { ReactFlowProvider } from '@xyflow/react'; +import {mockReactFlow} from "../setupFlowTests.ts"; + +mockReactFlow(); /** * Custom render function that wraps components with necessary providers