Copilot commented on code in PR #6385:
URL: https://github.com/apache/texera/pull/6385#discussion_r3567402173


##########
frontend/src/app/workspace/component/result-panel/result-table-frame/result-table-frame.component.spec.ts:
##########
@@ -18,23 +18,95 @@
  */
 
 import { ComponentFixture, TestBed } from "@angular/core/testing";
+import { SimpleChange } from "@angular/core";
 
 import { ResultTableFrameComponent } from "./result-table-frame.component";
 import { OperatorMetadataService } from 
"../../../service/operator-metadata/operator-metadata.service";
 import { StubOperatorMetadataService } from 
"../../../service/operator-metadata/stub-operator-metadata.service";
 import { HttpClientTestingModule } from "@angular/common/http/testing";
-import { NzModalModule } from "ng-zorro-antd/modal";
-import { NzTableModule } from "ng-zorro-antd/table";
+import { NzModalModule, NzModalService } from "ng-zorro-antd/modal";
+import { NzTableModule, NzTableQueryParams } from "ng-zorro-antd/table";
 import { NoopAnimationsModule } from "@angular/platform-browser/animations";
+import { By, DomSanitizer } from "@angular/platform-browser";
+import { of, Subject } from "rxjs";
 import { commonTestProviders } from "../../../../common/testing/test-utils";
 import { GuiConfigService } from 
"../../../../common/service/gui-config.service";
+import {
+  OperatorPaginationResultService,
+  WorkflowResultService,
+} from "../../../service/workflow-result/workflow-result.service";
+import { WorkflowStatusService } from 
"../../../service/workflow-status/workflow-status.service";
+import { PanelResizeService } from 
"../../../service/workflow-result/panel-resize/panel-resize.service";
+import { OperatorState, OperatorStatistics, WebResultUpdate } from 
"../../../types/execute-workflow.interface";
+import { PaginatedResultEvent } from 
"../../../types/workflow-websocket.interface";
+import { IndexableObject } from "../../../types/result-table.interface";
+import { RowModalComponent } from "../result-panel-modal.component";
+import { ResultExportationComponent } from 
"../../result-exportation/result-exportation.component";
+
+type OperatorStatsMap = Record<string, Record<string, Record<string, number>>>;
 
 describe("ResultTableFrameComponent", () => {
   let component: ResultTableFrameComponent;
   let fixture: ComponentFixture<ResultTableFrameComponent>;
+  let workflowResultService: WorkflowResultService;
+  let workflowStatusService: WorkflowStatusService;
+  let resizeService: PanelResizeService;
+  let modalService: NzModalService;
 
   const GUI_CONFIG_LIMIT = 15;
 
+  const SAMPLE_ROW: IndexableObject = { _id: 0, name: "alice", score: 90 };
+
+  const makePageEvent = (
+    pageIndex: number,
+    table: ReadonlyArray<IndexableObject> = [SAMPLE_ROW]
+  ): PaginatedResultEvent => ({
+    requestID: "",
+    operatorID: "op1",
+    pageIndex,
+    table,
+    schema: [],
+  });
+
+  // Installs a paginated-result-service double behind 
WorkflowResultService.getPaginatedResultService.
+  const makePaginatedResultService = (overrides: Record<string, unknown> = {}) 
=> {
+    const paginatedResultService = {
+      getCurrentTotalNumTuples: vi.fn().mockReturnValue(42),
+      getCurrentPageIndex: vi.fn().mockReturnValue(1),
+      getStats: vi.fn().mockReturnValue({ name: { min: 1 } }),
+      selectPage: vi.fn().mockReturnValue(of(makePageEvent(1))),
+      ...overrides,
+    };
+    vi.spyOn(workflowResultService, 
"getPaginatedResultService").mockReturnValue(
+      paginatedResultService as unknown as OperatorPaginationResultService
+    );
+    return paginatedResultService;
+  };
+
+  const makeStatistics = (state: OperatorState): OperatorStatistics => ({
+    operatorState: state,
+    aggregatedInputRowCount: 0,
+    inputPortMetrics: {},
+    aggregatedOutputRowCount: 0,
+    outputPortMetrics: {},
+  });
+
+  const paginationUpdate = (totalNumTuples: number, dirtyPageIndices: 
number[]): WebResultUpdate => ({
+    mode: { type: "PaginationMode" },
+    totalNumTuples,
+    dirtyPageIndices,
+  });
+
+  const queryParams = (pageIndex: number): NzTableQueryParams => ({ pageIndex, 
pageSize: 5, sort: [], filter: [] });
+
+  // Re-creates the component so spies installed on service streams are picked 
up by ngOnInit.
+  const recreateComponent = (operatorId?: string): void => {
+    fixture = TestBed.createComponent(ResultTableFrameComponent);
+    component = fixture.componentInstance;
+    component.operatorId = operatorId;
+    fixture.detectChanges();
+  };

Review Comment:
   `recreateComponent` creates a new ComponentFixture without destroying the 
existing one. The previous component instance remains alive (including its 
`untilDestroyed` subscriptions), which can lead to multiple active 
subscriptions and cross-test interference/flakiness when test Subjects emit.



##########
frontend/src/app/workspace/component/result-panel/result-table-frame/result-table-frame.component.spec.ts:
##########
@@ -54,11 +126,20 @@ describe("ResultTableFrameComponent", () => {
         ...commonTestProviders,
       ],
     }).compileComponents();
+    workflowResultService = TestBed.inject(WorkflowResultService);
+    workflowStatusService = TestBed.inject(WorkflowStatusService);
+    resizeService = TestBed.inject(PanelResizeService);
+    modalService = TestBed.inject(NzModalService);
     fixture = TestBed.createComponent(ResultTableFrameComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
   });
 
+  afterEach(() => {
+    document.querySelectorAll(".cdk-overlay-container").forEach(container => 
(container.innerHTML = ""));
+    vi.restoreAllMocks();
+  });

Review Comment:
   The spec never destroys the active Angular fixture in `afterEach`. This can 
leak DOM/subscriptions across tests (especially after `recreateComponent`), 
making the suite order-dependent.



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