Files
Piik/tests/creation-profile.test.ts
T
AAA d9cdb55cfc feat(rooms): finish Browser v12 room and UI controls
* feat(rooms): simplify code entry

* fix(host): clarify room entry labels

* docs(rooms): decouple access management from sharing

* feat(host): streamline room and quality controls

* docs(rooms): define private code entry

* feat(rooms): support private invitation-only entry

* docs(ui): unify viewer connection details

* feat(ui): unify viewer connection details

* docs(todo): queue product UI polish

* docs(route): settle local observation boundaries

* docs(rooms): align private entry truth
2026-08-25 01:50:57 +08:00

71 lines
1.8 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: "private",
roomPassword: "room-password",
});
expect(readCreationProfile()).toEqual({
codeEntryPolicy: "private",
roomPassword: "room-password",
});
expect(values.get("screener:host-creation-profile:v1")).not.toContain(
"SITE_ACCESS_PASSWORD",
);
saveCreationProfile({ codeEntryPolicy: "private", roomPassword: null });
expect(readCreationProfile()).toEqual({
codeEntryPolicy: "private",
roomPassword: null,
});
});
it("discards removed 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();
});
});