fix(ai-toolbar): finalize normalized clipboard test coverage

This commit is contained in:
2026-04-23 10:38:35 -04:00
parent 251520fd29
commit 71e4133d57
4 changed files with 40 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
import { afterEach, beforeEach, expect, mock } from "bun:test";
import * as React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import type { CalendarEvent } from "@/lib/types";
export type AIToolbarProps = {
adminAiEnabled: boolean;
@@ -19,7 +20,7 @@ export type AIToolbarProps = {
onSummaryDismiss: () => void;
summary: string | null;
summaryUpdated: string | null;
events: Array<{ id?: string }>;
events: CalendarEvent[];
};
const actualReact = React;
@@ -63,7 +64,7 @@ export const registerAIToolbarEffectHooks = () => {
globalThis.document = {
addEventListener: documentAddEventListener,
removeEventListener: documentRemoveEventListener,
} as Document;
} as unknown as Document;
documentAddEventListener.mockImplementation(
(
type: string,
@@ -102,7 +103,7 @@ export const registerAIToolbarMarkupHooks = () => {
globalThis.document = {
addEventListener: () => {},
removeEventListener: () => {},
} as Document;
} as unknown as Document;
mock.module("@/hooks/use-mobile", () => ({
useIsMobile: () => false,
}));
@@ -276,10 +277,16 @@ export const createDocumentKeydownEvent = (
metaKey: false,
shiftKey: false,
altKey: false,
target: { tagName: "DIV", isContentEditable: false },
target: { tagName: "DIV", isContentEditable: false } as unknown as EventTarget,
...overrides,
}) as unknown as KeyboardEvent;
export const setMockNavigatorClipboardRead = (read: () => Promise<unknown>) => {
(globalThis as { navigator?: Navigator }).navigator = {
clipboard: { read },
} as unknown as Navigator;
};
const escapeForRegex = (value: string) =>
value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");