import { afterAll, describe, expect, test } from "bun:test";
import { GlobalRegistrator } from "@happy-dom/global-registrator";
// The DOM comes first: dialogs and menus portal only where a document existed at load.
const ownsDom = !GlobalRegistrator.isRegistered;
if (ownsDom) GlobalRegistrator.register();
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
true;
window.matchMedia = ((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener() {},
removeListener() {},
addEventListener() {},
removeEventListener() {},
dispatchEvent: () => false,
})) as typeof window.matchMedia;
const { act } = await import("react");
const { createRoot } = await import("react-dom/client");
afterAll(() => {
if (ownsDom) GlobalRegistrator.unregister();
});
const { MeetingsListPage } = await import("./meetings-list-page");
const { MeetingDetailPage } = await import("./meeting-detail-page");
const {
createMeetingRecorderStore,
MeetingRecorderProvider,
MeetingRecorderStoreProvider,
useMeetingRecorder,
useMeetingRecorderControls,
} = await import("./recorder-context");
const { createMeetingsFixture, ELSEWHERE_RECORDING_ID, FAILED_RECORDING_ID } =
await import("../testing/meetings-fixture");
async function render(node: React.ReactNode, host?: (container: HTMLElement) => void) {
const container = document.createElement("div");
host?.(container);
document.body.append(container);
const root = createRoot(container);
const store = createMeetingRecorderStore();
await act(async () => {
root.render({node});
});
return {
container,
store,
rerender: async (next: React.ReactNode) => {
await act(async () => {
root.render(
{next},
);
});
},
unmount: async () => {
await act(async () => root.unmount());
container.remove();
},
};
}
async function settle(milliseconds = 400) {
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, milliseconds));
});
}
/** Wait until the page shows `text`: each read in the fixture takes 120 ms. */
async function waitForText(container: HTMLElement, text: string, timeout = 3_000) {
const deadline = Date.now() + timeout;
while (!(container.textContent ?? "").includes(text)) {
if (Date.now() > deadline) throw new Error(`Timed out waiting for "${text}"`);
await settle(50);
}
}
async function waitFor(check: () => boolean, timeout = 3_000) {
const deadline = Date.now() + timeout;
while (!check()) {
if (Date.now() > deadline) throw new Error("Timed out waiting");
await settle(50);
}
}
/** Picks Summary, Transcript or Notepad under the meeting's title. */
async function openTab(container: HTMLElement, name: "Summary" | "Transcript" | "Notepad") {
const tab = [
...container.querySelectorAll('[data-slot="segmented-control-item"]'),
].find((item) => item.textContent?.trim() === name);
if (!tab) throw new Error(`No ${name} tab`);
await act(async () => tab.click());
}
function checkedTab(container: HTMLElement): string | null {
return (
container
.querySelector('[data-slot="segmented-control-item"][aria-checked="true"]')
?.textContent?.trim() ?? null
);
}
/** Types into a field the way react-dom notices. */
async function typeInto(field: HTMLInputElement | HTMLTextAreaElement, value: string) {
await act(async () => {
// react-dom watches the focused field for typing.
field.focus();
const prototype =
field instanceof window.HTMLTextAreaElement
? window.HTMLTextAreaElement.prototype
: window.HTMLInputElement.prototype;
Object.getOwnPropertyDescriptor(prototype, "value")!.set!.call(field, value);
field.dispatchEvent(new window.Event("input", { bubbles: true }));
});
}
describe("Meetings list", () => {
test("takes its surfaces from the host page, as the embedded chat does", async () => {
const fixture = createMeetingsFixture();
const page = (
`/meetings/${id}`}
onOpen={() => {}}
/>
);
// A dark host page darker than Opengeni's own page grey: the sticky bars
// and the page background become the host's color, not grey boxes.
const hosted = await render(page, (container) => {
container.setAttribute("data-og-theme", "dark");
container.style.backgroundColor = "rgb(26, 26, 25)";
});
// Inside Opengeni's own content pane, whose page background is already
// its own canvas, nothing is restyled.
const inApp = await render(page, (container) => {
container.setAttribute("data-og-theme", "dark");
container.style.backgroundColor = "rgb(32, 32, 32)";
container.style.setProperty("--og-color-bg", "#202020");
});
try {
await settle();
const hostedRoot = hosted.container.querySelector("[data-og-host-theme]");
expect(hostedRoot?.classList.contains("og-root")).toBe(true);
expect(hostedRoot?.style.getPropertyValue("--og-color-bg")).toBe("rgb(26 26 25)");
expect(hostedRoot?.style.getPropertyValue("--og-color-canvas")).toBe("rgb(26 26 25)");
expect(hostedRoot?.querySelectorAll("[data-og-host-theme]")).toHaveLength(0);
const inAppRoot = inApp.container.querySelector("[data-og-host-theme]");
expect(inAppRoot?.style.getPropertyValue("--og-color-bg")).toBe("");
expect(inAppRoot?.getAttribute("data-og-theme")).toBeNull();
} finally {
await hosted.unmount();
await inApp.unmount();
}
});
test("lists meetings with their state and opens one", async () => {
const fixture = createMeetingsFixture();
const opened: string[] = [];
const view = await render(
`/meetings/${id}`}
onOpen={(id) => opened.push(id)}
/>,
);
try {
await settle();
const text = view.container.textContent ?? "";
expect(text).toContain("Weekly product sync");
expect(text).toContain("Transcribing");
expect(text).toContain("Transcript failed");
// The recorder waits for its capture code before offering Start recording.
const start = [...view.container.querySelectorAll("button")].find((button) =>
button.textContent?.includes("Start recording"),
);
expect(start?.disabled).toBe(true);
const row = view.container.querySelector(`a[href="/meetings/${fixture.readyId}"]`);
expect(row).not.toBeNull();
await act(async () => {
row!.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
});
expect(opened).toEqual([fixture.readyId]);
} finally {
await view.unmount();
}
});
test("the person's own Only me meetings from other workspaces are listed here and open in place", async () => {
const fixture = createMeetingsFixture({ otherWorkspaces: true });
const opened: string[] = [];
const view = await render(
`/meetings/${id}`}
onOpen={(id) => opened.push(id)}
/>,
);
try {
await waitForText(view.container, "Pipeline review");
const text = view.container.textContent ?? "";
// In the normal list, not a separate section, labelled with where they are stored.
expect(text).not.toContain("From other workspaces");
expect(text).toContain("Only me, recorded in Sales");
const row = [...view.container.querySelectorAll("a[href]")].find(
(element) => element.textContent?.includes("Pipeline review"),
)!;
expect(row.getAttribute("href")).toBe(`/meetings/${ELSEWHERE_RECORDING_ID}`);
await act(async () => {
row.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
});
expect(opened).toEqual([ELSEWHERE_RECORDING_ID]);
} finally {
await view.unmount();
}
});
test("an Only me meeting from another workspace opens here, says where it lives and can't be shared here", async () => {
const fixture = createMeetingsFixture({ otherWorkspaces: true });
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "recorded in Sales");
expect(view.container.textContent).toContain("Only me · recorded in Sales");
// Sharing it with a workspace happens where it is stored.
expect(view.container.querySelector('[aria-label^="Who can see this"]')).toBeNull();
} finally {
await view.unmount();
}
});
test("the owner chooses where their Only me meeting works, and leaves a workspace they turn it off in", async () => {
const fixture = createMeetingsFixture({ otherWorkspaces: true });
const personal = "c3d4e5f6-a7b8-4c9d-8e0f-2a3b4c5d6e7f";
const left: string[] = [];
const page = (reachWorkspaces?: { id: string; name: string; personal?: boolean }[]) => (
left.push("back")}
/>
);
const openMenu = async (container: HTMLElement) => {
const trigger = container.querySelector(
'[aria-label="More actions for Pipeline review"]',
);
await act(async () => {
trigger!.dispatchEvent(
new PointerEvent("pointerdown", { bubbles: true, button: 0, pointerType: "mouse" }),
);
});
await settle(50);
return [...document.querySelectorAll('[role="menuitem"]')];
};
// Without the person's workspaces, the page doesn't offer the choice.
const bare = await render(page());
try {
await waitForText(bare.container, "recorded in Sales");
const items = await openMenu(bare.container);
expect(items.map((item) => item.textContent?.trim())).not.toContain("Available in…");
await act(async () => {
document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
});
await settle(50);
} finally {
await bare.unmount();
}
const view = await render(
page([
{ id: fixture.workspaceId, name: "Design" },
{ id: "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", name: "Sales" },
{ id: personal, name: "Ingrid", personal: true },
]),
);
try {
await waitForText(view.container, "recorded in Sales");
const item = (await openMenu(view.container)).find(
(candidate) => candidate.textContent?.trim() === "Available in…",
);
expect(item).toBeDefined();
await act(async () => item!.click());
await settle(100);
const dialog = document.querySelector('[role="dialog"]')!;
const text = dialog.textContent ?? "";
expect(text).toContain("It stays Only me");
expect(text).toContain("Belongs to you. Only you manage it.");
// The workspace storing it is always ticked; Personal always has it, so no row.
const box = (label: string) => {
const element = [...dialog.querySelectorAll("label")].find(
(each) => each.textContent === label,
);
return element ? (document.getElementById(element.htmlFor) as HTMLInputElement) : null;
};
expect(box("Sales")?.disabled).toBe(true);
expect(box("Sales")?.checked).toBe(true);
expect(box("Your Personal workspace")).toBeNull();
expect(text).not.toContain("will no longer show");
// Turning it off where it was opened says it will leave, then leaves.
await act(async () => box("Design (this workspace)")!.click());
expect(dialog.textContent).toContain("It will no longer show in this workspace");
const save = [...dialog.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Save",
)!;
await act(async () => save.click());
await waitFor(() => left.length > 0);
expect(left).toEqual(["back"]);
const saved = await fixture.client.getRecording(fixture.workspaceId, ELSEWHERE_RECORDING_ID);
expect(saved.reachWorkspaceIds).toEqual([]);
} finally {
await view.unmount();
}
});
test("search finds meetings by transcript words and says what it searches", async () => {
const fixture = createMeetingsFixture();
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
const search = async (text: string) => {
const input = view.container.querySelector(
'input[aria-label="Search meetings"]',
)!;
await act(async () => {
// react-dom watches the focused field for typing.
input.focus();
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")!.set!.call(
input,
text,
);
input.dispatchEvent(new window.Event("input", { bubbles: true }));
// react-dom loads before the DOM here, so it reads typing from key events.
input.dispatchEvent(new window.KeyboardEvent("keyup", { bubbles: true }));
});
// Past the typing pause, then until the new list has loaded.
await settle(400);
const deadline = Date.now() + 3_000;
while ((view.container.textContent ?? "").includes("Loading meetings")) {
if (Date.now() > deadline) throw new Error("Timed out waiting for the search");
await settle(50);
}
};
try {
await waitForText(view.container, "Weekly product sync");
// Spoken in the meeting, not in any title, and only the start of a word.
await search("annual disc");
const found = view.container.textContent ?? "";
expect(found).toContain("Weekly product sync");
expect(found).not.toContain("Transcript failed");
await search("zzz");
expect(view.container.textContent).toContain("Searches titles and transcripts.");
} finally {
await view.unmount();
}
});
test("an empty workspace explains how to start", async () => {
const fixture = createMeetingsFixture({ state: "empty" });
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await settle();
expect(view.container.textContent).toContain("No meetings yet");
} finally {
await view.unmount();
}
});
test("an EU-only workspace without an EU route says Not supported in EU instead of recording", async () => {
const fixture = createMeetingsFixture();
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await waitForText(view.container, "Weekly product sync");
const notice = view.container.querySelector('[data-tone="info"]');
expect(notice?.textContent).toBe("Not supported in EU");
const buttons = [...view.container.querySelectorAll("button")];
expect(buttons.some((button) => button.textContent?.includes("Start recording"))).toBe(false);
} finally {
await view.unmount();
}
});
test("a host can show only its own meetings inside its page, with a reminder at Start", async () => {
const fixture = createMeetingsFixture();
await fixture.client.updateRecording(fixture.workspaceId, fixture.readyId, {
externalRef: "project:42",
});
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
externalRef="project:42"
header={false}
notice="Tell the people present that you're recording."
/>,
);
try {
await waitForText(view.container, "Weekly product sync");
const text = view.container.textContent ?? "";
expect(text).not.toContain("Transcript failed");
expect(text).toContain("Tell the people present that you're recording.");
expect(view.container.querySelector("h1")).toBeNull();
} finally {
await view.unmount();
}
});
test("a host that doesn't let this person record says why, and still lists the meetings", async () => {
const fixture = createMeetingsFixture();
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
recordingOff="An administrator has to turn on meeting recording."
/>,
);
try {
await waitForText(view.container, "Weekly product sync");
const text = view.container.textContent ?? "";
expect(text).toContain("An administrator has to turn on meeting recording.");
const start = [...view.container.querySelectorAll("button")].find((button) =>
/start recording/i.test(button.textContent ?? ""),
);
expect(start).toBeUndefined();
} finally {
await view.unmount();
}
});
});
describe("Recorder provider", () => {
test("records with the host's own client, once the host knows its workspace", async () => {
const requests: string[] = [];
const client = {
requestJson: async (method: string, path: string) => {
requests.push(`${method} ${path}`);
return {};
},
};
const seen: { recorder: ReturnType["recorder"] } = {
recorder: null,
};
function Probe() {
seen.recorder = useMeetingRecorder().recorder;
return null;
}
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
const mount = (workspaceId: string | null) =>
act(async () => {
root.render(
,
);
});
await mount(null);
await settle(100);
expect(seen.recorder).toBeNull();
await mount("workspace-1");
const deadline = Date.now() + 3_000;
while (!seen.recorder && Date.now() < deadline) await settle(50);
expect(seen.recorder?.state).toBe("idle");
await act(async () => root.unmount());
container.remove();
});
test("Stop on a recording made in another workspace opens it in that workspace", async () => {
const fixture = createMeetingsFixture();
const openedElsewhere: string[] = [];
const openedHere: string[] = [];
const store = createMeetingRecorderStore(
() => {},
(recordingId, workspaceId) => {
openedElsewhere.push(`${workspaceId}/${recordingId}`);
return true;
},
);
let state: "recording" | "stopped" = "recording";
const recorder = {
get state() {
return state;
},
recordingId: "recording-elsewhere",
supported: true,
title: null,
tracks: [],
elapsedMilliseconds: 61_000,
systemAudioKind: null,
upload: { created: true },
recovered: [],
uploads: {},
retryUpload: () => false,
live: null,
error: null,
stop: async () => {
state = "stopped";
},
pause: () => {},
resume: () => {},
} as unknown as ReturnType["recorder"];
store.set(recorder, "workspace-elsewhere");
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
await act(async () => {
root.render(
`/meetings/${id}`}
onOpen={(id) => openedHere.push(id)}
/>
,
);
});
try {
const stop = [...container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Stop",
);
expect(stop).toBeDefined();
await act(async () => {
stop!.click();
});
await settle(50);
expect(openedElsewhere).toEqual(["workspace-elsewhere/recording-elsewhere"]);
expect(openedHere).toEqual([]);
} finally {
await act(async () => root.unmount());
container.remove();
}
});
test("Start recording from the app's actions starts what the button starts, after a stopped recording too", async () => {
const fixture = createMeetingsFixture();
const store = createMeetingRecorderStore();
let state: "stopped" | "recording" = "stopped";
const starts: Array> = [];
const recorder = {
get state() {
return state;
},
recordingId: "recording-earlier",
supported: true,
title: null,
tracks: [],
elapsedMilliseconds: 0,
systemAudioKind: null,
systemAudioSupported: false,
upload: null,
recovered: [],
uploads: {},
retryUpload: () => false,
live: null,
error: null,
start: async (options: Record) => {
starts.push(options);
},
stop: async () => {},
pause: () => {},
resume: () => {},
} as unknown as ReturnType["recorder"];
store.set(recorder, fixture.workspaceId);
let controls: ReturnType = null;
function Controls() {
controls = useMeetingRecorderControls();
return null;
}
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
const page = (
`/meetings/${id}`}
onOpen={() => {}}
/>
);
try {
await act(async () => root.render(page));
await waitForText(container, "Start recording");
expect(controls).not.toBeNull();
expect(controls!.state).toBe("stopped");
expect(controls!.supported).toBe(true);
// The button's start...
const button = [...container.querySelectorAll("button")].find(
(candidate) => candidate.textContent?.trim() === "Start recording",
);
await act(async () => button!.click());
await waitFor(() => starts.length === 1);
// ...and the action's, through the same panel, with the same options.
await act(async () => controls!.requestStart());
await waitFor(() => starts.length === 2);
expect(store.pendingStart()).toBeNull();
expect(starts[1]).toEqual(starts[0]!);
// Neither makes up a name: Opengeni names the meeting, from the
// calendar or the conversation, so a made-up one never hides it.
expect(starts[0]!.title).toBeUndefined();
expect(starts[0]!.titleSource).toBeUndefined();
// While one records, the action asks for no second start.
state = "recording";
await act(async () => store.set(recorder, fixture.workspaceId));
await act(async () => controls!.requestStart());
expect(store.pendingStart()).toBeNull();
} finally {
await act(async () => root.unmount());
container.remove();
}
});
test("Stop recording from the app's actions stops and opens the meeting in its workspace", async () => {
const opened: string[] = [];
const store = createMeetingRecorderStore(
() => {},
(recordingId, workspaceId) => {
opened.push(`${workspaceId}/${recordingId}`);
return true;
},
);
let stops = 0;
const recorder = {
state: "paused",
recordingId: "recording-now",
supported: true,
stop: async () => {
stops += 1;
},
} as unknown as ReturnType["recorder"];
store.set(recorder, "workspace-recorded");
let controls: ReturnType = null;
function Controls() {
controls = useMeetingRecorderControls();
return null;
}
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
try {
// Without a recorder provider there is nothing to control.
await act(async () => root.render());
expect(controls).toBeNull();
await act(async () =>
root.render(
,
),
);
await act(async () => controls!.stop());
expect(stops).toBe(1);
expect(opened).toEqual(["workspace-recorded/recording-now"]);
// A host without a way to open meetings hears which one to open itself.
const bare = createMeetingRecorderStore();
bare.set({ ...recorder!, state: "recording" } as typeof recorder, "workspace-bare");
await act(async () =>
root.render(
,
),
);
const result: { stopped: unknown } = { stopped: undefined };
await act(async () => {
result.stopped = await controls!.stop();
});
expect(result.stopped).toEqual({
recordingId: "recording-now",
workspaceId: "workspace-bare",
opened: false,
});
} finally {
await act(async () => root.unmount());
container.remove();
}
});
test("a start that is still waiting never begins a second recording after the button's recording stops", async () => {
const fixture = createMeetingsFixture();
const store = createMeetingRecorderStore();
let state: "idle" | "recording" | "stopped" = "idle";
const starts: Array> = [];
const recorder = {
get state() {
return state;
},
recordingId: "recording-now",
supported: true,
title: null,
tracks: [],
elapsedMilliseconds: 0,
systemAudioKind: null,
systemAudioSupported: false,
upload: null,
recovered: [],
uploads: {},
retryUpload: () => false,
live: null,
error: null,
start: async (options: Record) => {
starts.push(options);
},
stop: async () => {},
pause: () => {},
resume: () => {},
} as unknown as ReturnType["recorder"];
store.set(recorder, fixture.workspaceId);
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
try {
await act(async () =>
root.render(
`/meetings/${id}`}
onOpen={() => {}}
/>
,
),
);
// The key asks for a start while the page still loads its models...
act(() => store.requestStart({ title: "" }));
// ...and the person clicks Start before it happens.
const button = [...container.querySelectorAll("button")].find(
(candidate) => candidate.textContent?.trim() === "Start recording",
);
await act(async () => button!.click());
expect(starts).toHaveLength(1);
state = "recording";
await act(async () => store.set(recorder, fixture.workspaceId));
expect(store.pendingStart()).toBeNull();
state = "stopped";
await act(async () => store.set(recorder, fixture.workspaceId));
await settle(500);
expect(starts).toHaveLength(1);
} finally {
await act(async () => root.unmount());
container.remove();
}
});
test("the key's start keeps a title already typed, as the button does", async () => {
const fixture = createMeetingsFixture();
const store = createMeetingRecorderStore();
const starts: Array> = [];
const recorder = {
state: "idle",
recordingId: null,
supported: true,
title: null,
tracks: [],
elapsedMilliseconds: 0,
systemAudioKind: null,
systemAudioSupported: false,
upload: null,
recovered: [],
uploads: {},
retryUpload: () => false,
live: null,
error: null,
start: async (options: Record) => {
starts.push(options);
},
stop: async () => {},
pause: () => {},
resume: () => {},
} as unknown as ReturnType["recorder"];
store.set(recorder, fixture.workspaceId);
const view = await (async () => {
const container = document.createElement("div");
document.body.append(container);
const root = createRoot(container);
await act(async () =>
root.render(
`/meetings/${id}`}
onOpen={() => {}}
/>
,
),
);
return { container, root };
})();
try {
await waitForText(view.container, "Start recording");
const field = view.container.querySelector(
'input[placeholder="Name this meeting, or it\'s named for you"]',
);
expect(field).not.toBeNull();
// A call app's name, with nothing typed, is sent as the app's guess.
await act(async () => store.requestStart({ title: "Zoom meeting", titleSource: "app" }));
await waitFor(() => starts.length === 1);
expect(starts[0]).toMatchObject({ title: "Zoom meeting", titleSource: "app" });
expect(field!.value).toBe("");
starts.length = 0;
await typeInto(field!, "Design review");
await act(async () => store.requestStart({ title: "" }));
await waitFor(() => starts.length === 1);
expect(starts[0]!.title).toBe("Design review");
expect(starts[0]!.titleSource).toBeUndefined();
// A call app's guess never replaces a name someone typed.
starts.length = 0;
await act(async () => store.requestStart({ title: "Zoom meeting", titleSource: "app" }));
await waitFor(() => starts.length === 1);
expect(starts[0]).toMatchObject({ title: "Design review" });
expect(starts[0]!.titleSource).toBeUndefined();
} finally {
await act(async () => view.root.unmount());
view.container.remove();
}
});
});
describe("Meeting page", () => {
test("shows the host's own details beside the transcript", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
details={(recording) => [
{ id: "project", label: "Project", content: `Linked to ${recording.title}` },
]}
/>,
);
try {
await waitForText(view.container, "Linked to Weekly product sync");
expect(view.container.textContent).toContain("Project");
} finally {
await view.unmount();
}
});
test("shows the transcript with named and unnamed speakers", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
// The transcript has loaded once the header counts its speakers.
await waitForText(view.container, "4 speakers");
await openTab(view.container, "Transcript");
const text = view.container.textContent ?? "";
expect(text).toContain("Weekly product sync");
expect(text).toContain("Ingrid Solberg");
expect(text).toContain("Tomas Eriksen");
expect(text).toContain("Speaker 2");
expect(text).toContain("Version 1");
expect(text).toContain("4 speakers");
// Speakers still to name sit at the top of the transcript, and each
// unnamed turn says it can be named.
const review = view.container.querySelector('[aria-label="Speakers to review"]');
expect(review?.textContent).toContain("Speaker 2");
expect(review?.textContent).not.toContain("Tomas Eriksen");
expect(text).toContain("Who spoke? 1 speaker to name, 1 name to confirm.");
expect(
view.container.querySelectorAll('ol [aria-label="Speaker 2, name this speaker"]').length,
).toBeGreaterThan(0);
// The owner controls who can see it.
expect(view.container.querySelector('[aria-label^="Who can see this"]')).not.toBeNull();
} finally {
await view.unmount();
}
});
test("opens on the Summary an agent wrote, and the notepad saves as you type", async () => {
const fixture = createMeetingsFixture();
const opened: string[] = [];
const view = await render(
{}}
onOpenChat={(sessionId) => opened.push(sessionId)}
/>,
);
try {
await waitForText(view.container, "mocks both pricing tables");
expect(checkedTab(view.container)).toBe("Summary");
const text = view.container.textContent ?? "";
expect(text).toContain("Written by an agent");
expect(text).toContain("Action items");
// The transcript and the notepad wait in their own tabs.
expect(view.container.querySelector('ol[aria-label="Transcript"]')).toBeNull();
expect(view.container.querySelector('textarea[placeholder^="Jot down"]')).toBeNull();
const openChat = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent === "Open the chat",
)!;
await act(async () => openChat.click());
expect(opened).toEqual(["7c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f"]);
await openTab(view.container, "Notepad");
const notepad = view.container.querySelector(
'textarea[placeholder^="Jot down"]',
)!;
expect(notepad.value).toContain("Tomas: schema review");
await typeInto(notepad, `${notepad.value}\n- follow up on onboarding`);
await waitForText(view.container, "Saved");
const saved = await fixture.client.listRecordingNotes(fixture.workspaceId, fixture.readyId);
expect(saved.notes.find((note) => note.kind === "notepad")?.body).toContain(
"follow up on onboarding",
);
await openTab(view.container, "Transcript");
expect(view.container.querySelector('ol[aria-label="Transcript"]')).not.toBeNull();
} finally {
await view.unmount();
}
});
test("opens on the Transcript when there are no written notes, still offering Write notes", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "The audio was deleted on");
await settle(300);
expect(checkedTab(view.container)).toBe("Transcript");
expect(view.container.querySelector('ol[aria-label="Transcript"]')).not.toBeNull();
await openTab(view.container, "Summary");
expect(view.container.textContent).toContain("No notes yet.");
const write = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Write notes",
);
expect(write).toBeDefined();
} finally {
await view.unmount();
}
});
test("the Summary shows mentions as chips with current names, and copies them as plain names", async () => {
const fixture = createMeetingsFixture();
await fixture.client.saveRecordingNote(fixture.workspaceId, fixture.readyId, "notes", {
body: [
"[Tomas](speaker:speaker_0) asked [Someone](speaker:speaker_1) for a draft.",
"",
"- [ ] [T.](person:1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e) sends the numbers",
"- [ ] [Ghost](speaker:speaker_9) and [Nobody](person:00000000-0000-4000-8000-000000000000) stay plain",
].join("\n"),
});
const copied: string[] = [];
const clipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
Object.defineProperty(window.navigator, "clipboard", {
configurable: true,
value: { writeText: async (text: string) => void copied.push(text) },
});
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "stay plain");
// Chips need the speakers, which load with the transcript.
const chips = async () => {
const deadline = Date.now() + 3_000;
while (view.container.querySelectorAll("[data-mention]").length < 3) {
if (Date.now() > deadline) throw new Error("No mention chips");
await settle(50);
}
return [...view.container.querySelectorAll("[data-mention]")].map((chip) => [
chip.getAttribute("data-mention"),
chip.textContent,
]);
};
// Current names, not the names written into the links.
expect(await chips()).toEqual([
["speaker", "Tomas Eriksen"],
["speaker", "Speaker 2"],
["person", "Tomas Eriksen"],
]);
const summary = view.container.textContent ?? "";
expect(summary).toContain("Ghost and Nobody stay plain");
// Never a broken link.
expect(view.container.querySelector('a[href^="speaker:"], a[href^="person:"]')).toBeNull();
expect(summary).not.toContain("unavailable");
const copy = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Copy",
)!;
await act(async () => copy.click());
await settle(50);
expect(copied).toEqual([
[
"Tomas Eriksen asked Speaker 2 for a draft.",
"",
"- [ ] Tomas Eriksen sends the numbers",
"- [ ] Ghost and Nobody stay plain",
].join("\n"),
]);
expect(view.container.textContent).toContain("Copied");
} finally {
await view.unmount();
if (clipboard) Object.defineProperty(window.navigator, "clipboard", clipboard);
else delete (window.navigator as { clipboard?: unknown }).clipboard;
}
});
test("transcript turns read as bubbles under the speaker's name, and the pencil corrects the words", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
// The transcript has loaded once the header counts its speakers.
await waitForText(view.container, "4 speakers");
await openTab(view.container, "Transcript");
const turns = [...view.container.querySelectorAll('ol[aria-label="Transcript"] > li')];
expect(turns.length).toBeGreaterThan(3);
for (const turn of turns) {
// The name once per turn, in the speaker's colour, above one bubble.
expect(turn.querySelectorAll("[data-speaker-name]").length).toBe(1);
const name = turn.querySelector("[data-speaker-name]");
expect(name?.style.getPropertyValue("--speaker-hue")).toStartWith("var(--color-chart-");
expect(name?.className).toContain("var(--speaker-hue)");
expect(turn.querySelectorAll("[data-turn-bubble]").length).toBe(1);
}
const tomas = turns.find((turn) =>
turn.querySelector("[data-speaker-name]")?.textContent?.includes("Tomas Eriksen"),
)!;
const pencil = tomas.querySelector(
'[aria-label^="Correct the words of Tomas Eriksen at"]',
);
// Next to the turn's ⋯ menu.
expect(pencil?.nextElementSibling?.getAttribute("aria-label")).toStartWith(
"More actions for Tomas Eriksen",
);
await act(async () => pencil!.click());
await waitForText(document.body, "Fix what the transcript got wrong");
const dialog = document.body.querySelector('[role="dialog"]');
expect(dialog?.textContent).toContain("Correct the words");
// One field per line of that turn.
const lines = [...(dialog?.querySelectorAll("textarea") ?? [])].map((field) => field.value);
expect(lines.join(" ")).toBe(tomas.querySelector("[data-turn-bubble]")?.textContent ?? "");
} finally {
await view.unmount();
}
});
test("Ask about this meeting hands the host the meeting and the question", async () => {
const fixture = createMeetingsFixture();
const asked: Array<[string, string]> = [];
const without = await render(
{}}
/>,
);
try {
await waitForText(without.container, "mocks both pricing tables");
// Only a host that answers it shows the input.
expect(
without.container.querySelector('input[placeholder="Ask about this meeting"]'),
).toBeNull();
} finally {
await without.unmount();
}
const view = await render(
{}}
onAsk={async (recordingId, question) => {
asked.push([recordingId, question]);
}}
/>,
);
try {
await waitForText(view.container, "mocks both pricing tables");
const input = () =>
view.container.querySelector(
'input[placeholder="Ask about this meeting"]',
);
expect(input()).not.toBeNull();
await openTab(view.container, "Notepad");
expect(input()).toBeNull();
await openTab(view.container, "Transcript");
expect(input()).not.toBeNull();
await typeInto(input()!, " What did we decide on pricing? ");
const send = view.container.querySelector('button[aria-label="Ask"]')!;
expect(send.disabled).toBe(false);
await act(async () => send.click());
await settle(50);
expect(asked).toEqual([[fixture.readyId, "What did we decide on pricing?"]]);
// Taken: the input is ready for the next question.
expect(input()?.value).toBe("");
} finally {
await view.unmount();
}
});
test("Ask keeps the question when the host can't take it", async () => {
const fixture = createMeetingsFixture();
let answer: "decline" | "fail" = "decline";
let calls = 0;
const view = await render(
{}}
onAsk={async () => {
calls += 1;
// Declining means the host has already said why, such as no chat.
if (answer === "decline") return false;
throw new Error("offline");
}}
/>,
);
try {
await waitForText(view.container, "mocks both pricing tables");
const input = view.container.querySelector(
'input[placeholder="Ask about this meeting"]',
)!;
await typeInto(input, "Who owns the pricing table?");
const send = () =>
view.container.querySelector('button[aria-label="Ask"]')!;
await act(async () => send().click());
await settle(50);
expect(calls).toBe(1);
expect(input.value).toBe("Who owns the pricing table?");
answer = "fail";
await act(async () => send().click());
await settle(50);
expect(calls).toBe(2);
expect(input.value).toBe("Who owns the pricing table?");
expect(input.disabled).toBe(false);
} finally {
await view.unmount();
}
});
test("an unsaved Summary edit survives a look at the Transcript", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "mocks both pricing tables");
await waitForText(view.container, "4 speakers");
const summary = () => view.container.querySelector('[data-meeting-tab="summary"]')!;
const edit = [...summary().querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Edit",
)!;
await act(async () => edit.click());
await settle(50);
await typeInto(summary().querySelector("textarea")!, "A draft in progress");
await openTab(view.container, "Transcript");
expect(view.container.querySelector('ol[aria-label="Transcript"]')).not.toBeNull();
await openTab(view.container, "Summary");
expect(summary().querySelector("textarea")?.value).toBe("A draft in progress");
} finally {
await view.unmount();
}
});
test("going straight to another meeting opens on that meeting's own tab", async () => {
const fixture = createMeetingsFixture();
const page = (recordingId: string) => (
{}}
/>
);
const view = await render(page(fixture.readyId));
try {
await waitForText(view.container, "mocks both pricing tables");
expect(checkedTab(view.container)).toBe("Summary");
await openTab(view.container, "Notepad");
// A meeting without written notes, in the same mounted page.
await view.rerender(page("7f8a9b0c-1d2e-4f3a-8b4c-5d6e7f8a9b0c"));
await waitForText(view.container, "The audio was deleted on");
await settle(300);
expect(checkedTab(view.container)).toBe("Transcript");
} finally {
await view.unmount();
}
});
test("a voice suggestion is marked and can be turned down", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "Lea Haugen");
const leaChip = () =>
[...view.container.querySelectorAll("[data-mention]")].map((chip) => chip.textContent);
await waitForText(view.container, "mocks both pricing tables");
await waitForText(view.container, "4 speakers");
expect(leaChip()).toContain("Lea Haugen");
const text = view.container.textContent ?? "";
expect(text).toContain("Suggested by voice");
const notThem = view.container.querySelector(
'[aria-label="Not Lea Haugen"]',
);
expect(notThem).not.toBeNull();
await act(async () => notThem!.click());
await settle(400);
// The summary follows the speaker's name without being rewritten.
expect(leaChip()).not.toContain("Lea Haugen");
expect(leaChip()).toContain("Speaker 3");
await openTab(view.container, "Transcript");
const after = view.container.textContent ?? "";
expect(after).not.toContain("Suggested by voice");
expect(after).toContain("Speaker 3");
expect(after).toContain("Who spoke? 2 speakers have no name yet.");
} finally {
await view.unmount();
}
});
test("someone else's shared meeting has no visibility control", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await settle(700);
expect(view.container.querySelector('[aria-label^="Who can see this"]')).toBeNull();
expect(view.container.textContent).toContain("Shared with the workspace");
} finally {
await view.unmount();
}
});
test("a meeting whose audio retention deleted keeps its transcript and says why", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "The audio was deleted on");
expect(view.container.textContent).toContain("retention setting");
const again = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Transcribe again",
);
expect(again?.disabled).toBe(true);
} finally {
await view.unmount();
}
});
test("a missing provider key names the model and the provider that isn't connected", async () => {
const fixture = createMeetingsFixture();
const missingKey = (recording: T): T => ({
...recording,
transcript: {
...(recording.transcript as object),
errorCode: "missing_provider_key",
},
});
const client = {
...fixture.client,
getRecording: async (workspaceId: string, id: string) =>
missingKey(await fixture.client.getRecording(workspaceId, id)),
} as typeof fixture.client;
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "needs ElevenLabs");
const text = view.container.textContent ?? "";
expect(text).toContain("Scribe v2 needs ElevenLabs, which isn't connected.");
expect(text).toContain("Try another model");
expect(text).not.toContain("No transcription provider is connected");
} finally {
await view.unmount();
}
});
test("while a meeting is processed, the player waits until every recorded track can play", async () => {
const fixture = createMeetingsFixture();
const listed = await fixture.client.listRecordings(fixture.workspaceId);
const processing = listed.recordings.find((entry) => entry.state === "processing")!;
// The microphone is ready to play; the computer audio isn't yet.
let playable = new Set([0]);
let reads = 0;
const recordings = {
...fixture.client,
getRecording: async (workspaceId: string, id: string) => {
const found = await fixture.client.getRecording(workspaceId, id);
if (id !== processing.id) return found;
reads += 1;
return {
...found,
tracks: found.tracks.map((track) => ({
...track,
playable: playable.has(track.trackNumber),
})),
};
},
};
const player = (container: HTMLElement) =>
container.querySelector('[aria-label="Position"]') !== null;
const view = await render(
{}}
/>,
);
try {
await waitFor(() => reads > 0);
await settle(600);
// The microphone alone would sound as if the call was never recorded.
expect(player(view.container)).toBe(false);
playable = new Set([0, 1]);
// The page reads the meeting again while it's processed.
await waitFor(() => player(view.container), 6_000);
} finally {
await view.unmount();
}
});
test("a transcript that failed before the audio was prepared can be made again", async () => {
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "The transcript failed");
await settle(300);
expect(view.container.textContent).not.toContain("isn't available anymore");
const again = [...view.container.querySelectorAll("button")].filter(
(button) => button.textContent?.trim() === "Transcribe again",
);
expect(again.length).toBeGreaterThan(0);
for (const button of again) expect(button.disabled).toBe(false);
} finally {
await view.unmount();
}
});
test("a wrong speaker count is fixed by telling it how many people spoke", async () => {
const fixture = createMeetingsFixture();
const asked: unknown[] = [];
const client = {
...fixture.client,
createRecordingTranscript: async (
workspaceId: string,
id: string,
request: { transcription?: unknown },
) => {
asked.push(request.transcription);
return await fixture.client.createRecordingTranscript(workspaceId, id);
},
} as typeof fixture.client;
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "Wrong number of speakers?");
const wrong = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Wrong number of speakers?",
)!;
await act(async () => wrong.click());
await waitForText(document.body, "Number of speakers");
const field = document.body.querySelector('input[inputmode="numeric"]')!;
await typeInto(field, "4");
const submit = [...document.body.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Transcribe",
)!;
await act(async () => submit.click());
await waitFor(() => asked.length === 1);
expect(asked[0]).toMatchObject({ speakers: 4 });
expect(asked[0]).not.toHaveProperty("maxSpeakers");
} finally {
await view.unmount();
}
});
/** The fixture's failed meeting, refused for credits on the deployment's model. */
async function creditRefusal(withSubscription: boolean) {
const fixture = createMeetingsFixture();
const base = await fixture.client.listRecordingModels(fixture.workspaceId);
const scribe = base.models.find((model) => model.model === "scribe_v2")!;
const mai = {
...scribe,
providerId: "azure-speech",
providerName: "Azure Speech",
model: "MAI-Transcribe-2",
name: "MAI-Transcribe-2",
funding: "deployment" as const,
usdPerHour: 0.36,
};
const chatgpt = {
...scribe,
providerId: "codex-subscription",
providerName: "ChatGPT",
model: "chatgpt-dictation",
name: "ChatGPT dictation",
funding: "workspace_subscription" as const,
usdPerHour: null,
};
const asked: unknown[] = [];
const client = {
...fixture.client,
listRecordingModels: async () => ({
...base,
models: withSubscription ? [mai, chatgpt] : [mai],
default: { providerId: "azure-speech", model: "MAI-Transcribe-2" },
}),
getRecording: async (workspaceId: string, id: string) => {
const recording = await fixture.client.getRecording(workspaceId, id);
return {
...recording,
transcript: {
...recording.transcript!,
providerId: "azure-speech",
model: "MAI-Transcribe-2",
errorCode: "insufficient_credits",
},
};
},
createRecordingTranscript: async (
workspaceId: string,
id: string,
request: Parameters[2],
) => {
asked.push(request);
return await fixture.client.createRecordingTranscript(workspaceId, id, request);
},
} as typeof fixture.client;
return { fixture, client, asked };
}
test("a transcript refused for credits says so and transcribes with a model that needs none", async () => {
const { fixture, client, asked } = await creditRefusal(true);
const view = await render(
{}}
onOpenBilling={() => {}}
/>,
);
try {
await waitForText(view.container, "Transcribe with ChatGPT dictation");
const text = view.container.textContent ?? "";
expect(text).toContain(
"MAI-Transcribe-2 uses credits, and this organization is out of them.",
);
// One direct fix: the free model, not a purchase as well.
const labels = [...view.container.querySelectorAll("button")].map((button) =>
button.textContent?.trim(),
);
expect(labels).not.toContain("Add credits");
const fix = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Transcribe with ChatGPT dictation",
)!;
await act(async () => fix.click());
await waitFor(() => asked.length === 1);
expect(asked[0]).toMatchObject({
transcription: { providerId: "codex-subscription", model: "chatgpt-dictation" },
});
} finally {
await view.unmount();
}
});
test("with no model that needs no credits, the fix is adding them", async () => {
const { fixture, client } = await creditRefusal(false);
let opened = 0;
const view = await render(
{}}
onOpenBilling={() => {
opened += 1;
}}
/>,
);
try {
await waitForText(view.container, "Add credits");
const add = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Add credits",
)!;
await act(async () => add.click());
expect(opened).toBe(1);
expect(view.container.textContent).toContain("Transcribe again");
} finally {
await view.unmount();
}
});
test("a refused upload this device finished in the background says why and tries again", async () => {
const { LIVE_RECORDING_ID } = await import("../testing/meetings-fixture");
const fixture = createMeetingsFixture();
const retried: string[] = [];
const failedUpload = {
recordingId: LIVE_RECORDING_ID,
created: true,
pendingChunks: 0,
pendingBytes: 0,
uploading: false,
retryingAfterError: null,
failed: { code: "insufficient_credits", message: "No credits." },
finalized: false,
discarded: false,
};
// The recorder is idle: the meeting was recorded before a reload, and the
// upload that finishes it in the background was refused.
const recorder = {
state: "idle",
recordingId: null,
title: null,
elapsedMilliseconds: 0,
tracks: [],
upload: null,
error: null,
live: null,
supported: true,
systemAudioSupported: false,
systemAudioKind: null,
recovered: [],
uploads: { [LIVE_RECORDING_ID]: failedUpload },
retryUpload: (id: string) => {
retried.push(id);
return true;
},
start: async () => {},
pause: () => {},
resume: () => {},
stop: async () => {},
discard: async () => {},
rename: async () => {},
levels: () => ({}),
} as unknown as NonNullable["recorder"]>;
const view = await render(
{}}
/>,
);
try {
await act(async () => view.store.set(recorder));
await waitForText(view.container, "The upload didn't finish");
const text = view.container.textContent ?? "";
expect(text).toContain("out of credits");
expect(text).toContain("The audio is kept on this device");
const again = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Try again",
)!;
await act(async () => again.click());
expect(retried).toEqual([LIVE_RECORDING_ID]);
// Finishing it in the background reads Uploading from this device, with no action.
await act(async () =>
view.store.set({
...recorder,
uploads: {
[LIVE_RECORDING_ID]: {
...failedUpload,
failed: null,
uploading: true,
pendingChunks: 3,
},
},
}),
);
expect(view.container.textContent).toContain("Uploading the audio from this device.");
} finally {
await view.unmount();
}
});
});
describe("Retention settings", () => {
test("names periods and warns only when a change deletes sooner", async () => {
const { retentionPeriodName, retentionChangeWarning } = await import("./meeting-settings");
expect(retentionPeriodName(30)).toBe("30 days");
expect(retentionPeriodName(365)).toBe("1 year");
expect(retentionPeriodName(730)).toBe("2 years");
expect(retentionChangeWarning(undefined, { transcriptDays: 365 })?.confirmLabel).toBe(
"Delete old meetings",
);
expect(retentionChangeWarning(undefined, { audioDays: 0 })?.title).toBe(
"Delete audio once transcribed?",
);
expect(retentionChangeWarning({ audioDays: 7 }, { audioDays: 30 })).toBeNull();
expect(retentionChangeWarning({ transcriptDays: 90 }, {})).toBeNull();
});
});
describe("Transcription model picker", () => {
test("says who pays for each model, and what makes an unavailable one pickable", async () => {
const { transcriptionModelMeta, transcriptionModelUnavailableReason } =
await import("./meeting-settings");
const entry = {
providerId: "codex-subscription",
providerName: "ChatGPT subscription",
model: "chatgpt-dictation",
name: "ChatGPT dictation",
available: false,
funding: "workspace_subscription" as const,
usdPerHour: 0,
capabilities: {
batch: true,
live: false,
diarization: false,
liveDiarization: false,
multichannel: false,
maxSpeakers: null,
wordTimestamps: false,
languages: [],
languageDetection: true,
keyterms: false,
speakerLibrary: false,
maxDurationSeconds: 600,
maxFileBytes: null,
},
};
expect(transcriptionModelMeta(entry)).toBe("Your subscription");
expect(transcriptionModelUnavailableReason(entry)).toBe(
"Connect your ChatGPT subscription first",
);
const scribe = { ...entry, providerName: "ElevenLabs", funding: "workspace_key" as const };
expect(transcriptionModelMeta({ ...scribe, usdPerHour: 0.22 })).toBe("$0.22 per hour");
expect(transcriptionModelUnavailableReason(scribe)).toBe("Connect ElevenLabs first");
const azure = { ...entry, providerName: "Azure Speech", funding: "deployment" as const };
expect(transcriptionModelMeta(azure)).toBe("Azure Speech");
expect(transcriptionModelUnavailableReason(azure)).toBe(
"Azure Speech isn't available here right now",
);
});
test("transcribing again prices every recorded track, since each is billed on its own", async () => {
const { transcribeAgainEstimate } = await import("./meeting-detail-page");
const hour = 3_600_000;
const track = (trackNumber: number, durationMilliseconds: number, chunkCount = 10) => ({
trackNumber,
kind: "audio" as const,
source: trackNumber === 0 ? ("microphone" as const) : ("system" as const),
mimeType: "audio/webm",
chunkCount,
totalBytes: 1_000,
durationMilliseconds,
playable: true,
video: null,
live: null,
});
// A microphone beside computer audio: two hours of audio for a one-hour meeting.
const both = transcribeAgainEstimate(
{ durationMilliseconds: hour, tracks: [track(0, hour), track(1, hour)] },
0.22,
);
expect(both?.tracks).toBe(2);
expect(both?.usd).toBeCloseTo(0.44, 6);
// A track that never got audio costs nothing.
const micOnly = transcribeAgainEstimate(
{ durationMilliseconds: hour, tracks: [track(0, hour), track(1, 0, 0)] },
0.22,
);
expect(micOnly).toEqual({ usd: 0.22, tracks: 1 });
// Without track details the meeting's length is the audio.
expect(transcribeAgainEstimate({ durationMilliseconds: hour / 2, tracks: [] }, 0.22)).toEqual({
usd: 0.11,
tracks: 1,
});
expect(transcribeAgainEstimate({ durationMilliseconds: hour, tracks: [] }, null)).toBeNull();
});
});
describe("Recorder errors", () => {
test("the desktop app points to the computer's settings, not the browser's", async () => {
const { recorderErrorText } = await import("./recorder-panel");
const denied = { code: "microphone_denied", message: "Permission denied" } as Parameters<
typeof recorderErrorText
>[0];
expect(recorderErrorText(denied, "desktop").body).toContain("your computer's privacy settings");
expect(recorderErrorText(denied, "display").body).toContain("browser");
});
test("the desktop app's reason for no computer audio is said in the viewer's words", async () => {
const { recorderErrorText } = await import("./recorder-panel");
const failure = (reason?: string) =>
({
code: "system_audio_unavailable",
message: "The desktop app's own English sentence.",
...(reason ? { reason } : {}),
}) as Parameters[0];
expect(recorderErrorText(failure("permission_denied"), "desktop")).toEqual({
title: "Computer audio isn't allowed",
body: "Allow this app under System Settings > Privacy & Security > Screen & System Audio Recording, then start again.",
});
expect(recorderErrorText(failure("sound_server_unavailable"), "desktop").body).toBe(
"No sound server (PipeWire or PulseAudio) is running. Start one, or record without computer audio.",
);
expect(recorderErrorText(failure("unavailable"), "desktop").body).toBe(
"This computer can't record its own audio. Record without computer audio instead.",
);
for (const reason of ["capture_failed", undefined]) {
expect(recorderErrorText(failure(reason), "desktop")).toEqual({
title: "Can't record computer audio",
body: "Computer audio didn't start. Start again, or record without computer audio.",
});
}
const translated = (key: string) => `nb:${key}`;
expect(
recorderErrorText(failure("sound_server_unavailable"), "desktop", translated as never),
).toEqual({
title: "nb:meetings.recorderPanel.canTRecordComputerAudio",
body: "nb:meetings.recorderPanel.noSoundServerIsRunning",
});
});
test("a used-up usage allowance says so in the person's words", async () => {
const { uploadFailureReason } = await import("./recorder-panel");
expect(uploadFailureReason("The workspace usage allowance is exhausted.")).toBe(
"The usage allowance is used up, so new meetings can't be transcribed until it renews.",
);
});
});
describe("Live transcript", () => {
/** A recorder on this device, recording the fixture's meeting in progress. */
async function fakeRecorder(
state: "recording" | "paused" | "stopping" | "stopped",
upload: { pendingChunks?: number; finalized?: boolean; retryingAfterError?: string } = {},
) {
const { LIVE_RECORDING_ID } = await import("../testing/meetings-fixture");
const calls: string[] = [];
const recorder = {
state,
recordingId: LIVE_RECORDING_ID,
title: "Platform standup",
elapsedMilliseconds: 754_000,
tracks: [{ trackNumber: 0, source: "microphone", label: "Microphone" }],
upload: {
recordingId: LIVE_RECORDING_ID,
created: true,
pendingChunks: upload.pendingChunks ?? 1,
pendingBytes: 4_000,
uploading: true,
retryingAfterError: upload.retryingAfterError ?? null,
failed: null,
finalized: upload.finalized ?? false,
discarded: false,
},
error: null,
live: null,
supported: true,
systemAudioSupported: false,
systemAudioKind: null,
recovered: [],
uploads: {},
retryUpload: () => false,
start: async () => {},
pause: () => calls.push("pause"),
resume: () => calls.push("resume"),
stop: async () => {
calls.push("stop");
},
discard: async () => {},
rename: async () => {},
levels: () => ({}),
} as unknown as NonNullable["recorder"]>;
return { recorder, calls, recordingId: LIVE_RECORDING_ID };
}
test("taking notes while recording shows it's recording, with Stop, not Uploading", async () => {
const fixture = createMeetingsFixture();
const { recorder, calls, recordingId } = await fakeRecorder("recording");
const view = await render(
{}}
/>,
);
try {
await act(async () => view.store.set(recorder));
await waitForText(view.container, "Platform standup");
const text = view.container.textContent ?? "";
expect(text).not.toContain("Uploading");
expect(text).not.toContain("Not finished yet");
const bar = view.container.querySelector('section[aria-label="Recording"]');
expect(bar?.textContent).toContain("12:34");
const stop = [...bar!.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Stop",
);
expect(stop).toBeDefined();
await act(async () => stop!.click());
expect(calls).toEqual(["stop"]);
// Said once, by the bar, not again beside the title.
expect(text.split("Recording").length - 1).toBe(1);
// Recording here keeps one page: no tabs, the notepad and the live preview.
expect(view.container.querySelector('[data-slot="segmented-control"]')).toBeNull();
expect(view.container.querySelector('textarea[placeholder^="Jot down"]')).not.toBeNull();
await act(async () => view.store.set({ ...recorder, state: "paused" }));
expect(view.container.textContent).toContain("Paused");
expect(view.container.textContent).toContain("Resume");
} finally {
await view.unmount();
}
});
test("after Stop the meeting reads Transcribing, never Uploading", async () => {
const fixture = createMeetingsFixture();
// Stop waits for the last few seconds of audio, then the recorder is stopped.
const { recorder, recordingId } = await fakeRecorder("stopping", { pendingChunks: 1 });
const view = await render(
{}}
/>,
);
try {
await act(async () => view.store.set(recorder));
await waitForText(view.container, "Platform standup");
let text = view.container.textContent ?? "";
expect(text).toContain("Transcribing");
expect(text).not.toContain("Uploading");
expect(view.container.querySelector('section[aria-label="Recording"]')).toBeNull();
await act(async () =>
view.store.set({
...recorder,
state: "stopped",
upload: { ...recorder.upload!, pendingChunks: 0, finalized: true },
}),
);
expect(view.container.textContent).toContain("Transcribing");
// Stopped, it is a meeting like any other, with its tabs, even while
// this recorder still holds the live text it heard.
await act(async () =>
view.store.set({
...recorder,
state: "stopped",
upload: { ...recorder.upload!, pendingChunks: 0, finalized: true },
live: [
{
trackNumber: 0,
state: "closed",
partial: "",
segments: [
{
trackNumber: 0,
segmentNumber: 0,
startMilliseconds: 1_000,
endMilliseconds: 3_000,
text: "Morning, everyone.",
},
],
error: null,
},
],
}),
);
expect(view.container.querySelector('[data-slot="segmented-control"]')).not.toBeNull();
expect(view.container.querySelector('section[aria-label="Recording"]')).toBeNull();
// Only a lost connection keeps it from transcribing, and it says so.
await act(async () =>
view.store.set({
...recorder,
upload: { ...recorder.upload!, retryingAfterError: "Failed to fetch" },
}),
);
text = view.container.textContent ?? "";
expect(text).toContain("Offline");
expect(text).not.toContain("Transcribing.");
} finally {
await view.unmount();
}
});
test("the list says Transcribing for a meeting just stopped here", async () => {
const fixture = createMeetingsFixture();
const { recorder } = await fakeRecorder("stopping", { pendingChunks: 1 });
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await act(async () => view.store.set(recorder));
await waitForText(view.container, "Platform standup");
await settle();
// The widest box around the meeting's title that holds no other meeting.
let row: Element | null = [...view.container.querySelectorAll("a")].find((link) =>
link.textContent?.includes("Platform standup"),
)!;
while (row.parentElement && row.parentElement.querySelectorAll("a").length === 1) {
row = row.parentElement;
}
expect(row.textContent).toContain("Transcribing");
expect(view.container.textContent).not.toContain("Uploading");
} finally {
await view.unmount();
}
});
test("a meeting can be named while it records", async () => {
const { RecorderPanel } = await import("./recorder-panel");
const renamed: string[] = [];
const recorder = {
state: "recording",
recordingId: "r1",
title: null,
elapsedMilliseconds: 61_000,
tracks: [],
upload: null,
error: null,
live: null,
supported: true,
systemAudioSupported: false,
systemAudioKind: null,
recovered: [],
uploads: {},
retryUpload: () => false,
start: async () => {},
pause: () => {},
resume: () => {},
stop: async () => {},
discard: async () => {},
rename: async (title: string) => {
renamed.push(title);
},
levels: () => ({}),
} as unknown as Parameters[0]["recorder"];
const view = await render();
try {
expect(view.container.textContent).toContain("Named for you");
const nameIt = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Name it",
)!;
await act(async () => nameIt.click());
const input = view.container.querySelector("input")!;
await act(async () => {
Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")!.set!.call(
input,
" Customer call ",
);
input.dispatchEvent(new window.Event("input", { bubbles: true }));
// react-dom loads before the DOM here, so it reads typing from key events.
input.dispatchEvent(new window.KeyboardEvent("keyup", { bubbles: true }));
});
const save = [...view.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Save",
)!;
await act(async () => save.click());
await settle(50);
expect(renamed).toEqual(["Customer call"]);
} finally {
await view.unmount();
}
});
test("a meeting recorded elsewhere shows the saved live text as a preview", async () => {
const { LIVE_RECORDING_ID } = await import("../testing/meetings-fixture");
const fixture = createMeetingsFixture();
const view = await render(
{}}
/>,
);
try {
await waitForText(view.container, "Let's keep this one short.");
const text = view.container.textContent ?? "";
expect(text).toContain("Not finished yet");
expect(text).toContain("still being recorded on another device");
// Beside tab audio the microphone is the person recording, by name, and
// the tab audio is everyone else.
expect(text).toContain("Ingrid Solberg");
expect(text).toContain("Others");
expect(text).not.toContain("Microphone");
expect(text).not.toContain("You0:04");
expect(view.container.querySelector('[role="log"]')).not.toBeNull();
} finally {
await view.unmount();
}
});
test("the person recording reads their own name on the microphone's live text", async () => {
const { liveSpeakerName } = await import("./recorder-panel");
const withTab = {
tracks: [
{ trackNumber: 0, source: "microphone" as const },
{ trackNumber: 1, source: "system" as const },
],
systemAudioKind: "tab" as const,
} as unknown as Parameters[0];
expect(liveSpeakerName(withTab, 0, undefined, "Ingrid Solberg")).toBe("Ingrid Solberg");
expect(liveSpeakerName(withTab, 1, undefined, "Ingrid Solberg")).toBe("Others");
expect(liveSpeakerName(withTab, 0)).toBe("You");
const micOnly = {
tracks: [{ trackNumber: 0, source: "microphone" as const }],
systemAudioKind: null,
} as unknown as Parameters[0];
expect(liveSpeakerName(micOnly, 0, undefined, "Ingrid Solberg")).toBe("Microphone");
});
test("the recorder bar keeps live text and its cost in its options menu", async () => {
const fixture = createMeetingsFixture();
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await waitForText(view.container, "Start recording");
// It waits in the options menu beside Start, not as another control in the bar.
expect(view.container.textContent).not.toContain("Live transcript");
expect(view.container.textContent).not.toContain("per hour");
} finally {
await view.unmount();
}
});
test("the recorder starts in the workspace's meeting language", async () => {
const fixture = createMeetingsFixture();
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await waitForText(view.container, "Start recording");
expect(
view.container.querySelector('button[aria-label="Recording options, Norwegian"]'),
).not.toBeNull();
} finally {
await view.unmount();
}
});
test("without a language from the host, the recorder starts in the one the server reports", async () => {
const fixture = createMeetingsFixture({ language: "no" });
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await waitForText(view.container, "Start recording");
await waitFor(
() =>
view.container.querySelector('button[aria-label="Recording options, Norwegian"]') !==
null,
);
} finally {
await view.unmount();
}
});
test("without a live default from the host, the recorder follows the workspace's setting", async () => {
const liveChecked = async (hostDefault: boolean | undefined) => {
const fixture = createMeetingsFixture({ liveTranscript: true });
const view = await render(
`/meetings/${id}`}
onOpen={() => {}}
/>,
);
try {
await waitForText(view.container, "Start recording");
const trigger = view.container.querySelector(
'button[aria-label^="Recording options"]',
);
await act(async () => {
trigger!.dispatchEvent(
new PointerEvent("pointerdown", { bubbles: true, button: 0, pointerType: "mouse" }),
);
});
await waitFor(() => document.querySelector('[role="menuitemcheckbox"]') !== null);
return document.querySelector('[role="menuitemcheckbox"]')!.getAttribute("aria-checked");
} finally {
await view.unmount();
}
};
expect(await liveChecked(undefined)).toBe("true");
// A host that decides for itself still wins.
expect(await liveChecked(false)).toBe("false");
});
test("streamed pieces are joined without doubled or stray punctuation", async () => {
const { tidyLiveText, tidyPartialText } = await import("./live-transcript");
expect(tidyLiveText(["It's between you…", ". And the dog ."])).toBe(
"It's between you. And the dog.",
);
expect(tidyLiveText(["Well...", "maybe,,", "yes!!"])).toBe("Well... maybe, yes!");
expect(tidyPartialText("so we were thinking…")).toBe("so we were thinking");
});
test("unavailable live text says why and that nothing is lost", async () => {
const { liveUnavailableText } = await import("./recorder-panel");
const text = liveUnavailableText([
{ error: { code: "quota_exceeded", message: "The live transcript stopped" } },
]);
expect(text).toContain("out of credit");
expect(text).toContain("You still get the transcript");
expect(liveUnavailableText([{ error: null }])).not.toContain(" ");
});
test("a stopped upload says why the server refused it", async () => {
const { recorderErrorText } = await import("./recorder-panel");
expect(
recorderErrorText({ code: "upload_failed", message: "Recording not found" }).body,
).toContain("The meeting was deleted, or you no longer have access to it.");
expect(
recorderErrorText({ code: "upload_failed", message: "Chunk index out of range." }).body,
).toContain("The server refused the audio: Chunk index out of range.");
});
test("turns from one track read as one turn, in time order", async () => {
const { groupLiveTurns } = await import("./live-transcript");
const turns = groupLiveTurns([
{ trackNumber: 1, startMilliseconds: 9_000, text: "Morning." },
{ trackNumber: 0, startMilliseconds: 4_000, text: "Hi all." },
{ trackNumber: 1, startMilliseconds: 12_000, text: "Release went out." },
{ trackNumber: 1, startMilliseconds: 14_000, text: " " },
]);
expect(turns.map((turn) => [turn.trackNumber, turn.texts.join(" ")])).toEqual([
[0, "Hi all."],
[1, "Morning. Release went out."],
]);
});
test("the microphone's echo of the call is left out; what the person says stays", async () => {
const { withoutLiveMicrophoneEchoes } = await import("../recordings");
const tracks = [
{ trackNumber: 0, source: "microphone" as const },
{ trackNumber: 1, source: "system" as const },
];
const lines = [
// Kari, in the call, heard from the speakers too.
{
trackNumber: 1,
startMilliseconds: 4_000,
endMilliseconds: 9_000,
text: "Elektrikerne kommer mandag klokken åtte.",
},
{
trackNumber: 0,
startMilliseconds: 4_300,
endMilliseconds: 9_200,
text: "Elektrikerne kommer mandag, klokka åtte.",
},
// The person recording answers.
{
trackNumber: 0,
startMilliseconds: 10_000,
endMilliseconds: 13_000,
text: "Da må gipsen vente til tirsdag.",
},
// A word of their own while Kari speaks stays, as does an echo-like line much later.
{ trackNumber: 0, startMilliseconds: 5_000, endMilliseconds: 5_400, text: "Mandag?" },
{
trackNumber: 0,
startMilliseconds: 40_000,
endMilliseconds: 43_000,
text: "Elektrikerne kommer mandag klokken åtte.",
},
];
expect(withoutLiveMicrophoneEchoes(lines, tracks).map((line) => line.text)).toEqual([
"Elektrikerne kommer mandag klokken åtte.",
"Da må gipsen vente til tirsdag.",
"Mandag?",
"Elektrikerne kommer mandag klokken åtte.",
]);
// A microphone alone is a room: nothing is an echo.
expect(withoutLiveMicrophoneEchoes(lines, [tracks[0]!])).toHaveLength(lines.length);
});
});