mengw15 commented on code in PR #7420:
URL: https://github.com/apache/texera/pull/7420#discussion_r3739751001
##########
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:
Adopted — added an `afterEach` in this describe that clears the overlay
contents, mirroring `computing-unit-selection.component.spec.ts` (including
clearing `innerHTML` rather than removing the container element, since CDK
caches it).
##########
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:
Adopted — the delete button is now selected via `button[title='Delete']`
instead of the last element, so it no longer depends on button order or on the
share button staying hidden.
##########
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:
Correct — this file does have one pre-existing fake-timer test. Reworded the
PR description to say the added tests introduce no *new* `vi.useFakeTimers()`
usage.
--
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]