Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

test(ui): test the user-hint warning with real inputs (#648)

ladislav-urban448d32118b1e
diff --git a/packages/ui/scripts/embed.test.mjs b/packages/ui/scripts/embed.test.mjs
index 79155504..e125cfe8 100644
--- a/packages/ui/scripts/embed.test.mjs
+++ b/packages/ui/scripts/embed.test.mjs
@@ -9,6 +9,7 @@ import {
acceptsEvent,
badgeMessage,
embedRequested,
+ hintWarning,
isAppPath,
isNativePath,
openMessage,
@@ -131,12 +132,34 @@ test("nothing hides without a valid init from the parent", () => {
});
test("the embedded page warns when the host's user isn't who is signed in here", () => {
+ // Someone else: warn, naming both.
+ assert.deepEqual(hintWarning("[email protected]", "[email protected]"), { hint: "[email protected]", signedIn: "[email protected]" });
+ // The same person, whatever the case or spacing on either side.
+ assert.equal(hintWarning("[email protected]", "[email protected]"), null);
+ assert.equal(hintWarning("[email protected]", "[email protected]"), null);
+ assert.equal(hintWarning(" [email protected] ", "[email protected]"), null);
+ // Shown lowercased.
+ assert.deepEqual(hintWarning("[email protected]", "[email protected]"), { hint: "[email protected]", signedIn: "[email protected]" });
+ // Nothing without a hint, or without a session.
+ for (const hint of [null, undefined, "", " "]) assert.equal(hintWarning(hint, "[email protected]"), null, String(hint));
+ for (const email of [null, undefined, "", " "]) assert.equal(hintWarning("[email protected]", email), null, String(email));
+ // A hint as init delivers it is compared the same way.
+ const init = parseHostMessage({
+ protocol: EMBED_PROTOCOL,
+ type: "init",
+ contract: 1,
+ theme: { mode: "light", tokens: {} },
+ productName: "Host",
+ userHint: "[email protected]",
+ });
+ assert.equal(hintWarning(init.init.userHint, "[email protected]"), null);
+ assert.ok(hintWarning(init.init.userHint, "[email protected]"));
+});
+
+test("the warning is shown above the page and signs out back to it", () => {
const shell = readFileSync(new URL("../src/components/embed/EmbeddedShell.tsx", import.meta.url), "utf8");
- // Shown above the page, compared case-blind (the hint arrives lowercased).
assert.match(shell, /<UserHintWarning \/>\s*<PausedBanner \/>/);
- assert.match(shell, /const signedIn = data\?\.user\?\.email\?\.toLowerCase\(\) \?\? "";/);
- // Nothing without a hint or a session, and nothing when they agree.
- assert.match(shell, /if \(!hint \|\| !signedIn \|\| hint === signedIn\) return null;/);
+ assert.match(shell, /hintWarning\(init\?\.userHint, data\?\.user\?\.email\)/);
// Sign out comes back to the same page, still embedded.
- assert.match(shell, /callbackUrl: `\/signin\?embed=1&callbackUrl=\$\{encodeURIComponent\(window\.location\.pathname \+ window\.location\.search\)\}`/);
+ assert.match(shell, /signOut\(\{[\s\S]*?\/signin\?embed=1&callbackUrl=/);
});
diff --git a/packages/ui/src/components/embed/EmbeddedShell.tsx b/packages/ui/src/components/embed/EmbeddedShell.tsx
index 7678a491..e30d056c 100644
--- a/packages/ui/src/components/embed/EmbeddedShell.tsx
+++ b/packages/ui/src/components/embed/EmbeddedShell.tsx
@@ -9,7 +9,7 @@ import PausedBanner from "@/components/executive/PausedBanner";
import type { Hub } from "@/components/shell/navConfig";
import { usePageCrumbLabel } from "@/components/shell/PageCrumb";
import HubTabs from "@/components/ui/HubTabs";
-import { embedRequested, isNativePath, openMessage, queryWithoutEmbed, routeMessage } from "@/lib/embed";
+import { embedRequested, hintWarning, isNativePath, openMessage, queryWithoutEmbed, routeMessage } from "@/lib/embed";
// The page in a host's frame (embedded mode, lib/embed.ts): no sidebar, top
// bar, bottom bar or Ask OE panel (the host has its own), but the hub's tabs,
@@ -81,13 +81,13 @@ export default function EmbeddedShell({
// The host says who is using it (`userHint`, display only). When that isn't
// who is signed in here, say so: the next person at a shared computer must
-// not work on as the last one without knowing.
+// not work on as the last one without knowing (lib/embed.ts, hintWarning).
function UserHintWarning() {
const { init } = useEmbed();
const { data } = useSession();
- const signedIn = data?.user?.email?.toLowerCase() ?? "";
- const hint = init?.userHint ?? "";
- if (!hint || !signedIn || hint === signedIn) return null;
+ const warning = hintWarning(init?.userHint, data?.user?.email);
+ if (!warning) return null;
+ const { hint, signedIn } = warning;
return (
<div
role="alert"
diff --git a/packages/ui/src/lib/embed.ts b/packages/ui/src/lib/embed.ts
index 21c2e7bb..9888917f 100644
--- a/packages/ui/src/lib/embed.ts
+++ b/packages/ui/src/lib/embed.ts
@@ -188,6 +188,21 @@ function parseInit(data: Record<string, unknown>): EmbedInit | null {
return { theme, font, productName, userHint, nativePaths };
}
+/**
+ * Whether the embedded page warns that the host's user (`userHint`) isn't
+ * who is signed in here (`email`), and the two names to show: compared
+ * case-blind, and nothing to say without both.
+ */
+export function hintWarning(
+ hint: string | null | undefined,
+ email: string | null | undefined,
+): { hint: string; signedIn: string } | null {
+ const host = hint?.trim().toLowerCase() ?? "";
+ const signedIn = email?.trim().toLowerCase() ?? "";
+ if (!host || !signedIn || host === signedIn) return null;
+ return { hint: host, signedIn };
+}
+
/** A message from the host → what it says, or null to drop it. */
export function parseHostMessage(data: unknown): HostMessage | null {
if (!isRecord(data) || data.protocol !== EMBED_PROTOCOL) return null;