mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 00:22:31 +00:00
test(webui): cover randomUUID entry shim fallback
Add a focused regression test for the non-secure-context WebUI entry shim so missing crypto.randomUUID no longer depends on manual verification. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
5ea2c37325
commit
6d07aa6059
42
webui/src/tests/main-randomuuid.test.tsx
Normal file
42
webui/src/tests/main-randomuuid.test.tsx
Normal file
@ -0,0 +1,42 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const render = vi.fn();
|
||||
const createRoot = vi.fn(() => ({ render }));
|
||||
|
||||
vi.mock("react-dom/client", () => ({
|
||||
default: { createRoot },
|
||||
}));
|
||||
|
||||
vi.mock("@/App", () => ({
|
||||
default: () => null,
|
||||
}));
|
||||
|
||||
describe("main entry crypto shim", () => {
|
||||
const originalRandomUUID = globalThis.crypto.randomUUID;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
createRoot.mockClear();
|
||||
render.mockClear();
|
||||
document.body.innerHTML = '<div id="root"></div>';
|
||||
delete (globalThis.crypto as Crypto & { randomUUID?: Crypto["randomUUID"] }).randomUUID;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(globalThis.crypto, "randomUUID", {
|
||||
value: originalRandomUUID,
|
||||
configurable: true,
|
||||
});
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
it("installs a randomUUID fallback when the browser omits it", async () => {
|
||||
await import("../main");
|
||||
|
||||
expect(globalThis.crypto.randomUUID).toEqual(expect.any(Function));
|
||||
expect(globalThis.crypto.randomUUID()).toMatch(
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
|
||||
);
|
||||
expect(createRoot).toHaveBeenCalledWith(document.getElementById("root"));
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user