PG1204 commented on code in PR #5626: URL: https://github.com/apache/texera/pull/5626#discussion_r3406323444
########## frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.browser.spec.ts: ########## @@ -0,0 +1,216 @@ +/** + * 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. + */ + +/** + * Mouse / pointer event tests for WorkflowEditorComponent. + * + * These tests exercise JointJS event paths (cell-view jQuery + * `.trigger("mousedown" | "dblclick")` dispatch, blank-area paper + * clicks, shift-click multi-select) that depend on real-DOM SVG hit + * testing and canvas measurement. jsdom does not implement those + * paths, so the tests live in a `.browser.spec.ts` file that is + * skipped by the default jsdom `test` target and picked up only by + * the `test-browser` target (Vitest + Playwright Chromium). + * + * Originally part of workflow-editor.component.spec.ts; commented out + * in PR #5146 to keep CI green after the file was added to the jsdom + * runner. Restored here per issue #5318. + */ + +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { NzModalRef, NzModalService } from "ng-zorro-antd/modal"; +import * as jQuery from "jquery"; + +import { WorkflowEditorComponent } from "./workflow-editor.component"; +import { NzModalCommentBoxComponent } from "./comment-box-modal/nz-modal-comment-box.component"; +import { workflowEditorTestImports, workflowEditorTestProviders } from "./workflow-editor.test-utils"; + +import { WorkflowActionService } from "../../service/workflow-graph/model/workflow-action.service"; +import { + mockCommentBox, + mockPoint, + mockResultPredicate, + mockScanPredicate, +} from "../../service/workflow-graph/model/mock-workflow-data"; +import { createYTypeFromObject } from "../../types/shared-editing.interface"; + +const createJQueryEvent = (event: string, properties?: object): JQuery.Event => + (jQuery as unknown as JQueryStatic).Event(event, properties); + +describe("WorkflowEditorComponent - mouse and pointer event integration", () => { + let component: WorkflowEditorComponent; + let fixture: ComponentFixture<WorkflowEditorComponent>; + let workflowActionService: WorkflowActionService; + let nzModalService: NzModalService; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: workflowEditorTestImports, + providers: workflowEditorTestProviders, + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(WorkflowEditorComponent); + component = fixture.componentInstance; + workflowActionService = TestBed.inject(WorkflowActionService); + workflowActionService.setHighlightingEnabled(true); + nzModalService = TestBed.inject(NzModalService); + fixture.detectChanges(); + }); + + it("should try to highlight the operator when user mouse clicks on an operator", () => { + const jointGraphWrapper = workflowActionService.getJointGraphWrapper(); + // install a spy on the highlight operator function and pass the call through + vi.spyOn(jointGraphWrapper, "highlightOperators"); + workflowActionService.addOperator(mockScanPredicate, mockPoint); + + // unhighlight the operator in case it's automatically highlighted + jointGraphWrapper.unhighlightOperators(mockScanPredicate.operatorID); + + // find the joint Cell View object of the operator element + const jointCellView = component.paper.findViewByModel(mockScanPredicate.operatorID); + jointCellView.$el.trigger("mousedown"); + + fixture.detectChanges(); + + // assert the highlighted operator is correct + expect(jointGraphWrapper.getCurrentHighlightedOperatorIDs()).toEqual([mockScanPredicate.operatorID]); + }); + + it("should highlight the commentBox when user clicks on a commentBox", () => { + const jointGraphWrapper = workflowActionService.getJointGraphWrapper(); + vi.spyOn(jointGraphWrapper, "highlightCommentBoxes"); + workflowActionService.addCommentBox(mockCommentBox); + jointGraphWrapper.unhighlightCommentBoxes(mockCommentBox.commentBoxID); + const jointCellView = component.paper.findViewByModel(mockCommentBox.commentBoxID); + jointCellView.$el.trigger("mousedown"); + fixture.detectChanges(); + expect(jointGraphWrapper.getCurrentHighlightedCommentBoxIDs()).toEqual([mockCommentBox.commentBoxID]); + }); + + it("should open commentBox as NzModal when user double clicks on a commentBox", () => { + const modalRef: NzModalRef = nzModalService.create({ Review Comment: I'll leave this as is in this PR. I shall raise a follow up PR for the simplification. -- 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]
