Xiao-zhen-Liu commented on code in PR #5626:
URL: https://github.com/apache/texera/pull/5626#discussion_r3406230564


##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.test-utils.ts:
##########
@@ -0,0 +1,84 @@
+/**
+ * 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.
+ */
+
+/**
+ * Shared TestBed configuration for WorkflowEditorComponent specs.
+ *
+ * The workflow editor has two spec files that drive the same component:
+ *   - workflow-editor.component.spec.ts          (jsdom test target)
+ *   - workflow-editor.component.browser.spec.ts  (test-browser target,
+ *                                                 for JointJS event paths
+ *                                                 that need real DOM/SVG)
+ *
+ * Both specs configure TestBed with the same set of imports and
+ * providers. Exporting the two arrays here keeps them in lock-step so
+ * the two TestBed setups don't drift over time.
+ */
+
+import { Provider } from "@angular/core";
+import { HttpClientTestingModule } from "@angular/common/http/testing";
+import { NoopAnimationsModule } from "@angular/platform-browser/animations";
+import { RouterTestingModule } from "@angular/router/testing";
+import { NzModalModule, NzModalService } from "ng-zorro-antd/modal";
+import { NzContextMenuService, NzDropDownModule } from 
"ng-zorro-antd/dropdown";
+
+import { WorkflowEditorComponent } from "./workflow-editor.component";
+import { NzModalCommentBoxComponent } from 
"./comment-box-modal/nz-modal-comment-box.component";
+
+import { WorkflowActionService } from 
"../../service/workflow-graph/model/workflow-action.service";
+import { WorkflowUtilService } from 
"../../service/workflow-graph/util/workflow-util.service";
+import { UndoRedoService } from "../../service/undo-redo/undo-redo.service";
+import { DragDropService } from "../../service/drag-drop/drag-drop.service";
+import { ValidationWorkflowService } from 
"../../service/validation/validation-workflow.service";
+import { OperatorMetadataService } from 
"../../service/operator-metadata/operator-metadata.service";
+import { StubOperatorMetadataService } from 
"../../service/operator-metadata/stub-operator-metadata.service";
+import { JointUIService } from "../../service/joint-ui/joint-ui.service";
+import { WorkflowStatusService } from 
"../../service/workflow-status/workflow-status.service";
+import { ExecuteWorkflowService } from 
"../../service/execute-workflow/execute-workflow.service";
+import { WorkflowVersionService } from 
"../../../dashboard/service/user/workflow-version/workflow-version.service";
+import { UserService } from "src/app/common/service/user/user.service";
+import { StubUserService } from 
"src/app/common/service/user/stub-user.service";
+import { commonTestProviders } from "../../../common/testing/test-utils";
+
+export const workflowEditorTestImports = [
+  RouterTestingModule,
+  HttpClientTestingModule,
+  NzModalModule,
+  NzDropDownModule,
+  NoopAnimationsModule,
+  WorkflowEditorComponent,
+  NzModalCommentBoxComponent,
+];
+
+export const workflowEditorTestProviders: Provider[] = [

Review Comment:
   Good call, and matches the existing 
`commonTestImports`/`commonTestProviders` pattern. Also nice that the original 
duplicate `UndoRedoService` is gone here.



##########
frontend/src/app/workspace/component/workflow-editor/workflow-editor.component.ts:
##########
@@ -397,10 +397,14 @@ export class WorkflowEditorComponent implements OnInit, 
AfterViewInit, OnDestroy
    * Centralizing this here avoids the race where the validation pass
    * overwrites a state-derived stroke (or vice versa) for an operator that
    * is both invalid and has a cached execution status.
+   *
+   * Callers that already have a Validation result (the validation stream)
+   * may pass it in to avoid recomputing it; callers without one (the
+   * operator-add stream) let the helper fetch it lazily.
    */
-  private applyOperatorBorder(operatorID: string): void {
-    const validation = 
this.validationWorkflowService.validateOperator(operatorID);
-    if (!validation.isValid) {
+  private applyOperatorBorder(operatorID: string, validation?: Validation): 
void {

Review Comment:
   This changes real app code, but the PR description only covers the test 
fixes. Please mention it in the description or split it out. It's correct (the 
stream emits the same `Validation` you'd recompute), but no test covers the new 
"validation passed in" path.



##########
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);

Review Comment:
   Good catch adding this — the old jsdom block didn't. A one-line comment on 
why would help.



##########
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:
   Not from this PR, but: creating a real modal just to mock `create` into 
returning it is roundabout. Could simplify if you ever revisit. Fine for now.



##########
frontend/angular.json:
##########
@@ -110,7 +110,6 @@
             "runnerConfig": "vitest.browser.config.ts",
             "tsConfig": "src/tsconfig.spec.json",
             "include": [
-              
"**/app/workspace/component/workflow-editor/workflow-editor.component.spec.ts",
               "**/*.browser.spec.ts"

Review Comment:
   Correct fix — the `test` target already excludes `*.browser.spec.ts`, so the 
two targets now split cleanly with no double-run.



-- 
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]

Reply via email to