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


##########
frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit-list-item/user-computing-unit-list-item.component.spec.ts:
##########
@@ -490,4 +492,134 @@ describe("UserComputingUnitListItemComponent", () => {
       expect(component.showGpuSelection()).toBe(true);
     });
   });
+
+  // ── Rendered-template interactions (the row's bindings) ──
+
+  describe("template interactions", () => {
+    /** The handlers that call `$event.stopPropagation()` need a real-ish 
event. */
+    const clickEvent = () => ({ stopPropagation: vi.fn() }) as unknown as 
MouseEvent;
+

Review Comment:
   The new popover/tooltip assertions read from the global 
`.cdk-overlay-container` text. Since Angular CDK caches this container across 
tests, leftover overlay DOM from earlier tests/specs can pollute these 
assertions and cause flakes. Consider clearing the overlay container contents 
in an `afterEach` inside this `describe` (pattern used elsewhere, e.g. 
`computing-unit-selection.component.spec.ts:1199-1204`).



##########
frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit-list-item/user-computing-unit-list-item.component.spec.ts:
##########
@@ -490,4 +492,134 @@ describe("UserComputingUnitListItemComponent", () => {
       expect(component.showGpuSelection()).toBe(true);
     });
   });
+
+  // ── Rendered-template interactions (the row's bindings) ──
+
+  describe("template interactions", () => {
+    /** The handlers that call `$event.stopPropagation()` need a real-ish 
event. */
+    const clickEvent = () => ({ stopPropagation: vi.fn() }) as unknown as 
MouseEvent;

Review Comment:
   PR description notes that the spec avoids `vi.useFakeTimers()`, but this 
spec file still contains a `vi.useFakeTimers()`-based test (pre-existing). 
Consider updating the description to clarify it means no *new* fake-timer usage 
was added in this PR.



##########
frontend/src/app/dashboard/component/user/user-computing-unit/user-computing-unit-list-item/user-computing-unit-list-item.component.spec.ts:
##########
@@ -490,4 +492,134 @@ describe("UserComputingUnitListItemComponent", () => {
       expect(component.showGpuSelection()).toBe(true);
     });
   });
+
+  // ── Rendered-template interactions (the row's bindings) ──
+
+  describe("template interactions", () => {
+    /** The handlers that call `$event.stopPropagation()` need a real-ish 
event. */
+    const clickEvent = () => ({ stopPropagation: vi.fn() }) as unknown as 
MouseEvent;
+
+    /** Show the metrics popover synchronously and return its overlay text. */
+    function openMetricsPopover(): { popover: NzPopoverDirective; text: string 
} {
+      const popover = 
fixture.debugElement.query(By.css(".metrics-container")).injector.get(NzPopoverDirective);
+      popover.show();
+      fixture.detectChanges();
+      return { popover, text: 
document.querySelector(".cdk-overlay-container")?.textContent ?? "" };
+    }
+
+    it("the rename button starts inline editing", () => {
+      const renameButton = fixture.debugElement.query(By.css(".edit-button 
button"));
+      expect(renameButton).toBeTruthy();
+
+      renameButton.triggerEventHandler("click", clickEvent());
+
+      expect(component.editingNameOfUnit).toBe(1);
+      expect(component.editingUnitName).toBe("unit-1");
+    });
+
+    it("clicking the unit name opens the metadata modal", () => {
+      const createSpy = vi
+        .spyOn(TestBed.inject(NzModalService), "create")
+        .mockReturnValue({} as ReturnType<NzModalService["create"]>);
+
+      
fixture.debugElement.query(By.css(".resource-name")).triggerEventHandler("click",
 null);
+
+      expect(createSpy).toHaveBeenCalledWith(expect.objectContaining({ nzData: 
component.entry }));
+    });
+
+    it("escape on the rename input cancels editing", () => {
+      component.editingNameOfUnit = 1;
+      fixture.detectChanges();
+
+      const input = 
fixture.debugElement.query(By.css("input.unit-name-edit-input"));
+      expect(input).toBeTruthy();
+      input.nativeElement.dispatchEvent(new KeyboardEvent("keydown", { key: 
"Escape", bubbles: true }));
+
+      expect(component.editingNameOfUnit).toBeNull();
+    });
+
+    it("enter on the rename input confirms with the typed value", () => {
+      computingUnitService.renameComputingUnit.mockReturnValue(of({} as 
Response));
+      component.editingNameOfUnit = 1;
+      fixture.detectChanges();
+
+      const input = 
fixture.debugElement.query(By.css("input.unit-name-edit-input"));
+      input.nativeElement.value = "  renamed  ";
+      input.nativeElement.dispatchEvent(new KeyboardEvent("keydown", { key: 
"Enter", bubbles: true }));
+
+      
expect(computingUnitService.renameComputingUnit).toHaveBeenCalledExactlyOnceWith(1,
 "renamed");
+    });
+
+    it("a click inside the rename input does not bubble to the row", () => {
+      component.editingNameOfUnit = 1;
+      fixture.detectChanges();
+      const stopPropagation = vi.fn();
+
+      fixture.debugElement
+        .query(By.css("input.unit-name-edit-input"))
+        .triggerEventHandler("click", { stopPropagation } as unknown as 
MouseEvent);
+
+      expect(stopPropagation).toHaveBeenCalledTimes(1);
+    });
+
+    it("the delete button emits the deleted output", () => {
+      const deletedSpy = vi.fn();
+      component.deleted.subscribe(deletedSpy);
+      const buttons = fixture.debugElement.queryAll(By.css(".button-group 
button"));
+
+      buttons[buttons.length - 1].triggerEventHandler("click", null);
+

Review Comment:
   This test clicks `buttons[buttons.length - 1]`, which makes it 
order-dependent (it will break if the share button becomes enabled by default 
or new buttons are added). Prefer selecting the delete button by a stable 
attribute like its `title="Delete"`.



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