@frankieai/react 0.2.16 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frankie.css +1 -1
- package/dist/index.cjs +121 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +71 -27
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/chat/ChatEmptyState.tsx +1 -1
- package/src/components/chat/ChatPanel.tsx +2 -2
- package/src/components/chat/FrankieChatPage.tsx +5 -3
- package/src/components/chat/FrankieInline.tsx +4 -4
- package/src/components/chat/FrankieWidget.tsx +4 -4
- package/src/generated/css-content.ts +1 -1
- package/src/hooks/FrankieProvider.tsx +17 -3
- package/src/index.ts +1 -1
- package/src/lib/theme-inherit.test.ts +31 -2
- package/src/lib/theme-inherit.ts +53 -13
- package/src/lib/theme.ts +22 -1
- package/src/styles/frankie.css +16 -0
- package/src/theme-ready.test.tsx +36 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { act, render, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { FrankieProvider } from "./hooks/FrankieProvider.js";
|
|
4
|
+
import { FrankieWidget } from "./components/chat/FrankieWidget.js";
|
|
5
|
+
import { __resetFrankieStylesForTests } from "./lib/ensure-frankie-styles.js";
|
|
6
|
+
|
|
7
|
+
/** Answer the stylesheet sentinel as a browser with our CSS loaded would. */
|
|
8
|
+
function stylesLoaded() {
|
|
9
|
+
const real = window.getComputedStyle.bind(window);
|
|
10
|
+
vi.spyOn(window, "getComputedStyle").mockImplementation((el: Element, pseudo?: string | null) => {
|
|
11
|
+
const style = real(el, pseudo ?? undefined);
|
|
12
|
+
return { ...style, getPropertyValue: (property: string) => (property === "--frankie-styles-ready" ? "1" : style.getPropertyValue(property)) } as CSSStyleDeclaration;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
afterEach(() => { vi.restoreAllMocks(); __resetFrankieStylesForTests(); });
|
|
17
|
+
|
|
18
|
+
describe("first paint", () => {
|
|
19
|
+
it("keeps the widget invisible until its theme is known, so OS dark mode never flashes first", async () => {
|
|
20
|
+
stylesLoaded();
|
|
21
|
+
// The visitor's OS prefers dark; the workspace says light.
|
|
22
|
+
vi.spyOn(window, "matchMedia").mockImplementation((query: string) => ({ matches: query.includes("dark"), media: query, addEventListener() {}, removeEventListener() {} }) as unknown as MediaQueryList);
|
|
23
|
+
let answer: (response: Response) => void = () => {};
|
|
24
|
+
const fetchImpl = vi.fn(() => new Promise<Response>((resolve) => { answer = resolve; }));
|
|
25
|
+
const { container } = render(<FrankieProvider publishableKey="pk_test" baseUrl="https://frankie.test" fetchImpl={fetchImpl as unknown as typeof fetch}><FrankieWidget /></FrankieProvider>);
|
|
26
|
+
const root = container.querySelector(".frankie-widget") as HTMLElement;
|
|
27
|
+
await waitFor(() => expect(root.dataset.frankieStyles).toBe("ready"));
|
|
28
|
+
expect(root.style.opacity).toBe("0");
|
|
29
|
+
|
|
30
|
+
await act(async () => {
|
|
31
|
+
answer(new Response(JSON.stringify({ tenantId: "acme", branding: { name: "Acme" }, theme: { mode: "light" }, auth: { mode: "anonymous" } }), { status: 200, headers: { "content-type": "application/json" } }));
|
|
32
|
+
});
|
|
33
|
+
await waitFor(() => expect(root.style.opacity).toBe(""));
|
|
34
|
+
expect(root.dataset.frankieMode).toBe("light");
|
|
35
|
+
});
|
|
36
|
+
});
|