Implements the accepted memory-resident room and access model on the single screener-v8 Browser wire. Local repository, full Web, build, and Chrome access/privacy gates passed before merge.
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
readCreationProfile,
|
|
saveCreationProfile,
|
|
} from "../src/client/lib/creation-profile.ts";
|
|
|
|
describe("Host creation profile", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("defaults to open code entry without a room password", () => {
|
|
vi.stubGlobal("window", {
|
|
localStorage: { getItem: () => null },
|
|
});
|
|
|
|
expect(readCreationProfile()).toEqual({
|
|
codeEntryPolicy: "open",
|
|
roomPassword: null,
|
|
});
|
|
});
|
|
|
|
it("persists the accepted creation preferences in same-origin storage", () => {
|
|
const values = new Map<string, string>();
|
|
vi.stubGlobal("window", {
|
|
localStorage: {
|
|
getItem: (key: string) => values.get(key) ?? null,
|
|
setItem: (key: string, value: string) => values.set(key, value),
|
|
removeItem: (key: string) => values.delete(key),
|
|
},
|
|
});
|
|
|
|
saveCreationProfile({
|
|
codeEntryPolicy: "password",
|
|
roomPassword: "room-password",
|
|
});
|
|
|
|
expect(readCreationProfile()).toEqual({
|
|
codeEntryPolicy: "password",
|
|
roomPassword: "room-password",
|
|
});
|
|
expect(values.get("screener:host-creation-profile:v1")).not.toContain(
|
|
"SITE_ACCESS_PASSWORD",
|
|
);
|
|
});
|
|
|
|
it("discards malformed or incomplete password-policy records", () => {
|
|
const removeItem = vi.fn();
|
|
vi.stubGlobal("window", {
|
|
localStorage: {
|
|
getItem: () =>
|
|
JSON.stringify({ codeEntryPolicy: "password", roomPassword: null }),
|
|
removeItem,
|
|
},
|
|
});
|
|
|
|
expect(readCreationProfile()).toEqual({
|
|
codeEntryPolicy: "open",
|
|
roomPassword: null,
|
|
});
|
|
expect(removeItem).toHaveBeenCalledOnce();
|
|
});
|
|
});
|