test(webui): synchronize touch composer typography snapshots
This commit is contained in:
1 parent
f80956966b
commit
9b5d552f40
1 file changed
+29
-18
@@ -1,23 +1,22 @@
|
|||||||
import { expect, test, type Locator } from "@playwright/test";
|
import { expect, test, type Locator } from "@playwright/test";
|
||||||
|
|
||||||
async function readMetrics(element: Locator) {
|
async function readMetrics(elements: Locator) {
|
||||||
return element.evaluate((node) => {
|
return elements.evaluateAll((nodes) => nodes.map((node) => {
|
||||||
if (!node.isConnected) return null;
|
|
||||||
const style = getComputedStyle(node);
|
const style = getComputedStyle(node);
|
||||||
return {
|
return {
|
||||||
size: parseFloat(style.fontSize), line: parseFloat(style.lineHeight), weight: style.fontWeight,
|
size: parseFloat(style.fontSize), line: parseFloat(style.lineHeight), weight: style.fontWeight,
|
||||||
family: style.fontFamily, letterSpacing: style.letterSpacing,
|
family: style.fontFamily, letterSpacing: style.letterSpacing,
|
||||||
padding: style.padding, autospace: style.getPropertyValue("text-autospace"),
|
padding: style.padding, autospace: style.getPropertyValue("text-autospace"),
|
||||||
};
|
};
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function metrics(element: Locator): Promise<NonNullable<Awaited<ReturnType<typeof readMetrics>>>> {
|
async function metrics(element: Locator): Promise<Awaited<ReturnType<typeof readMetrics>>[number]> {
|
||||||
let value: Awaited<ReturnType<typeof readMetrics>> = null;
|
let value: Awaited<ReturnType<typeof readMetrics>>[number] | undefined;
|
||||||
// Streamdown may replace a paragraph while settling its first render.
|
// Streamdown may replace a paragraph while settling its first render.
|
||||||
await expect.poll(async () => {
|
await expect.poll(async () => {
|
||||||
value = await readMetrics(element);
|
[value] = await readMetrics(element);
|
||||||
return value !== null && Number.isFinite(value.size) && Number.isFinite(value.line);
|
return value !== undefined && Number.isFinite(value.size) && Number.isFinite(value.line);
|
||||||
}).toBe(true);
|
}).toBe(true);
|
||||||
return value!;
|
return value!;
|
||||||
}
|
}
|
||||||
@@ -145,28 +144,40 @@ test("touch composer keeps literal mention metrics and a safe editable minimum",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
const input = page.getByRole("textbox", { name: "Message input", exact: true });
|
||||||
|
const overlay = page.locator(".thread-composer-input > div[aria-hidden]");
|
||||||
|
const layers = page.locator(".thread-composer-input > :is(div[aria-hidden], textarea)");
|
||||||
|
const readingSizes = [
|
||||||
|
["small", "Small reading text", 16],
|
||||||
|
["standard", "Standard reading text", 16],
|
||||||
|
["large", "Large reading text", 18],
|
||||||
|
] as const;
|
||||||
await input.fill("中文 English @typography 混排\n多行内容与光标保持一致,继续输入 more text.\n最后一行。");
|
await input.fill("中文 English @typography 混排\n多行内容与光标保持一致,继续输入 more text.\n最后一行。");
|
||||||
for (const label of ["Small reading text", "Standard reading text", "Large reading text"]) {
|
for (const [size, label, fontSize] of readingSizes) {
|
||||||
await page.getByRole("radio", { name: label, exact: true }).click();
|
await readingGroup.getByRole("radio", { name: label, exact: true }).click();
|
||||||
|
await expect(page.locator("html")).toHaveAttribute("data-reading-text-size", size);
|
||||||
|
await expect(input).toHaveCSS("font-size", `${fontSize}px`);
|
||||||
await input.focus();
|
await input.focus();
|
||||||
const overlay = page.locator(".thread-composer-input > div[aria-hidden]");
|
|
||||||
await expect(overlay).toContainText("@typography");
|
await expect(overlay).toContainText("@typography");
|
||||||
const text = await metrics(input);
|
// Sample both layers together; preference updates must not split the comparison.
|
||||||
expect(text.size).toBeGreaterThanOrEqual(16);
|
const [decoration, text] = await readMetrics(layers);
|
||||||
expect(await metrics(overlay)).toEqual(text);
|
expect(text.size).toBe(fontSize);
|
||||||
|
expect(decoration).toEqual(text);
|
||||||
expect(text.autospace).toBe("no-autospace");
|
expect(text.autospace).toBe("no-autospace");
|
||||||
expect(await input.evaluate(node => node.scrollHeight <= node.clientHeight + 1)).toBe(true);
|
expect(await input.evaluate(node => node.scrollHeight <= node.clientHeight + 1)).toBe(true);
|
||||||
expect(await page.evaluate(() => visualViewport?.scale)).toBe(1);
|
expect(await page.evaluate(() => visualViewport?.scale)).toBe(1);
|
||||||
}
|
}
|
||||||
await input.fill([...Array.from({ length: 18 }, (_, i) => `第 ${i + 1} 行 中文 English @typography 光标与装饰层。`), "最后一行。"].join("\n"));
|
await input.fill([...Array.from({ length: 18 }, (_, i) => `第 ${i + 1} 行 中文 English @typography 光标与装饰层。`), "最后一行。"].join("\n"));
|
||||||
for (const label of ["Small reading text", "Standard reading text", "Large reading text"]) {
|
for (const [size, label, fontSize] of readingSizes) {
|
||||||
await page.getByRole("radio", { name: label, exact: true }).click();
|
await readingGroup.getByRole("radio", { name: label, exact: true }).click();
|
||||||
|
await expect(page.locator("html")).toHaveAttribute("data-reading-text-size", size);
|
||||||
|
await expect(input).toHaveCSS("font-size", `${fontSize}px`);
|
||||||
await input.focus();
|
await input.focus();
|
||||||
await input.press("Control+End");
|
await input.press("Control+End");
|
||||||
const overlay = page.locator(".thread-composer-input > div[aria-hidden]");
|
|
||||||
expect(await input.evaluate(node => node.scrollHeight > node.clientHeight)).toBe(true);
|
expect(await input.evaluate(node => node.scrollHeight > node.clientHeight)).toBe(true);
|
||||||
await expect.poll(async () => Math.abs(await input.evaluate(node => node.scrollTop) - await overlay.evaluate(node => node.scrollTop))).toBeLessThanOrEqual(1);
|
await expect.poll(async () => Math.abs(await input.evaluate(node => node.scrollTop) - await overlay.evaluate(node => node.scrollTop))).toBeLessThanOrEqual(1);
|
||||||
expect(await metrics(overlay)).toEqual(await metrics(input));
|
const [decoration, text] = await readMetrics(layers);
|
||||||
|
expect(text.size).toBe(fontSize);
|
||||||
|
expect(decoration).toEqual(text);
|
||||||
}
|
}
|
||||||
await page.keyboard.press("End");
|
await page.keyboard.press("End");
|
||||||
await page.keyboard.type("追加文字");
|
await page.keyboard.type("追加文字");
|
||||||
|
|||||||
Reference in new issue
Block a user