Copilot commented on code in PR #6772: URL: https://github.com/apache/texera/pull/6772#discussion_r3627713195
########## frontend/src/app/workspace/service/workflow-graph/model/shared-model-change-handler.spec.ts: ########## @@ -0,0 +1,548 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { TestBed } from "@angular/core/testing"; +import * as joint from "jointjs"; +import { OperatorMetadataService } from "../../operator-metadata/operator-metadata.service"; +import { StubOperatorMetadataService } from "../../operator-metadata/stub-operator-metadata.service"; +import { JointUIService } from "../../joint-ui/joint-ui.service"; +import { UndoRedoService } from "../../undo-redo/undo-redo.service"; +import { WorkflowUtilService } from "../util/workflow-util.service"; +import { WorkflowActionService } from "./workflow-action.service"; +import { WorkflowGraph } from "./workflow-graph"; +import { JointGraphWrapper } from "./joint-graph-wrapper"; +import { commonTestProviders } from "../../../../common/testing/test-utils"; +import { GuiConfigService } from "../../../../common/service/gui-config.service"; +import { + mockCommentBox, + mockPoint, + mockResultPredicate, + mockScanPredicate, + mockScanResultLink, + mockSentimentPredicate, +} from "./mock-workflow-data"; +import { Comment, OperatorLink, OperatorPredicate, Point } from "../../../types/workflow-common.interface"; +import { createYTypeFromObject } from "../../../types/shared-editing.interface"; + +/** + * SharedModelChangeHandler is constructed internally by WorkflowActionService. It wires yjs deep-observers on the + * TexeraGraph's shared model (operatorIDMap, operatorLinkMap, elementPositionMap, commentBoxMap) and triggers the + * TexeraGraph's change subjects while mirroring the change onto the JointJS graph. + * + * These tests build the real service (so the handler is wired to real collaborators: WorkflowGraph, joint.dia.Graph, + * JointGraphWrapper, JointUIService) and drive the shared model through the graph's mutation API, asserting the + * corresponding subjects fire with the right payloads and that JointJS is kept in sync. + */ +describe("SharedModelChangeHandler", () => { + let service: WorkflowActionService; + let texeraGraph: WorkflowGraph; + let jointGraph: joint.dia.Graph; + let jointGraphWrapper: JointGraphWrapper; + + beforeEach(() => { + // silence the informational console.log calls emitted by the graph/handler on some mutations + vi.spyOn(console, "log").mockImplementation(() => {}); + + TestBed.configureTestingModule({ + providers: [ + WorkflowActionService, + WorkflowUtilService, + JointUIService, + UndoRedoService, + { + provide: OperatorMetadataService, + useClass: StubOperatorMetadataService, + }, + ...commonTestProviders, + ], + }); + service = TestBed.inject(WorkflowActionService); + texeraGraph = (service as any).texeraGraph; + jointGraph = service.getJointGraph(); + jointGraphWrapper = service.getJointGraphWrapper(); + }); + + afterEach(() => { + // Tear down the underlying shared model (awareness / websocket provider) to avoid leaks across tests. + try { + texeraGraph.destroyYModel(); + } catch (e) { + // a test that called loadNewYModel already destroyed the previous model; ignore. + } + vi.restoreAllMocks(); + }); Review Comment: The afterEach teardown swallows any exception from destroyYModel(). That can hide real shared-editing cleanup failures (and make later tests pass while leaking y-websocket/awareness resources). Since loadNewYModel() installs a fresh SharedModel, calling destroyYModel() here should be safe; let failures surface instead of ignoring them. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
