Skip to content

Build your personal knowledge base with Trilium Notes

test(client): cover controlled FormTextArea after user edits

hippi345b6f0eea84faa
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index b4c5d86a5b..e9169eed84 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -1900,6 +1900,7 @@ describe("Board column rename", () => {
.querySelector<HTMLTextAreaElement>(".board-new-item.inserting textarea");
if (!field) throw new Error("expected the field for a new card to be open");
field.value = "Made";
+ field.dispatchEvent(new Event("input", { bubbles: true }));
await act(async () => {
field.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
await flush();
diff --git a/apps/client/src/widgets/react/FormTextArea.spec.tsx b/apps/client/src/widgets/react/FormTextArea.spec.tsx
index 73c827b14f..4eabefde18 100644
--- a/apps/client/src/widgets/react/FormTextArea.spec.tsx
+++ b/apps/client/src/widgets/react/FormTextArea.spec.tsx
@@ -19,12 +19,19 @@ describe("FormTextArea", () => {
const textarea = () => container.querySelector<HTMLTextAreaElement>("textarea");
- it("reflects an updated currentValue prop when re-rendered", () => {
- act(() => render(<FormTextArea currentValue="first" />, container));
- expect(textarea()?.value).toBe("first");
+ it("reflects an updated currentValue prop after a user edit", () => {
+ act(() => render(<FormTextArea currentValue="note A" />, container));
- act(() => render(<FormTextArea currentValue="second" />, container));
- expect(textarea()?.value).toBe("second");
+ const el = textarea();
+ if (!el) throw new Error("textarea not found");
+
+ // Simulate the user typing, which dirties the DOM value without updating currentValue.
+ el.value = "user edit";
+ act(() => { el.dispatchEvent(new Event("input", { bubbles: true })); });
+
+ // Now re-render with a new prop, as if the parent switched to a different note.
+ act(() => render(<FormTextArea currentValue="note B" />, container));
+ expect(textarea()?.value).toBe("note B");
});
it("fires onChange with the new value when the user types", () => {