mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 05:30:16 +01:00
Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 Co-authored-by: Claude <noreply@anthropic.com>
1320 lines
58 KiB
JavaScript
1320 lines
58 KiB
JavaScript
// The Messenger in a real browser, at a phone's width and a desktop's.
|
||
//
|
||
// pnpm run demo && node test/browser-messenger.mjs
|
||
//
|
||
// Drives demo/messenger.html (a pretend backend) through what a person does:
|
||
// open a conversation, write, call the agent in, send a photo, read back up
|
||
// a long thread, edit, start a new conversation. And the things the eye
|
||
// checks that no unit test can: the box sits at the bottom of the screen
|
||
// with nothing empty under it, the thread fills what is left, nothing scrolls
|
||
// sideways, every control is a 44px target, no word is cut across lines, the
|
||
// text is 16px, and an agent's message can be told from a person's.
|
||
import { createServer } from "node:http";
|
||
import { readFile } from "node:fs/promises";
|
||
import { extname, join, normalize } from "node:path";
|
||
import { fileURLToPath } from "node:url";
|
||
import { chromium } from "playwright";
|
||
import { BROKEN_WORDS_SOURCE } from "../dist/audit.js";
|
||
|
||
const root = fileURLToPath(new URL("..", import.meta.url));
|
||
const types = {
|
||
".html": "text/html",
|
||
".js": "text/javascript",
|
||
".css": "text/css",
|
||
".woff2": "font/woff2",
|
||
};
|
||
const server = createServer(async (req, res) => {
|
||
const path = normalize(join(root, decodeURIComponent(new URL(req.url, "http://x").pathname)));
|
||
if (!path.startsWith(root)) return res.writeHead(403).end();
|
||
try {
|
||
const body = await readFile(path);
|
||
res
|
||
.writeHead(200, { "content-type": types[extname(path)] ?? "application/octet-stream" })
|
||
.end(body);
|
||
} catch {
|
||
res.writeHead(404).end();
|
||
}
|
||
}).listen(0);
|
||
const base = `http://localhost:${server.address().port}/demo/messenger.html`;
|
||
|
||
let failures = 0;
|
||
const check = (ok, what) => {
|
||
console.log(`${ok ? "PASS" : "FAIL"} ${what}`);
|
||
if (!ok) failures++;
|
||
};
|
||
|
||
// A 2×2 PNG: a photo, as far as the box can tell.
|
||
const PNG = Buffer.from(
|
||
"iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVR4nGP8z8DwnwEIGBkZGRgYAAA0BgMBCcLDvQAAAABJRU5ErkJggg==",
|
||
"base64",
|
||
);
|
||
|
||
/** Layout facts the eye checks: sideways scroll, small targets, cut words. */
|
||
async function layout(page) {
|
||
return page.evaluate(`(() => {
|
||
const small = [...document.querySelectorAll(
|
||
".ck-msgr button, .ck-msgr a[href], .ck-msgr input:not([type=file]), .ck-msgr textarea"
|
||
)]
|
||
.filter((e) => !e.closest("dialog:not([open])") && !e.closest("[hidden]"))
|
||
.map((e) => [e, e.getBoundingClientRect()])
|
||
.filter(([, r]) => r.width > 0 && r.height > 0 && (r.width < 44 || r.height < 44))
|
||
// The remove dot on a staged file extends its target with ::after, and
|
||
// a link inside a sentence is text, not a control.
|
||
.filter(([e]) => !e.classList.contains("ck-attach-remove") && !e.classList.contains("ck-msgr-link") && !e.closest(".ck-md"))
|
||
// The search field's box is the 44px target; the input inside fills it.
|
||
.filter(([e]) => !e.closest(".ck-msgr-search"))
|
||
.map(([e, r]) => (e.getAttribute("aria-label") || e.className || e.tagName) + " " + Math.round(r.width) + "x" + Math.round(r.height));
|
||
return {
|
||
overflow: document.documentElement.scrollWidth - window.innerWidth,
|
||
small,
|
||
broken: (${BROKEN_WORDS_SOURCE})(document.body),
|
||
};
|
||
})()`);
|
||
}
|
||
|
||
/** Where the parts of an open conversation sit, in CSS pixels. */
|
||
async function frame(page) {
|
||
return page.evaluate(() => {
|
||
const box = (sel) => document.querySelector(sel)?.getBoundingClientRect();
|
||
const top = box(".ck-msgr-top");
|
||
const wrap = box(".ck-msgr-thread-wrap");
|
||
const dock = box(".ck-msgr-dock");
|
||
return {
|
||
height: window.innerHeight,
|
||
top: top && { y: Math.round(top.top), bottom: Math.round(top.bottom) },
|
||
wrap: wrap && { y: Math.round(wrap.top), bottom: Math.round(wrap.bottom) },
|
||
dock: dock && { y: Math.round(dock.top), bottom: Math.round(dock.bottom) },
|
||
pageScroll: document.documentElement.scrollHeight - window.innerHeight,
|
||
};
|
||
});
|
||
}
|
||
|
||
const bubbles = (page) =>
|
||
page.$$eval(".ck-msgr-bubble", (els) => els.map((e) => e.textContent ?? ""));
|
||
const count = (page, text) => bubbles(page).then((all) => all.filter((b) => b === text).length);
|
||
const atEnd = (page) =>
|
||
page.$eval(".ck-msgr-scroll", (el) => el.scrollHeight - el.scrollTop - el.clientHeight < 4);
|
||
|
||
const browser = await chromium.launch({
|
||
...(process.env.CHROMIUM_PATH ? { executablePath: process.env.CHROMIUM_PATH } : {}),
|
||
// A microphone that is always there and never asks: the voice message.
|
||
args: ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"],
|
||
});
|
||
try {
|
||
// ── the screen, at every width, light and dark ──
|
||
for (const [name, width, height, dark] of [
|
||
["phone", 390, 844, false],
|
||
["small phone, dark", 320, 640, true],
|
||
["desktop", 1280, 800, false],
|
||
]) {
|
||
const phone = width < 768;
|
||
const context = await browser.newContext({
|
||
viewport: { width, height },
|
||
hasTouch: phone,
|
||
isMobile: phone,
|
||
});
|
||
const page = await context.newPage();
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.goto(base);
|
||
if (dark) await page.evaluate(() => document.documentElement.classList.add("dark"));
|
||
await page.waitForSelector(".ck-msgr-row");
|
||
|
||
let m = await layout(page);
|
||
check(m.overflow <= 0, `${name}: the list does not scroll sideways (${m.overflow}px)`);
|
||
check(
|
||
m.small.length === 0,
|
||
`${name}: every control in the list is 44px (${m.small.join(", ")})`,
|
||
);
|
||
check(m.broken.length === 0, `${name}: no word in the list is cut (${m.broken.join(", ")})`);
|
||
check(
|
||
(await page.locator(".ck-msgr-row").count()) === 5,
|
||
`${name}: five conversations are listed`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-row").first().locator(".ck-msgr-row-name").textContent()) ===
|
||
"Maya Keller",
|
||
`${name}: the newest conversation is first`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-badge").textContent()) === "2",
|
||
`${name}: an unread conversation shows its count`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-row-agent").count()) === 1,
|
||
`${name}: the conversation an agent joined says so on its face`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-main").isVisible()) === !phone,
|
||
`${name}: ${phone ? "one pane at a time" : "list and conversation side by side"}`,
|
||
);
|
||
|
||
// Open the conversation the agent joined.
|
||
await page.locator(".ck-msgr-row").first().click();
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
check(
|
||
(await page.locator(".ck-msgr-side").isVisible()) === !phone,
|
||
`${name}: opening a conversation ${phone ? "replaces the list" : "keeps the list beside it"}`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-back").isVisible()) === phone,
|
||
`${name}: ${phone ? "a way back to the list" : "no back button beside the list"}`,
|
||
);
|
||
|
||
const f = await frame(page);
|
||
check(f.pageScroll <= 0, `${name}: the page itself does not scroll (${f.pageScroll}px)`);
|
||
check(f.top.y === 0, `${name}: the conversation's top bar is at the top (${f.top.y})`);
|
||
check(
|
||
Math.abs(f.dock.bottom - f.height) <= 1,
|
||
`${name}: the box sits at the bottom of the screen, nothing empty under it (${f.height - f.dock.bottom}px)`,
|
||
);
|
||
check(
|
||
f.wrap.y === f.top.bottom && Math.abs(f.wrap.bottom - f.dock.y) <= 1,
|
||
`${name}: the thread fills everything between the top bar and the box`,
|
||
);
|
||
const chrome = f.top.bottom - f.top.y + (f.dock.bottom - f.dock.y);
|
||
check(
|
||
chrome <= 132,
|
||
`${name}: top bar and box together leave the screen to the conversation (${chrome}px of ${f.height})`,
|
||
);
|
||
check(await atEnd(page), `${name}: the conversation opens at its newest message`);
|
||
|
||
m = await layout(page);
|
||
check(m.overflow <= 0, `${name}: the conversation does not scroll sideways (${m.overflow}px)`);
|
||
check(m.small.length === 0, `${name}: every control is 44px (${m.small.join(", ")})`);
|
||
check(m.broken.length === 0, `${name}: no word is cut (${m.broken.join(", ")})`);
|
||
|
||
const sizes = await page.evaluate(() => ({
|
||
bubble: parseFloat(getComputedStyle(document.querySelector(".ck-msgr-bubble")).fontSize),
|
||
input: parseFloat(getComputedStyle(document.querySelector(".ck-input")).fontSize),
|
||
}));
|
||
check(sizes.bubble >= 16 && sizes.input >= 16, `${name}: messages and the box are 16px`);
|
||
check((await page.locator(".ck-mic").count()) === 1, `${name}: the box has a microphone`);
|
||
const row = await page.evaluate(() => {
|
||
const y = (sel) => Math.round(document.querySelector(sel).getBoundingClientRect().top);
|
||
return [y(".ck-composer .ck-tools .ck-icon-btn"), y(".ck-mic"), y(".ck-send")];
|
||
});
|
||
check(
|
||
Math.max(...row) - Math.min(...row) <= 2,
|
||
`${name}: attach, microphone and send are one row (${row.join("/")})`,
|
||
);
|
||
|
||
// Who is a person and who is not.
|
||
const agentRun = page.locator(".ck-msgr-from-agent").first();
|
||
check(
|
||
(await agentRun.locator(".ck-speaker-kind").textContent()) === "Agent",
|
||
`${name}: the agent's message is marked Agent`,
|
||
);
|
||
check(
|
||
/for Georgy/.test((await agentRun.locator(".ck-speaker").textContent()) ?? ""),
|
||
`${name}: and says whom it answered for`,
|
||
);
|
||
const looks = await page.evaluate(() => {
|
||
const style = (sel) => getComputedStyle(document.querySelector(sel));
|
||
const agent = style(".ck-msgr-from-agent .ck-msgr-bubble");
|
||
const other = style(".ck-msgr-other:not(.ck-msgr-from-agent) .ck-msgr-bubble");
|
||
const own = style(".ck-msgr-own .ck-msgr-bubble");
|
||
return {
|
||
agentBg: agent.backgroundColor,
|
||
agentBorder: agent.borderTopWidth,
|
||
otherBg: other.backgroundColor,
|
||
ownBg: own.backgroundColor,
|
||
agentFace: style(".ck-msgr-from-agent .ck-msgr-avatar").borderTopLeftRadius,
|
||
personFace: style(".ck-msgr-other:not(.ck-msgr-from-agent) .ck-msgr-avatar")
|
||
.borderTopLeftRadius,
|
||
};
|
||
});
|
||
check(
|
||
looks.agentBg !== looks.otherBg &&
|
||
looks.agentBorder === "1px" &&
|
||
looks.ownBg !== looks.otherBg,
|
||
`${name}: an agent's bubble, a person's and the viewer's are three different bubbles`,
|
||
);
|
||
check(
|
||
looks.agentFace !== looks.personFace,
|
||
`${name}: an agent's face is a different shape from a person's`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-other:not(.ck-msgr-from-agent) .ck-speaker-kind").count()) ===
|
||
0,
|
||
`${name}: no person is marked as an agent`,
|
||
);
|
||
check(
|
||
/Cat is here/.test((await page.locator(".ck-msgr-top-sub").textContent()) ?? ""),
|
||
`${name}: the top bar says an agent is in the conversation`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-top-sub .ck-speaker-kind").count()) === 0,
|
||
`${name}: under a person's name the top bar marks nobody as an agent`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-own .ck-msgr-tick-read").count()) > 0,
|
||
`${name}: a message the other person read shows it`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-link").getAttribute("href")) ===
|
||
"https://example.org/penguins-are-birds",
|
||
`${name}: an address in a message is a link, without the full stop after it`,
|
||
);
|
||
|
||
// Write. The message is shown once, the box is emptied, the thread follows.
|
||
await page.fill(".ck-input", "Speaking of birds");
|
||
await page.click(".ck-send");
|
||
await page.waitForFunction(
|
||
() => window.ckMessenger.calls.send === 1 && !document.querySelector(".ck-msgr-sending"),
|
||
);
|
||
check((await count(page, "Speaking of birds")) === 1, `${name}: a sent message is shown once`);
|
||
check((await page.inputValue(".ck-input")) === "", `${name}: the box is emptied`);
|
||
check(await atEnd(page), `${name}: the thread follows what was sent`);
|
||
|
||
// Call the agent in.
|
||
await page.fill(".ck-input", "@cat who is right?");
|
||
await page.keyboard.press("Enter");
|
||
await page.waitForSelector(".ck-msgr-awaited");
|
||
check(
|
||
/Cat is thinking/.test((await page.locator(".ck-msgr-awaited").textContent()) ?? ""),
|
||
`${name}: naming the agent shows that it is thinking`,
|
||
);
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-from-agent .ck-msgr-bubble")].some((b) =>
|
||
b.textContent.includes("you are right about the"),
|
||
),
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-awaited").count()) === 0,
|
||
`${name}: its answer ends the wait`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-from-agent .ck-msgr-bubble strong").last().textContent()) ===
|
||
"birds",
|
||
`${name}: the agent's answer is rendered as markdown`,
|
||
);
|
||
check(await atEnd(page), `${name}: the thread follows the agent's answer`);
|
||
|
||
// Somebody else, elsewhere and here.
|
||
await page.evaluate(() =>
|
||
window.ckMessenger.emit({
|
||
type: "message",
|
||
message: {
|
||
id: "push-1",
|
||
threadId: "ben",
|
||
authorId: "ben",
|
||
body: "Friday?",
|
||
createdAt: new Date(),
|
||
},
|
||
}),
|
||
);
|
||
if (phone) {
|
||
await page.click(".ck-msgr-back");
|
||
await page.waitForSelector(".ck-msgr-row");
|
||
}
|
||
check(
|
||
(await page.locator(".ck-msgr-badge").textContent()) === "3",
|
||
`${name}: a message in another conversation raises its count`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-row").first().locator(".ck-msgr-row-name").textContent()) ===
|
||
"Ben Ito",
|
||
`${name}: and brings it to the top of the list`,
|
||
);
|
||
await page.locator(".ck-msgr-row", { hasText: "Ben Ito" }).click();
|
||
// Side by side, the conversation that was open may still be on screen with
|
||
// a "New" line of its own: wait for THIS one before reading the thread.
|
||
await page.waitForFunction(
|
||
() => document.querySelector(".ck-msgr-top-name")?.textContent?.includes("Ben Ito") === true,
|
||
);
|
||
await page.waitForSelector(".ck-msgr-unread-line");
|
||
check(
|
||
(await page.locator(".ck-msgr-unread-line").textContent()) === "New",
|
||
`${name}: an unread conversation opens with a line where the new messages begin`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-speaker").count()) === 0,
|
||
`${name}: between two people nobody is named`,
|
||
);
|
||
await page.waitForFunction(() => !document.querySelector(".ck-msgr-badge"));
|
||
check(true, `${name}: reading it clears its count`);
|
||
// Debounced: a burst of read marks is one request.
|
||
await page.waitForFunction(() => window.ckMessenger.calls.markRead >= 1);
|
||
check(true, `${name}: and the read mark is sent`);
|
||
await page.evaluate(() =>
|
||
window.ckMessenger.emit({
|
||
type: "typing",
|
||
conversationId: "ben",
|
||
actorId: "ben",
|
||
typing: true,
|
||
}),
|
||
);
|
||
await page.waitForSelector(".ck-msgr-typing");
|
||
check(
|
||
/Ben Ito is typing/.test((await page.locator(".ck-msgr-typing").textContent()) ?? ""),
|
||
`${name}: somebody typing is shown by name`,
|
||
);
|
||
await page.evaluate(() =>
|
||
window.ckMessenger.emit({
|
||
type: "message",
|
||
message: {
|
||
id: "push-2",
|
||
threadId: "ben",
|
||
authorId: "ben",
|
||
body: "Or Saturday.",
|
||
createdAt: new Date(),
|
||
},
|
||
}),
|
||
);
|
||
await page.waitForFunction(() => !document.querySelector(".ck-msgr-typing"));
|
||
check(
|
||
(await count(page, "Or Saturday.")) === 1,
|
||
`${name}: their message arrives and the dots go`,
|
||
);
|
||
|
||
check(errors.length === 0, `${name}: no page errors (${errors.join("; ")})`);
|
||
await context.close();
|
||
}
|
||
|
||
// ── a phone: photos, a long thread, editing, a new conversation ──
|
||
{
|
||
const context = await browser.newContext({
|
||
viewport: { width: 390, height: 844 },
|
||
hasTouch: true,
|
||
isMobile: true,
|
||
});
|
||
const page = await context.newPage();
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
|
||
// The attach sheet, and a photo on its way.
|
||
await page.goto(`${base}?open=hike`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.tap(".ck-composer .ck-tools .ck-icon-btn");
|
||
await page.waitForSelector(".ck-sheet[open]");
|
||
const sources = await page.$$eval(".ck-sheet[open] .ck-attach-source", (els) =>
|
||
els.map((e) => e.textContent),
|
||
);
|
||
check(
|
||
sources.join(",") === "Camera,Photos,Videos,Files",
|
||
`attach: the sheet offers Camera, Photos, Videos, Files (${sources.join(",")})`,
|
||
);
|
||
const cells = await page.$$eval(".ck-sheet[open] .ck-attach-source", (els) =>
|
||
els.map((e) => Math.round(e.getBoundingClientRect().width)),
|
||
);
|
||
check(
|
||
Math.max(...cells) - Math.min(...cells) <= 1,
|
||
`attach: four equal cells in one row (${cells.join("/")})`,
|
||
);
|
||
check(
|
||
(await page.locator(".ck-sheet[open] .ck-attach-extra").last().textContent())?.includes(
|
||
"Ask Cat",
|
||
),
|
||
"attach: the same sheet offers to ask the agent",
|
||
);
|
||
check(
|
||
(await page
|
||
.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Request money" })
|
||
.count()) === 0,
|
||
"actions: an action that does not fit a conversation is not offered in it",
|
||
);
|
||
check(
|
||
(await page
|
||
.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Voice message" })
|
||
.count()) === 1,
|
||
"voice: the same sheet offers a voice message",
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-sheet-close").click();
|
||
|
||
await page.setInputFiles('input[data-ck-source="photos"]', {
|
||
name: "ridge.png",
|
||
mimeType: "image/png",
|
||
buffer: PNG,
|
||
});
|
||
await page.waitForSelector(".ck-msgr-upload");
|
||
check(
|
||
(await page.locator(".ck-msgr-upload-bar").count()) === 1 ||
|
||
(await page.locator('.ck-msgr-upload[data-upload="done"]').count()) === 1,
|
||
"upload: a photo on its way shows its progress",
|
||
);
|
||
await page.waitForSelector('.ck-msgr-upload[data-upload="done"]');
|
||
check(
|
||
!(await page.locator(".ck-send").isDisabled()),
|
||
"upload: a photo alone, with no words, can be sent",
|
||
);
|
||
const before = await page.locator(".ck-msgr-media").count();
|
||
await page.tap(".ck-send");
|
||
await page.waitForFunction(
|
||
(n) =>
|
||
document.querySelectorAll(".ck-msgr-media").length === n + 1 &&
|
||
!document.querySelector(".ck-msgr-sending"),
|
||
before,
|
||
);
|
||
check((await page.locator(".ck-msgr-upload").count()) === 0, "upload: the tray is cleared");
|
||
check(
|
||
(await page.evaluate(() => window.ckMessenger.calls.upload)) === 1,
|
||
"upload: the bytes went through the app's transport once",
|
||
);
|
||
check(await atEnd(page), "upload: the thread follows the photo");
|
||
let m = await layout(page);
|
||
check(m.overflow <= 0, `upload: nothing scrolls sideways (${m.overflow}px)`);
|
||
|
||
// A type the policy does not take is refused in words, before any upload.
|
||
await page.setInputFiles('input[data-ck-source="files"]', {
|
||
name: "page.html",
|
||
mimeType: "text/html",
|
||
buffer: Buffer.from("<script>alert(1)</script>"),
|
||
});
|
||
await page.waitForSelector(".ck-msgr-dock .ck-note");
|
||
check(
|
||
(await page.locator(".ck-msgr-dock .ck-note").textContent()) ===
|
||
"page.html cannot be sent here.",
|
||
"upload: a type that is not accepted is refused in words",
|
||
);
|
||
check(
|
||
(await page.evaluate(() => window.ckMessenger.calls.upload)) === 1,
|
||
"upload: and nothing was uploaded for it",
|
||
);
|
||
|
||
// The viewer: a picture, the whole screen, and back.
|
||
await page.locator(".ck-msgr-media").last().click();
|
||
await page.waitForSelector(".ck-msgr-viewer[open] img");
|
||
const viewer = await page.$eval(".ck-msgr-viewer[open]", (d) => {
|
||
const r = d.getBoundingClientRect();
|
||
return [Math.round(r.width), Math.round(r.height)];
|
||
});
|
||
check(viewer[0] === 390 && viewer[1] === 844, "viewer: a picture opens on the whole screen");
|
||
await page.keyboard.press("Escape");
|
||
await page.waitForFunction(() => !document.querySelector(".ck-msgr-viewer"));
|
||
check(true, "viewer: Escape closes it");
|
||
|
||
// ── replies, reactions, cards ──
|
||
await page.goto(`${base}?open=maya`);
|
||
await page.waitForSelector(".ck-msgr-quote");
|
||
check(
|
||
(await page.locator(".ck-msgr-quote").first().textContent())?.includes(
|
||
"Fine. But they swim better",
|
||
),
|
||
"reply: a reply shows the message it answers",
|
||
);
|
||
await page.locator(".ck-msgr-quote").first().tap();
|
||
await page.waitForSelector(".ck-msgr-found");
|
||
check(true, "reply: tapping the quote leads to that message and marks it");
|
||
m = await layout(page);
|
||
check(m.overflow <= 0, `reply: nothing scrolls sideways (${m.overflow}px)`);
|
||
check(m.small.length === 0, `reply: every control is 44px (${m.small.join(", ")})`);
|
||
|
||
const card = page.locator(".ck-msgr-card").first();
|
||
check(
|
||
(await card.locator(".ck-msgr-card-amount").textContent()) === "CHF 12.00",
|
||
"card: a payment request shows its amount",
|
||
);
|
||
check(
|
||
(await card.locator(".ck-msgr-card-action").textContent()) === "Pay CHF 12.00",
|
||
"card: and what this reader can do about it",
|
||
);
|
||
|
||
// A long press: react, then reply.
|
||
const bubble = page.locator(".ck-msgr-other .ck-msgr-bubble").last();
|
||
await bubble.dispatchEvent("contextmenu");
|
||
await page.waitForSelector(".ck-sheet[open] .ck-msgr-react");
|
||
const reacts = await page.$$eval(".ck-sheet[open] .ck-msgr-react", (els) =>
|
||
els.map((e) => Math.round(e.getBoundingClientRect().height)),
|
||
);
|
||
check(
|
||
reacts.length === 6 && Math.min(...reacts) >= 44,
|
||
`react: six emoji in one row, each 44px (${reacts.join("/")})`,
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-msgr-react").nth(1).tap();
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-reaction")].some(
|
||
(e) => e.textContent === "❤️" && e.getAttribute("aria-pressed") === "true",
|
||
),
|
||
);
|
||
check(
|
||
(await page.evaluate(() => window.ckMessenger.calls.react)) === 1,
|
||
"react: the emoji is on the message at once and the server is told once",
|
||
);
|
||
await page.locator('.ck-msgr-reaction[aria-pressed="true"]').tap();
|
||
await page.waitForFunction(
|
||
() => !document.querySelector('.ck-msgr-reaction[aria-pressed="true"]'),
|
||
);
|
||
check(true, "react: tapping your own chip takes it off");
|
||
|
||
await bubble.dispatchEvent("contextmenu");
|
||
await page.waitForSelector(".ck-sheet[open] .ck-attach-extra");
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Reply" }).tap();
|
||
await page.waitForSelector(".ck-msgr-replying");
|
||
await page.fill(".ck-input", "Answering that one");
|
||
await page.tap(".ck-send");
|
||
await page.waitForFunction(
|
||
() =>
|
||
!document.querySelector(".ck-msgr-sending") &&
|
||
[...document.querySelectorAll(".ck-msgr-own .ck-msgr-msg")].some(
|
||
(e) => e.querySelector(".ck-msgr-quote") && e.textContent.includes("Answering that one"),
|
||
),
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-replying").count()) === 0,
|
||
"reply: the sent message carries its quote, and the box forgets it",
|
||
);
|
||
check(
|
||
await page.evaluate(() => {
|
||
const sent = window.ckMessenger.store.maya.at(-1);
|
||
return Boolean(sent.replyTo && sent.replyTo.id);
|
||
}),
|
||
"reply: the server is told which message was answered",
|
||
);
|
||
|
||
// An app's action: ask for money.
|
||
await page.tap(".ck-composer .ck-tools .ck-icon-btn");
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Request money" }).tap();
|
||
await page.waitForSelector(".ck-sheet[open] .ck-msgr-amount");
|
||
await page.locator(".ck-sheet[open] .ck-msgr-btn-primary").tap();
|
||
check(
|
||
(await page.locator(".ck-msgr-amount-error").count()) === 1,
|
||
"actions: no amount, no request — and the sheet says so",
|
||
);
|
||
await page.fill(".ck-msgr-amount-box input", "7,5");
|
||
m = await layout(page);
|
||
check(m.small.length === 0, `actions: every control is 44px (${m.small.join(", ")})`);
|
||
await page.locator(".ck-sheet[open] .ck-msgr-btn-primary").tap();
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-own .ck-msgr-card-amount")].some(
|
||
(e) => e.textContent === "CHF 7.50",
|
||
),
|
||
);
|
||
check(true, "actions: a comma is a decimal point, and the card is in the thread");
|
||
|
||
// ── search inside a conversation ──
|
||
await page.goto(`${base}?open=long`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
check(
|
||
(await count(page, "Line 3 of a long conversation.")) === 0,
|
||
"search: the message looked for is not loaded yet",
|
||
);
|
||
await page.locator('.ck-msgr-top [aria-label="Search this conversation"]').tap();
|
||
await page.waitForSelector(".ck-sheet[open] .ck-msgr-search input");
|
||
m = await layout(page);
|
||
check(m.small.length === 0, `search: every control is 44px (${m.small.join(", ")})`);
|
||
await page.fill(".ck-sheet[open] .ck-msgr-search input", "zzz-not-there");
|
||
await page.waitForFunction(
|
||
() =>
|
||
document.querySelector(".ck-sheet[open] .ck-msgr-hint")?.textContent ===
|
||
"No message has that.",
|
||
);
|
||
check(true, "search: words nobody wrote say so");
|
||
await page.fill(".ck-sheet[open] .ck-msgr-search input", "Line 3 of");
|
||
await page
|
||
.locator(".ck-sheet[open] .ck-msgr-row", { hasText: "Line 3 of a long" })
|
||
.first()
|
||
.waitFor();
|
||
const hits = await page.locator(".ck-sheet[open] .ck-msgr-row").count();
|
||
check(hits >= 1, `search: the server's matches are listed (${hits})`);
|
||
await page
|
||
.locator(".ck-sheet[open] .ck-msgr-row", { hasText: "Line 3 of a long conversation." })
|
||
.first()
|
||
.tap();
|
||
await page.waitForSelector(".ck-msgr-found", { timeout: 15000 });
|
||
check(
|
||
(await page.locator(".ck-msgr-found").textContent())?.includes(
|
||
"Line 3 of a long conversation.",
|
||
),
|
||
"search: tapping a match loads back to it, leads there and marks it",
|
||
);
|
||
check(
|
||
(await page.locator(".ck-sheet[open]").count()) === 0,
|
||
"search: and the sheet is out of the way",
|
||
);
|
||
m = await layout(page);
|
||
check(m.overflow <= 0, `search: nothing scrolls sideways (${m.overflow}px)`);
|
||
|
||
// ── a voice message: the empty box's own button, recorded in place ──
|
||
await page.goto(`${base}?open=maya`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.evaluate(() => {
|
||
// Every microphone track this page opens, so the test can see them closed.
|
||
window.ckTracks = [];
|
||
const open = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
||
navigator.mediaDevices.getUserMedia = async (c) => {
|
||
const stream = await open(c);
|
||
window.ckTracks.push(...stream.getTracks());
|
||
return stream;
|
||
};
|
||
});
|
||
const liveTracks = () =>
|
||
page.evaluate(() => window.ckTracks.filter((t) => t.readyState === "live").length);
|
||
const voiceButton = page.locator('.ck-send[aria-label="Record a voice message"]');
|
||
check(
|
||
(await voiceButton.count()) === 1,
|
||
"voice: with nothing typed, the send slot records a voice message",
|
||
);
|
||
await page.fill(".ck-input", "words");
|
||
check(
|
||
(await voiceButton.count()) === 0 &&
|
||
(await page.locator('.ck-send[aria-label="Send message"]').count()) === 1,
|
||
"voice: with words typed, the same slot sends them",
|
||
);
|
||
await page.fill(".ck-input", "");
|
||
const voiceBefore = await page.locator(".ck-msgr-thread-wrap .ck-msgr-note").count();
|
||
const sentBefore = await page.evaluate(() => window.ckMessenger.calls.send);
|
||
await voiceButton.tap();
|
||
await page.waitForSelector('.ck-msgr-voicebar[data-phase="recording"]');
|
||
check((await liveTracks()) === 1, "voice: recording opens one microphone");
|
||
check(
|
||
(await page.locator(".ck-composer").count()) === 0,
|
||
"voice: the recording takes the box's place",
|
||
);
|
||
m = await layout(page);
|
||
check(m.small.length === 0, `voice: every control is 44px (${m.small.join(", ")})`);
|
||
check(m.overflow <= 0, `voice: nothing scrolls sideways while recording (${m.overflow}px)`);
|
||
await page.waitForFunction(() =>
|
||
/^0:0[1-9]$/.test(document.querySelector(".ck-msgr-voicebar-time")?.textContent ?? ""),
|
||
);
|
||
check(true, "voice: the take counts its seconds");
|
||
await page.locator('.ck-msgr-voicebar [aria-label="Send voice message"]').tap();
|
||
await page.waitForFunction(
|
||
({ n, sends }) =>
|
||
document.querySelectorAll(".ck-msgr-thread-wrap .ck-msgr-note").length === n + 1 &&
|
||
window.ckMessenger.calls.send === sends + 1 &&
|
||
!document.querySelector(".ck-msgr-sending"),
|
||
{ n: voiceBefore, sends: sentBefore },
|
||
);
|
||
check(true, "voice: one tap stops, uploads and sends it");
|
||
check((await liveTracks()) === 0, "voice: sending closes the microphone");
|
||
check(
|
||
(await page.locator(".ck-composer").count()) === 1 &&
|
||
(await page.locator(".ck-msgr-upload").count()) === 0,
|
||
"voice: the box is back, and the tray is empty",
|
||
);
|
||
check(
|
||
await page.evaluate(() => {
|
||
const sent = window.ckMessenger.store.maya.at(-1).attachments?.[0];
|
||
return (
|
||
sent?.kind === "audio" &&
|
||
sent.durationMs >= 1000 &&
|
||
/^voice-\d{4}-\d{2}-\d{2}-\d{4}\.(m4a|webm|ogg)$/.test(sent.name)
|
||
);
|
||
}),
|
||
"voice: it is sent as an audio file with its length and a name a person can find",
|
||
);
|
||
const note = page.locator(".ck-msgr-thread-wrap .ck-msgr-note").last();
|
||
check(
|
||
/^0:0[1-9]$/.test((await note.locator(".ck-msgr-note-time").textContent()) ?? ""),
|
||
"voice: the voice note shows its length before it is played",
|
||
);
|
||
await note.locator(".ck-msgr-note-play").tap();
|
||
await page.waitForFunction(() => {
|
||
const notes = document.querySelectorAll(".ck-msgr-thread-wrap .ck-msgr-note");
|
||
return notes[notes.length - 1]?.getAttribute("data-playing") === "true";
|
||
});
|
||
check(true, "voice: it plays");
|
||
await note.locator(".ck-msgr-note-speed").tap();
|
||
check(
|
||
(await note.locator(".ck-msgr-note-speed").textContent()) === "1.5×",
|
||
"voice: and plays faster on a tap",
|
||
);
|
||
await note.locator(".ck-msgr-note-play").tap();
|
||
m = await layout(page);
|
||
check(m.small.length === 0, `voice: the note's controls are 44px (${m.small.join(", ")})`);
|
||
// The play button is the bubble's ink on the bubble, never ink on ink.
|
||
const contrast = await note.evaluate((el) => {
|
||
const bubble = getComputedStyle(el).backgroundColor;
|
||
const disc = getComputedStyle(el.querySelector(".ck-msgr-note-play")).backgroundColor;
|
||
return { bubble, disc };
|
||
});
|
||
// Far apart, not merely different: rgb(0,0,0) on rgb(26,26,26) is
|
||
// "different" and invisible (it was, on 2026-11-15).
|
||
const lum = (c) => {
|
||
const [r, g, b] = (c.match(/\d+(\.\d+)?/g) ?? []).map(Number);
|
||
return (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
|
||
};
|
||
check(
|
||
Math.abs(lum(contrast.bubble) - lum(contrast.disc)) > 0.5,
|
||
`voice: the play button stands out from its bubble (${contrast.disc} on ${contrast.bubble})`,
|
||
);
|
||
// Show text: the words of a voice message, under it, and hidden again.
|
||
const wrap = page.locator(".ck-msgr-thread-wrap .ck-msgr-note-wrap").last();
|
||
await wrap.locator(".ck-msgr-note-text-toggle").tap();
|
||
await page.waitForSelector(".ck-msgr-note-words");
|
||
check(
|
||
(await wrap.locator(".ck-msgr-note-words").textContent()) === "Meet at the bridge at six.",
|
||
"voice: Show text shows the words under the voice message",
|
||
);
|
||
await wrap.locator(".ck-msgr-note-text-toggle").tap();
|
||
check(
|
||
(await wrap.locator(".ck-msgr-note-words").count()) === 0,
|
||
"voice: and Hide text hides them",
|
||
);
|
||
|
||
// Delete while recording: nothing is sent, the microphone is closed.
|
||
const sendsNow = await page.evaluate(() => window.ckMessenger.calls.send);
|
||
await voiceButton.tap();
|
||
await page.waitForSelector('.ck-msgr-voicebar[data-phase="recording"]');
|
||
await page.locator('.ck-msgr-voicebar [aria-label="Delete recording"]').tap();
|
||
await page.waitForFunction(() => window.ckTracks.every((t) => t.readyState === "ended"));
|
||
check(
|
||
(await page.evaluate(() => window.ckMessenger.calls.send)) === sendsNow &&
|
||
(await page.locator(".ck-composer").count()) === 1,
|
||
"voice: deleting a recording sends nothing and closes the microphone",
|
||
);
|
||
// Send tapped at once: nothing to send, and the person is told so.
|
||
await voiceButton.tap();
|
||
await page.waitForSelector('.ck-msgr-voicebar[data-phase="recording"]');
|
||
await page.locator('.ck-msgr-voicebar [aria-label="Send voice message"]').tap();
|
||
await page.waitForSelector(".ck-msgr-dock .ck-note");
|
||
check(
|
||
((await page.locator(".ck-msgr-dock .ck-note").textContent()) ?? "").includes("too short"),
|
||
"voice: a recording too short to send says so, never silence",
|
||
);
|
||
await page.waitForFunction(() => window.ckTracks.every((t) => t.readyState === "ended"));
|
||
check(true, "voice: and its microphone is closed");
|
||
// The "+" offers it too, and it records in the same place.
|
||
await page.tap(".ck-composer .ck-tools .ck-icon-btn");
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Voice message" }).tap();
|
||
await page.waitForSelector('.ck-msgr-voicebar[data-phase="recording"]');
|
||
await page.locator('.ck-msgr-voicebar [aria-label="Delete recording"]').tap();
|
||
await page.waitForSelector(".ck-composer");
|
||
check(true, "voice: the + offers it as well, recorded in the box's place");
|
||
|
||
// ── inside a host's own base styles, with a photo that is not square ──
|
||
// What a person saw on a phone on 2026-11-13: the field drawn as a box
|
||
// inside the box, the name pushed off its subtitle, a photo as an oval.
|
||
await page.goto(`${base}?open=maya&host=hostile`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.locator(".ck-input").focus();
|
||
const host = await page.evaluate(() => {
|
||
const box = (s) => {
|
||
const r = document.querySelector(s)?.getBoundingClientRect();
|
||
return r ? [Math.round(r.width), Math.round(r.height)] : null;
|
||
};
|
||
const style = (s, k) => {
|
||
const e = document.querySelector(s);
|
||
return e ? getComputedStyle(e)[k] : null;
|
||
};
|
||
return {
|
||
avatar: box(".ck-msgr-top .ck-msgr-avatar img"),
|
||
name: box(".ck-msgr-top-name"),
|
||
top: box(".ck-msgr-top"),
|
||
ring: style(".ck-input", "boxShadow"),
|
||
radius: style(".ck-input", "borderRadius"),
|
||
bubble: style(".ck-msgr-from-agent .ck-msgr-bubble", "lineHeight"),
|
||
paragraph: style(".ck-msgr-from-agent .ck-msgr-bubble p", "lineHeight"),
|
||
link: style(".ck-msgr-link", "minHeight"),
|
||
};
|
||
});
|
||
check(
|
||
host.avatar?.[0] === host.avatar?.[1] && host.avatar?.[0] === 36,
|
||
`host styles: a photo that is not square is still a circle (${host.avatar})`,
|
||
);
|
||
check(
|
||
host.ring === "none" && host.radius === "0px",
|
||
`host styles: the field has no ring of its own inside the composer (${host.ring})`,
|
||
);
|
||
check(
|
||
(host.name?.[1] ?? 99) < 30 && (host.top?.[1] ?? 99) <= 60,
|
||
`host styles: the name sits on its subtitle (name ${host.name?.[1]}px, bar ${host.top?.[1]}px)`,
|
||
);
|
||
check(
|
||
host.bubble === host.paragraph,
|
||
`host styles: an agent's answer is spaced like a person's (${host.paragraph} / ${host.bubble})`,
|
||
);
|
||
check(
|
||
host.link === "0px" || host.link === "auto",
|
||
`host styles: a link in a sentence is text, not a 44px target (min-height ${host.link})`,
|
||
);
|
||
m = await layout(page);
|
||
check(m.overflow <= 0, `host styles: nothing scrolls sideways (${m.overflow}px)`);
|
||
// A search field is a pill; a host's ring on the input inside it is the
|
||
// same box inside a box (seen in the search sheet, 2026-11-14).
|
||
await page.locator('.ck-msgr-top [aria-label="Search this conversation"]').tap();
|
||
await page.locator(".ck-sheet[open] .ck-msgr-search input").focus();
|
||
await page.fill(".ck-sheet[open] .ck-msgr-search input", "birds");
|
||
await page.locator(".ck-sheet[open] .ck-msgr-row").first().waitFor();
|
||
const field = await page.$eval(".ck-sheet[open] .ck-msgr-search input", (el) => {
|
||
const cs = getComputedStyle(el);
|
||
return `${cs.boxShadow} ${cs.borderRadius}`;
|
||
});
|
||
check(
|
||
field === "none 0px",
|
||
`host styles: a search field has no ring inside its pill (${field})`,
|
||
);
|
||
const shown = await page.$$eval(".ck-sheet[open] .ck-msgr-found-text", (els) =>
|
||
els.map((e) => e.textContent ?? "").join(" "),
|
||
);
|
||
check(!shown.includes("**"), "search: an agent's answer is listed as words, not markdown");
|
||
await page.locator(".ck-sheet[open] .ck-sheet-close").click();
|
||
|
||
// A failed upload keeps its tile, with a way to try again.
|
||
await page.goto(`${base}?open=hike&fail=upload`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.setInputFiles('input[data-ck-source="photos"]', {
|
||
name: "lake.png",
|
||
mimeType: "image/png",
|
||
buffer: PNG,
|
||
});
|
||
await page.waitForSelector('.ck-msgr-upload[data-upload="failed"]');
|
||
check(
|
||
(await page.locator(".ck-msgr-upload-retry").count()) === 1,
|
||
"upload: a failed upload stays, with Try again",
|
||
);
|
||
check(
|
||
/lake\.png could not be uploaded/.test(
|
||
(await page.locator(".ck-msgr-dock .ck-note").textContent()) ?? "",
|
||
),
|
||
"upload: and says so in words",
|
||
);
|
||
check(
|
||
await page.locator(".ck-send").isDisabled(),
|
||
"upload: nothing can be sent with only a failed file",
|
||
);
|
||
|
||
// A send that fails keeps the message, with Try again.
|
||
await page.goto(`${base}?open=maya&fail=send`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.fill(".ck-input", "Is anyone there?");
|
||
await page.tap(".ck-send");
|
||
await page.waitForSelector(".ck-msgr-failed-row");
|
||
check(
|
||
/Not sent\./.test((await page.locator(".ck-msgr-failed-row").textContent()) ?? ""),
|
||
"send: a message that did not go is kept and says so",
|
||
);
|
||
await page.locator(".ck-msgr-failed-row button", { hasText: "Try again" }).tap();
|
||
await page.waitForFunction(() => window.ckMessenger.calls.send === 2);
|
||
check(
|
||
(await count(page, "Is anyone there?")) === 1,
|
||
"send: Try again sends the same message, not a second one",
|
||
);
|
||
m = await layout(page);
|
||
check(
|
||
m.small.length === 0,
|
||
`send: Try again and Delete are 44px targets (${m.small.join(", ")})`,
|
||
);
|
||
|
||
// An agent that never answers is said to be silent, not left "thinking".
|
||
await page.goto(`${base}?open=maya&agent=quiet&patience=400`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.fill(".ck-input", "@cat hello?");
|
||
await page.tap(".ck-send");
|
||
await page.waitForFunction(() =>
|
||
document.querySelector(".ck-msgr-awaited")?.textContent.includes("has not answered"),
|
||
);
|
||
await page.locator(".ck-msgr-awaited button").tap();
|
||
await page.waitForFunction(() => !document.querySelector(".ck-msgr-awaited"));
|
||
check(true, "agent: one that stays silent is said to be silent, and the note can be dismissed");
|
||
|
||
// A long thread: opens at the end, loads earlier messages at the top,
|
||
// and the reader's place is kept.
|
||
await page.goto(`${base}?open=long`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
check(await atEnd(page), "long: the thread opens at its newest message");
|
||
check((await page.locator(".ck-msgr-bubble").count()) === 30, "long: one page is loaded");
|
||
const first = await page.locator(".ck-msgr-bubble").first().textContent();
|
||
// A real wheel, as a reader scrolls: a scripted scrollTo is not a person
|
||
// leaving the end of the thread, and the thread would rightly follow on.
|
||
// Up to the top and no further, so what happens next is the loading.
|
||
await page.mouse.move(195, 400);
|
||
const loaded = () => page.locator(".ck-msgr-bubble").count();
|
||
for (let i = 0; i < 40 && (await loaded()) === 30; i++) {
|
||
if ((await page.$eval(".ck-msgr-scroll", (el) => el.scrollTop)) <= 0) break;
|
||
await page.mouse.wheel(0, -300);
|
||
await page.waitForTimeout(20);
|
||
}
|
||
// The wheel stops here: what moves the thread from now on is the page of
|
||
// history arriving, not the reader.
|
||
await page.waitForFunction(() => document.querySelectorAll(".ck-msgr-bubble").length >= 60);
|
||
check((await loaded()) === 60, "long: reaching the top loads the page before it, once");
|
||
const kept = await page.evaluate((text) => {
|
||
const scroller = document.querySelector(".ck-msgr-scroll").getBoundingClientRect();
|
||
const bubble = [...document.querySelectorAll(".ck-msgr-bubble")].find(
|
||
(b) => b.textContent === text,
|
||
);
|
||
const r = bubble.getBoundingClientRect();
|
||
// The message that was at the top is still near the top: the page of
|
||
// history went in above it, not under the reader's eyes.
|
||
return r.top >= scroller.top - 4 && r.top < scroller.top + 240;
|
||
}, first);
|
||
check(kept, "long: earlier messages load above, and what was being read stays in view");
|
||
check(
|
||
(await page.locator(".ck-jump").count()) === 1,
|
||
"long: away from the end, a button leads back to the newest message",
|
||
);
|
||
await page.evaluate(() =>
|
||
window.ckMessenger.emit({
|
||
type: "message",
|
||
message: {
|
||
id: "push-9",
|
||
threadId: "long",
|
||
authorId: "zoe",
|
||
body: "Still here?",
|
||
createdAt: new Date(),
|
||
},
|
||
}),
|
||
);
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-bubble")].some(
|
||
(b) => b.textContent === "Still here?",
|
||
),
|
||
);
|
||
check(
|
||
!(await atEnd(page)),
|
||
"long: a message arriving does not pull the reader away from what they read",
|
||
);
|
||
await page.locator(".ck-jump").tap();
|
||
await page.waitForFunction(() => !document.querySelector(".ck-jump"));
|
||
check(await atEnd(page), "long: the button goes to the newest message");
|
||
|
||
// Edit: the words go back into the box, and the bubble says it was edited.
|
||
await page.goto(`${base}?open=maya`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
await page.locator(".ck-msgr-own .ck-msgr-msg").last().dispatchEvent("contextmenu");
|
||
await page.waitForSelector(".ck-sheet[open] .ck-attach-extra");
|
||
const actions = await page.$$eval(".ck-sheet[open] .ck-attach-extra-text", (els) =>
|
||
els.map((e) => e.textContent),
|
||
);
|
||
check(
|
||
actions.join(",") === "Reply,Copy text,Edit,Forward,Info,Delete for me,Delete for everyone",
|
||
`actions: a message of the viewer's offers Reply, Copy, Edit, Info and both deletes (${actions.join(",")})`,
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Edit" }).tap();
|
||
await page.waitForSelector(".ck-msgr-editing");
|
||
check(
|
||
(await page.inputValue(".ck-input")) === "That we agree on.",
|
||
"edit: the message is in the box",
|
||
);
|
||
await page.fill(".ck-input", "That much we agree on.");
|
||
await page.tap(".ck-send");
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-bubble")].some(
|
||
(b) => b.textContent === "That much we agree on.",
|
||
),
|
||
);
|
||
check(
|
||
(await count(page, "That we agree on.")) === 0,
|
||
"edit: the bubble is changed, not added to",
|
||
);
|
||
check(
|
||
/edited/.test((await page.locator(".ck-msgr-own .ck-msgr-meta").last().textContent()) ?? ""),
|
||
"edit: and says it was edited",
|
||
);
|
||
await page.waitForFunction(() => !document.querySelector(".ck-msgr-editing"));
|
||
check((await page.inputValue(".ck-input")) === "", "edit: the box is back to writing, empty");
|
||
|
||
// "edited" opens Info: what it said before, and who has it.
|
||
await page.locator(".ck-msgr-own .ck-msgr-edited").last().tap();
|
||
await page.waitForSelector(".ck-msgr-info-edit");
|
||
const info = (await page.locator(".ck-msgr-info").textContent()) ?? "";
|
||
check(info.includes("That we agree on."), "info: an edited message shows what it said before");
|
||
check(info.includes("Maya Keller"), `info: and who it went to (${info.slice(0, 120)})`);
|
||
// Styled, not raw markup: the sheet's own rules reached the page (0.39 and
|
||
// 0.42 shipped them in a generated file the build overwrote).
|
||
check(
|
||
(await page
|
||
.locator(".ck-msgr-info-list")
|
||
.first()
|
||
.evaluate((el) => getComputedStyle(el).listStyleType)) === "none",
|
||
"info: the sheet is styled (its list has no bullets)",
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-sheet-close").click();
|
||
await page.waitForFunction(() => !document.querySelector(".ck-sheet[open]"));
|
||
|
||
// Delete for everyone: the place stays and says so.
|
||
await page.locator(".ck-msgr-own .ck-msgr-msg").last().dispatchEvent("contextmenu");
|
||
await page
|
||
.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Delete for everyone" })
|
||
.tap();
|
||
await page.locator(".ck-sheet[open] .ck-msgr-btn-danger").tap();
|
||
await page.waitForSelector(".ck-msgr-deleted");
|
||
check(
|
||
(await page.locator(".ck-msgr-deleted").last().textContent()) === "You deleted this message",
|
||
"delete for everyone: a marker stays where the message was",
|
||
);
|
||
check(
|
||
(await count(page, "That much we agree on.")) === 0,
|
||
"delete for everyone: nothing of what it said",
|
||
);
|
||
await page.waitForFunction(() => !document.querySelector(".ck-sheet[open]"));
|
||
|
||
// A sheet an action closed, and the next long press in the same moment:
|
||
// the closed sheet's late close event must not shut the new one.
|
||
await page.locator(".ck-msgr-other .ck-msgr-msg").first().dispatchEvent("contextmenu");
|
||
await page.waitForSelector(".ck-sheet[open] .ck-attach-extra");
|
||
await page.evaluate(async () => {
|
||
const copy = [...document.querySelectorAll(".ck-sheet[open] .ck-attach-extra")].find((b) =>
|
||
b.textContent?.includes("Copy text"),
|
||
);
|
||
copy?.click();
|
||
// Let React close the dialog, then reopen before its close event runs.
|
||
await new Promise((r) => requestAnimationFrame(() => r(null)));
|
||
document
|
||
.querySelectorAll(".ck-msgr-other .ck-msgr-msg")[1]
|
||
?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true }));
|
||
});
|
||
await page.waitForTimeout(300);
|
||
check(
|
||
(await page.locator(".ck-sheet[open] .ck-attach-extra").count()) > 0,
|
||
"actions: a sheet reopened at once is not shut by the one that just closed",
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-sheet-close").click();
|
||
await page.waitForFunction(() => !document.querySelector(".ck-sheet[open]"));
|
||
|
||
await page.locator(".ck-msgr-other .ck-msgr-msg").first().dispatchEvent("contextmenu");
|
||
await page
|
||
.waitForSelector(".ck-sheet[open] .ck-attach-extra", { timeout: 8000 })
|
||
.catch(async (error) => {
|
||
// What the page looked like when the sheet did not open, for a CI log.
|
||
const state = await page.evaluate(() => ({
|
||
dialogs: [...document.querySelectorAll("dialog")].map((d) => ({
|
||
open: d.open,
|
||
label: d.getAttribute("aria-label"),
|
||
items: d.querySelectorAll(".ck-attach-extra").length,
|
||
})),
|
||
other: document.querySelectorAll(".ck-msgr-other .ck-msgr-msg").length,
|
||
first: document.querySelector(".ck-msgr-other .ck-msgr-msg")?.outerHTML.slice(0, 300),
|
||
notice: document.querySelector(".ck-msgr-notice, [role=alert]")?.textContent,
|
||
}));
|
||
console.log("SHEET DID NOT OPEN", JSON.stringify(state), errors.slice(-5));
|
||
throw error;
|
||
});
|
||
const theirs = await page.$$eval(".ck-sheet[open] .ck-attach-extra-text", (els) =>
|
||
els.map((e) => e.textContent),
|
||
);
|
||
check(
|
||
theirs.join(",") === "Reply,Copy text,Forward,Delete for me",
|
||
`actions: somebody else's message can be answered, copied and deleted for me only (${theirs.join(",")})`,
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-sheet-close").click();
|
||
await page.waitForFunction(() => !document.querySelector(".ck-sheet[open]"));
|
||
|
||
// Forward: choose a conversation, send, and the copy says where it came from.
|
||
await page.locator(".ck-msgr-other .ck-msgr-msg").first().dispatchEvent("contextmenu");
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Forward" }).tap();
|
||
await page.waitForSelector(".ck-msgr-forward-row");
|
||
check(
|
||
(await page
|
||
.locator(".ck-msgr-forward-row")
|
||
.first()
|
||
.evaluate((el) => getComputedStyle(el).minHeight)) === "48px",
|
||
"forward: the rows are styled, a touch target each",
|
||
);
|
||
await page.locator(".ck-msgr-forward-row", { hasText: "Ben Ito" }).tap();
|
||
check(
|
||
(await page.locator(".ck-msgr-forward .ck-msgr-btn-primary").textContent()) === "Send to 1",
|
||
"forward: the button says how many conversations it goes to",
|
||
);
|
||
await page.locator(".ck-msgr-forward .ck-msgr-btn-primary").tap();
|
||
await page.waitForFunction(() => document.body.textContent?.includes("Forwarded."));
|
||
check(true, "forward: the person is told it was forwarded");
|
||
|
||
// Pin: the conversation goes to the top of the list, marked.
|
||
await page.tap(".ck-msgr-back");
|
||
await page.locator(".ck-msgr-row", { hasText: "Ben Ito" }).tap();
|
||
await page.waitForSelector(".ck-msgr-forwarded");
|
||
check(
|
||
((await page.locator(".ck-msgr-forwarded").last().textContent()) ?? "").includes("Forwarded"),
|
||
"forward: the copy in the other conversation is marked Forwarded",
|
||
);
|
||
await page.tap(".ck-msgr-top-more");
|
||
const conversationMenu = await page.$$eval(".ck-sheet[open] .ck-attach-extra-text", (els) =>
|
||
els.map((e) => e.textContent),
|
||
);
|
||
check(
|
||
conversationMenu.join(",") === "Pin,Mute,Delete conversation",
|
||
`menu: a conversation can be pinned, muted or deleted (${conversationMenu.join(",")})`,
|
||
);
|
||
await page.locator(".ck-sheet[open] .ck-attach-extra", { hasText: "Pin" }).tap();
|
||
await page.tap(".ck-msgr-back");
|
||
await page.waitForFunction(() =>
|
||
document.querySelector(".ck-msgr-row")?.textContent?.includes("Ben Ito"),
|
||
);
|
||
check(true, "pin: a pinned conversation is first in the list");
|
||
await page.locator(".ck-msgr-row", { hasText: "Maya Keller" }).tap();
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
|
||
// A draft survives a visit to another conversation.
|
||
await page.fill(".ck-input", "half a thought");
|
||
await page.tap(".ck-msgr-back");
|
||
await page.locator(".ck-msgr-row", { hasText: "Weekend hike" }).tap();
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
check((await page.inputValue(".ck-input")) === "", "draft: another conversation starts empty");
|
||
await page.tap(".ck-msgr-back");
|
||
await page.locator(".ck-msgr-row", { hasText: "Maya Keller" }).tap();
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
check(
|
||
(await page.inputValue(".ck-input")) === "half a thought",
|
||
"draft: and the words are still there on the way back",
|
||
);
|
||
|
||
// A new conversation.
|
||
await page.tap(".ck-msgr-back");
|
||
await page.locator(".ck-msgr-btn-primary", { hasText: "New" }).tap();
|
||
await page.waitForSelector(".ck-sheet[open] .ck-msgr-new");
|
||
// Before anything is typed: who the app suggests, an agent marked as one.
|
||
await page.waitForSelector(".ck-sheet[open] .ck-msgr-row");
|
||
const suggested = await page.$$eval(".ck-sheet[open] .ck-msgr-row", (rows) =>
|
||
rows.map((r) => r.querySelector(".ck-msgr-row-text")?.textContent ?? ""),
|
||
);
|
||
check(
|
||
suggested.join("|") === "ChefAgent|Maya Keller@maya",
|
||
`new: the sheet opens on the app's suggestions, an agent marked as one (${suggested.join("|")})`,
|
||
);
|
||
m = await layout(page);
|
||
check(m.small.length === 0, `new: every control is 44px (${m.small.join(", ")})`);
|
||
await page.fill(".ck-sheet[open] .ck-msgr-search input", "ada");
|
||
await page.locator(".ck-sheet[open] .ck-msgr-row", { hasText: "Ada Okafor" }).waitFor();
|
||
await page.waitForFunction(
|
||
() => document.querySelectorAll(".ck-sheet[open] .ck-msgr-row").length === 1,
|
||
);
|
||
check(true, "new: typing replaces the suggestions with what was searched for");
|
||
await page.locator(".ck-sheet[open] .ck-msgr-row").tap();
|
||
await page.locator(".ck-sheet[open] .ck-msgr-btn-primary").tap();
|
||
await page.waitForSelector(".ck-msgr-top-name");
|
||
check(
|
||
(await page.locator(".ck-msgr-top-name").textContent()) === "Ada Okafor",
|
||
"new: picking a person opens the conversation with them",
|
||
);
|
||
await page.waitForSelector(".ck-msgr-thread-wrap .ck-msgr-hint");
|
||
check(
|
||
/Type @cat to bring Cat in/.test(
|
||
(await page.locator(".ck-msgr-thread-wrap").textContent()) ?? "",
|
||
),
|
||
"new: an empty conversation says how to bring the agent in",
|
||
);
|
||
const f = await frame(page);
|
||
check(
|
||
Math.abs(f.dock.bottom - f.height) <= 1,
|
||
"new: the box is at the bottom of an empty conversation too",
|
||
);
|
||
|
||
// Alone with an agent: nothing to type to bring it in, and its answer is
|
||
// what makes the message read.
|
||
await page.tap(".ck-msgr-back");
|
||
await page.locator(".ck-msgr-btn-primary", { hasText: "New" }).tap();
|
||
await page.locator(".ck-sheet[open] .ck-msgr-row", { hasText: "Chef" }).tap();
|
||
await page.locator(".ck-sheet[open] .ck-msgr-btn-primary").tap();
|
||
await page.waitForSelector(".ck-msgr-thread-wrap .ck-msgr-hint");
|
||
const aloneHint = (await page.locator(".ck-msgr-thread-wrap").textContent()) ?? "";
|
||
check(
|
||
/Chef answers every message here\./.test(aloneHint) && !/Type @cat/.test(aloneHint),
|
||
"agent alone: the empty conversation says it answers every message, with no mention to type",
|
||
);
|
||
await page.fill(".ck-input", "How long for pasta?");
|
||
await page.tap(".ck-send");
|
||
await page.waitForSelector(".ck-msgr-own .ck-msgr-tick");
|
||
await page.waitForFunction(() =>
|
||
[...document.querySelectorAll(".ck-msgr-bubble")].some(
|
||
(b) => b.textContent === "Salt the water first.",
|
||
),
|
||
);
|
||
check(
|
||
(await page.locator(".ck-msgr-own .ck-msgr-tick-read").count()) === 1,
|
||
"agent alone: a message the agent answered shows Read",
|
||
);
|
||
|
||
// The list fails once, says so, and Try again loads it.
|
||
await page.goto(`${base}?fail=list`);
|
||
await page.waitForSelector(".ck-msgr-list [role=alert]");
|
||
await page.locator(".ck-msgr-list [role=alert] button").tap();
|
||
await page.waitForSelector(".ck-msgr-row");
|
||
check(true, "list: a failed load says so, and Try again loads it");
|
||
|
||
check(errors.length === 0, `phone flows: no page errors (${errors.join("; ")})`);
|
||
await context.close();
|
||
}
|
||
|
||
// ── a keyboard, no mouse: what can be done to a message ──
|
||
for (const [name, width, height, touch] of [
|
||
["keyboard, desktop", 1280, 800, false],
|
||
["keyboard, phone", 390, 844, true],
|
||
]) {
|
||
const context = await browser.newContext({
|
||
viewport: { width, height },
|
||
hasTouch: touch,
|
||
isMobile: touch,
|
||
});
|
||
const page = await context.newPage();
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.goto(`${base}?open=maya`);
|
||
await page.waitForSelector(".ck-msgr-bubble");
|
||
// From the thread, Tab reaches a message's own button.
|
||
await page.focus(".ck-msgr-scroll");
|
||
let reached = false;
|
||
for (let i = 0; i < 80 && !reached; i++) {
|
||
await page.keyboard.press("Tab");
|
||
reached = await page.evaluate(
|
||
() =>
|
||
document.activeElement?.classList.contains("ck-msgr-act") &&
|
||
Boolean(document.activeElement.closest(".ck-msgr-own")),
|
||
);
|
||
}
|
||
check(reached, `${name}: Tab reaches the actions of a message of the viewer's`);
|
||
const act = await page.evaluate(() => {
|
||
const el = document.activeElement;
|
||
const r = el.getBoundingClientRect();
|
||
return {
|
||
opacity: getComputedStyle(el).opacity,
|
||
ring: el.matches(":focus-visible"),
|
||
width: Math.round(r.width),
|
||
height: Math.round(r.height),
|
||
left: Math.round(r.left),
|
||
right: Math.round(r.right),
|
||
vw: window.innerWidth,
|
||
label: el.getAttribute("aria-label"),
|
||
sideways: document.querySelector(".ck-msgr-scroll").scrollLeft,
|
||
};
|
||
});
|
||
check(
|
||
act.opacity === "1" && act.ring,
|
||
`${name}: the focused button is drawn (opacity ${act.opacity})`,
|
||
);
|
||
check(
|
||
act.width >= 44 && act.height >= 44,
|
||
`${name}: it is a 44px target (${act.width}x${act.height})`,
|
||
);
|
||
check(
|
||
act.left >= 0 && act.right <= act.vw && act.sideways === 0,
|
||
`${name}: it is on the screen and the thread did not move sideways (${act.left}..${act.right} of ${act.vw})`,
|
||
);
|
||
check(Boolean(act.label), `${name}: it has a name a screen reader can say (${act.label})`);
|
||
await page.keyboard.press("Enter");
|
||
await page.waitForSelector(".ck-sheet[open] .ck-attach-extra");
|
||
const offered = await page.$$eval(".ck-sheet[open] .ck-attach-extra-text", (els) =>
|
||
els.map((e) => e.textContent),
|
||
);
|
||
check(
|
||
offered.includes("Edit") && offered.includes("Delete for everyone"),
|
||
`${name}: Enter opens the sheet with Edit and Delete (${offered.join(",")})`,
|
||
);
|
||
// Edit, by keyboard alone: Tab to it, Enter, and the words are in the box.
|
||
let onEdit = false;
|
||
for (let i = 0; i < 20 && !onEdit; i++) {
|
||
await page.keyboard.press("Tab");
|
||
onEdit = await page.evaluate(
|
||
() =>
|
||
document.activeElement?.closest(".ck-sheet[open]") !== null &&
|
||
document.activeElement?.textContent?.trim() === "Edit",
|
||
);
|
||
}
|
||
check(onEdit, `${name}: Tab inside the sheet reaches Edit`);
|
||
await page.keyboard.press("Enter");
|
||
await page.waitForSelector(".ck-msgr-editing");
|
||
check(
|
||
(await page.inputValue(".ck-input")).length > 0,
|
||
`${name}: Enter on Edit puts the message in the box`,
|
||
);
|
||
// Somebody else's message is reachable too (Reply, Copy).
|
||
const others = await page.$$eval(".ck-msgr-other .ck-msgr-act", (els) => els.length);
|
||
check(others > 0, `${name}: other people's messages have the button too`);
|
||
const m = await layout(page);
|
||
check(m.overflow <= 0, `${name}: nothing scrolls sideways (${m.overflow}px)`);
|
||
check(errors.length === 0, `${name}: no page errors (${errors.join("; ")})`);
|
||
await context.close();
|
||
}
|
||
} finally {
|
||
await browser.close();
|
||
server.close();
|
||
}
|
||
|
||
if (failures > 0) {
|
||
console.error(`${failures} Messenger check(s) failed`);
|
||
process.exit(1);
|
||
}
|
||
console.log("all Messenger checks passed");
|