Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(notes): pin the read-only lock to the real editor

Etienne Lescot21ea97ea9c7a
diff --git a/src/components/launch/NotesToolbar.test.tsx b/src/components/launch/NotesToolbar.test.tsx
index 3ee81d6b3..766e9c680 100644
--- a/src/components/launch/NotesToolbar.test.tsx
+++ b/src/components/launch/NotesToolbar.test.tsx
@@ -147,7 +147,7 @@ describe("NotesToolbar teleprompter controls", () => {
rerender(
<I18nProvider>
- <NotesToolbar {...createProps({ isPlaying: true })} />
+ <NotesToolbar {...createProps({ isPlaying: true, formattingDisabled: true })} />
</I18nProvider>,
);
expect(screen.getByRole("button", { name: "Pause auto-scroll" })).not.toHaveAttribute(
diff --git a/src/components/launch/NotesWindow.editable.test.tsx b/src/components/launch/NotesWindow.editable.test.tsx
new file mode 100644
index 000000000..c13000cb0
--- /dev/null
+++ b/src/components/launch/NotesWindow.editable.test.tsx
@@ -0,0 +1,50 @@
+import "@testing-library/jest-dom";
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { I18nProvider } from "@/contexts/I18nContext";
+import { NotesWindow } from "./NotesWindow";
+
+// The sibling suite stubs `@tiptap/react`, so nothing in it can show that the real note ever
+// stops accepting edits. `useEditor` honours `editable` only when it CREATES the editor and
+// pins every later option pass to the editor's own `isEditable`, which makes `setEditable` the
+// one path that carries a mirror toggle — and losing it, to a refactor or a Tiptap upgrade,
+// leaves every mocked assertion green. So this one drives the real editor and reads
+// `contenteditable` back off the DOM. (The constructor option stays pinned at the mocked
+// boundary: React flushes the effect before a test can observe the first paint.)
+vi.mock("@/components/ui/tooltip", () => ({
+ Tooltip: ({ children }: { children: React.ReactNode }) => children,
+}));
+
+beforeEach(() => {
+ localStorage.clear();
+});
+
+function noteBody(): HTMLElement {
+ const body = document.querySelector<HTMLElement>(".tiptap");
+ if (!body) {
+ throw new Error("the editor never mounted");
+ }
+
+ return body;
+}
+
+describe("NotesWindow read-only wiring against the real editor", () => {
+ it("stops and resumes accepting edits with the mirror", async () => {
+ const user = userEvent.setup();
+ render(
+ <I18nProvider>
+ <NotesWindow />
+ </I18nProvider>,
+ );
+ const mirror = screen.getByRole("button", { name: "Mirror horizontally" });
+
+ expect(noteBody()).toHaveAttribute("contenteditable", "true");
+
+ await user.click(mirror);
+ expect(noteBody()).toHaveAttribute("contenteditable", "false");
+
+ await user.click(mirror);
+ expect(noteBody()).toHaveAttribute("contenteditable", "true");
+ });
+});
diff --git a/src/components/launch/NotesWindow.test.tsx b/src/components/launch/NotesWindow.test.tsx
index 87989c452..cb77abcb1 100644
--- a/src/components/launch/NotesWindow.test.tsx
+++ b/src/components/launch/NotesWindow.test.tsx
@@ -312,8 +312,10 @@ describe("NotesWindow teleprompter mode", () => {
);
render(<NotesWindow />);
- // The editor must be CREATED read-only — an effect-only lock would leave the first
- // painted frame editable.
+ // `useEditor` is stubbed here, so this pins the option we hand Tiptap rather than what
+ // Tiptap does with it: the editor must be CREATED read-only, because an effect-only lock
+ // would leave the first painted frame editable. That the real editor honours it — and
+ // keeps honouring the effect afterwards — is covered in NotesWindow.editable.test.tsx.
expect(tiptapState.options?.editable).toBe(false);
expect(setEditable).toHaveBeenLastCalledWith(false, false);
expect(setEditable).not.toHaveBeenCalledWith(true, false);