mengw15 commented on code in PR #7655:
URL: https://github.com/apache/texera/pull/7655#discussion_r3780874823


##########
frontend/src/app/dashboard/component/admin/user/admin-user.component.spec.ts:
##########
@@ -611,4 +612,155 @@ describe("AdminUserComponent", () => {
       expect(component.filterByRole([], mk({ role: Role.ADMIN }))).toBe(false);
     });
   });
+
+  /**
+   * The tests above call the component's methods; these drive the table 
itself — the
+   * per-column search dropdowns, the click-to-edit cells and the row actions 
— so a control
+   * that loses its handler fails here.
+   */
+  describe("rendered table", () => {
+    /** Seeds both lists, as loading the users does, and renders the rows. */
+    function renderUsers(users: User[]): void {
+      component.userList = [...users];
+      component.listOfDisplayUser = [...users];
+      fixture.detectChanges();
+    }
+
+    const rowNames = (): string[] =>
+      Array.from(fixture.nativeElement.querySelectorAll("tbody tr")).map(row =>
+        ((row as HTMLElement).querySelectorAll("td")[2]?.textContent ?? 
"").trim()
+      );
+
+    it("swaps a cell for an input when it is clicked, and saves on enter", () 
=> {
+      const saveSpy = vi.spyOn(component, "saveEdit").mockImplementation(() => 
{});
+      renderUsers([userA]);
+
+      const nameCell = fixture.nativeElement.querySelectorAll("tbody tr 
td")[2].querySelector(".container");
+      nameCell.click();
+      fixture.detectChanges();
+
+      expect(component.editUid).toBe(userA.uid);
+      expect(component.editAttribute).toBe("name");
+      const input = fixture.nativeElement.querySelectorAll("tbody tr 
td")[2].querySelector("input");
+      expect(input).not.toBeNull();
+
+      input.value = "Alicia";
+      input.dispatchEvent(new Event("input"));
+      fixture.detectChanges();
+      expect(component.editName).toBe("Alicia");
+
+      // Only Enter commits; other keys leave the edit open.
+      input.dispatchEvent(new KeyboardEvent("keydown", { key: "a", bubbles: 
true }));
+      expect(saveSpy).not.toHaveBeenCalled();
+
+      input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", 
bubbles: true }));
+      expect(saveSpy).toHaveBeenCalled();
+
+      // Clicking away saves too, so a half-typed edit is not silently dropped.
+      saveSpy.mockClear();
+      fixture.nativeElement
+        .querySelectorAll("tbody tr td")[2]
+        .querySelector("div")
+        .dispatchEvent(new Event("focusout", { bubbles: true }));
+
+      expect(saveSpy).toHaveBeenCalled();
+    });
+
+    it("does the same for the email and comment cells, and saves when the cell 
loses focus", () => {
+      const saveSpy = vi.spyOn(component, "saveEdit").mockImplementation(() => 
{});
+      renderUsers([userA]);
+
+      const cells = () => fixture.nativeElement.querySelectorAll("tbody tr 
td");
+      cells()[3].querySelector(".container").click();
+      fixture.detectChanges();
+      expect(component.editAttribute).toBe("email");
+      const emailInput = cells()[3].querySelector("input[type=email]");
+      expect(emailInput).not.toBeNull();
+      emailInput.value = "[email protected]";
+      emailInput.dispatchEvent(new Event("input"));
+      fixture.detectChanges();
+      expect(component.editEmail).toBe("[email protected]");
+      emailInput.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", 
bubbles: true }));
+      cells()[3]
+        .querySelector("div")
+        .dispatchEvent(new Event("focusout", { bubbles: true }));
+      expect(saveSpy).toHaveBeenCalled();

Review Comment:
   Applied. The Enter assertion was indeed indistinguishable from the 
`focusout` that followed it — the name cell's flow already split them, email 
and comment did not. Each binding now has its own assertion with a 
`mockClear()` between.
   
   Verified the fix isn't cosmetic: deleting `(keydown.enter)` from the email 
input now fails the spec, where before the same mutation still passed.



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