style(webui): refine Markdown reading typography (#6568)
* style(webui): refine Markdown reading typography * fix(webui): stabilize composer and typography checks
This commit is contained in:
1 parent
0c92d5bb03
commit
e6127aa324
17 files changed
+307
-100
No files matched your search
@@ -52,7 +52,7 @@ test("custom reading size previews, persists and survives preset changes", async
|
||||
await page.reload();
|
||||
await expect(input).toHaveValue("24");
|
||||
await page.getByRole("radio", { name: "Small reading text", exact: true }).click();
|
||||
await expect(paragraph).toHaveCSS("font-size", "16px");
|
||||
await expect(paragraph).toHaveCSS("font-size", "15px");
|
||||
await page.getByRole("spinbutton", { name: "Custom text size", exact: true }).click();
|
||||
await expect(input).toHaveValue("24");
|
||||
await expect(paragraph).toHaveCSS("font-size", "24px");
|
||||
|
||||
@@ -61,9 +61,7 @@ for (const width of [1440, 390]) {
|
||||
const bubble = page.locator("[data-user-text-bubble]");
|
||||
const text = bubble.locator("p");
|
||||
const trigger = page.locator("[data-message-block-menu-trigger]");
|
||||
const fontSize = width === 390
|
||||
? { small: 15, standard: 16, large: 18 }[size]
|
||||
: { small: 16, standard: 18, large: 20 }[size];
|
||||
const fontSize = { small: 15, standard: 16, large: 18 }[size];
|
||||
await expect(text).toHaveCSS("font-size", `${fontSize}px`);
|
||||
await bubble.hover();
|
||||
await expect(trigger).toBeVisible();
|
||||
|
||||
@@ -147,3 +147,56 @@ test("idle voice and ready send remain distinct from the composer in both themes
|
||||
}
|
||||
await test.info().attach("action-contrast", { body: JSON.stringify(measurements, null, 2), contentType: "application/json" });
|
||||
});
|
||||
|
||||
|
||||
test("a long mobile placeholder remains available without shifting the composer", async ({ browser, baseURL }) => {
|
||||
const context = await browser.newContext({ baseURL, viewport: { width: 314, height: 844 }, hasTouch: true, isMobile: true, reducedMotion: "reduce" });
|
||||
try {
|
||||
const page = await context.newPage();
|
||||
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "fr"));
|
||||
await page.goto("/browser/fixture.html?case=composer-action&composerVariant=thread");
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
const input = page.locator(".thread-composer-input textarea");
|
||||
const action = page.locator(".composer-primary-action");
|
||||
await expect(input).toHaveAttribute("placeholder", /compétences/);
|
||||
const placeholder = (await input.getAttribute("placeholder"))!;
|
||||
await expect(input).toHaveAttribute("aria-description", placeholder);
|
||||
await expect(page.getByRole("tooltip")).toHaveCount(0);
|
||||
const before = (await action.boundingBox())!;
|
||||
const initialHeight = await input.evaluate(node => node.clientHeight);
|
||||
|
||||
await input.tap();
|
||||
const hint = page.getByRole("tooltip");
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
const hintSurface = page.locator('[data-radix-popper-content-wrapper] [data-side]').first();
|
||||
const composer = page.locator(".thread-composer-form");
|
||||
await expect.poll(async () => {
|
||||
const [hintBox, composerBox] = await Promise.all([hintSurface.boundingBox(), composer.boundingBox()]);
|
||||
return !!hintBox && !!composerBox && (hintBox.y + hintBox.height <= composerBox.y || hintBox.y >= composerBox.y + composerBox.height);
|
||||
}).toBe(true);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
|
||||
await input.fill("Bonjour");
|
||||
await expect(hint).toHaveCount(0);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
await input.fill("Première ligne\nDeuxième ligne\nTroisième ligne");
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBeGreaterThan(initialHeight);
|
||||
await input.fill("");
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
await expect.poll(() => input.evaluate(node => node.clientHeight)).toBe(initialHeight);
|
||||
expect(await action.boundingBox()).toEqual(before);
|
||||
await input.press("Escape");
|
||||
await expect(hint).toHaveCount(0);
|
||||
|
||||
await page.locator(".thread-composer-footer button").first().focus();
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await expect(input).toBeFocused();
|
||||
await expect(hint).toHaveText(placeholder);
|
||||
const box = (await input.boundingBox())!;
|
||||
await page.mouse.move(box.x + 5, box.y + 5);
|
||||
await page.mouse.move(1, 800);
|
||||
await expect(hint).toHaveCount(0);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
@@ -117,9 +117,9 @@ test("multiline drafts resize after reading typography changes", async ({ page }
|
||||
await input.fill("First line\nSecond line\nThird line");
|
||||
const standardHeight = await input.evaluate(node => node.clientHeight);
|
||||
const sizes = [
|
||||
["large", "Large reading text", 20],
|
||||
["large", "Large reading text", 18],
|
||||
["small", "Small reading text", 16],
|
||||
["standard", "Standard reading text", 18],
|
||||
["standard", "Standard reading text", 16],
|
||||
] as const;
|
||||
for (const [size, label, fontSize] of sizes) {
|
||||
await page.getByRole("radio", { name: label, exact: true }).click();
|
||||
@@ -128,7 +128,6 @@ test("multiline drafts resize after reading typography changes", async ({ page }
|
||||
expect(await input.evaluate(node => node.scrollHeight <= node.clientHeight + 1)).toBe(true);
|
||||
const height = await input.evaluate(node => node.clientHeight);
|
||||
if (size === "large") expect(height).toBeGreaterThan(standardHeight);
|
||||
else if (size === "small") expect(height).toBeLessThan(standardHeight);
|
||||
else expect(height).toBe(standardHeight);
|
||||
}
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import { MarkdownText } from "@/components/MarkdownText";
|
||||
export function DisplayMathFixture() {
|
||||
const [step, setStep] = useState(0);
|
||||
const [streaming, setStreaming] = useState(true);
|
||||
const terms = step === 0 ? "x + y" : Array.from({ length: 24 }, (_, index) => `x_{${index}}`).join(" + ");
|
||||
const terms = step === 0 ? "x + y" : Array.from({ length: 36 }, (_, index) => `x_{${index}}`).join(" + ");
|
||||
const tag = step < 2 ? "1" : "1000000";
|
||||
return <main className="mx-auto max-w-3xl p-6">
|
||||
<button onClick={() => setStep((value) => value + 1)}>Advance stream</button>
|
||||
|
||||
@@ -14,6 +14,7 @@ const createdAt = Date.now() / 1000;
|
||||
let streamLength = 0;
|
||||
let inputNumber = 0;
|
||||
const saveTasks = new URLSearchParams(location.search).has("saved");
|
||||
const historyParagraphs = new URLSearchParams(location.search).has("long-history") ? 20 : 12;
|
||||
const taskStorageKey = "fixture.subagent-dock.tasks";
|
||||
const taskLabels = new URLSearchParams(location.search).has("long-labels")
|
||||
? ["核对多轮任务完成后的归档位置、长标题换行与独立详情入口", "Review_the_responsive_subtask_panel_and_keyboard_focus_without_interrupting_running_work", "整理交互建议"]
|
||||
@@ -28,7 +29,7 @@ const tasks: SubagentTaskSnapshot[] = taskLabels.map((label, index) => ({
|
||||
const history: ThreadProjectionEvent[] = [
|
||||
{ event: "user_message", chat_id: chatId, projection_id: "preview-prompt", turn_id: turnId, text: "请让三个子任务分别检查实现、测试和交互。主对话继续讨论,不要等它们全部结束。", starts_turn: true },
|
||||
{ event: "message", chat_id: chatId, projection_id: "preview-answer", turn_id: turnId,
|
||||
text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(12) },
|
||||
text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(historyParagraphs) },
|
||||
];
|
||||
|
||||
function updateTask(index: number, patch: Partial<SubagentTaskSnapshot>) {
|
||||
|
||||
@@ -349,13 +349,12 @@ test("does not retire a completed list or detail while it is being read", async
|
||||
for (const width of [1440, 390]) {
|
||||
test(`keeps the reading position when results are archived and the live entry retires at ${width}px`, async ({ page }) => {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock");
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock&long-history");
|
||||
const body = page.getByTestId("thread-message-region");
|
||||
const paragraphs = body.getByText("主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。", { exact: true });
|
||||
await expect(paragraphs).toHaveCount(12);
|
||||
await expect(paragraphs).toHaveCount(20);
|
||||
await settledMotion(body);
|
||||
const anchor = paragraphs.nth(6);
|
||||
await anchor.scrollIntoViewIfNeeded();
|
||||
const anchor = paragraphs.nth(13);
|
||||
await body.hover();
|
||||
await page.mouse.wheel(0, -160);
|
||||
await expect.poll(() => body.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeGreaterThan(100);
|
||||
|
||||
@@ -38,11 +38,12 @@ for (const narrow of [false, true]) {
|
||||
await expect(tables).toHaveCount(2);
|
||||
await expect(formulaTable.locator(".katex")).toHaveCount(7);
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
expect(await page.evaluate(() => Array.from(document.fonts).some((font) => font.family === "Open Sans" && font.status === "loaded"))).toBe(true);
|
||||
const observations = [];
|
||||
for (const [size, label, bodySize] of [
|
||||
["small", "阅读字号:小", narrow ? 15 : 16],
|
||||
["standard", "阅读字号:标准", narrow ? 16 : 18],
|
||||
["large", "阅读字号:大", narrow ? 18 : 20],
|
||||
["small", "阅读字号:小", 15],
|
||||
["standard", "阅读字号:标准", 16],
|
||||
["large", "阅读字号:大", 18],
|
||||
] as const) {
|
||||
await group.getByRole("radio", { name: label, exact: true }).click();
|
||||
await expect(page.locator("html")).toHaveAttribute("data-reading-text-size", size);
|
||||
@@ -50,13 +51,14 @@ for (const narrow of [false, true]) {
|
||||
await expect(paragraph).toHaveCSS("font-size", `${bodySize}px`);
|
||||
const body = await metrics(paragraph);
|
||||
expect(body.size).toBe(bodySize);
|
||||
expect(body.line).toBeCloseTo(bodySize * 1.8);
|
||||
expect(body.line).toBeCloseTo(bodySize * 1.6);
|
||||
expect(body.weight).toBe("400");
|
||||
expect(body.family).toContain("Open Sans");
|
||||
expect((await metrics(page.locator("[data-user-text-bubble] p"))).size).toBe(bodySize);
|
||||
for (const selector of ["blockquote", "ol > li", ".task-list-item"]) {
|
||||
expect((await metrics(page.locator(`.markdown-content ${selector}`).first())).size).toBe(bodySize);
|
||||
}
|
||||
for (const [selector, ratio] of [["h1", 1.5], ["h2", 1.25], ["h3", 1.125], ["h4", 1]] as const) {
|
||||
for (const [selector, ratio] of [["h1", 2], ["h2", 1.5], ["h3", 1.25], ["h4", 1.125]] as const) {
|
||||
const heading = await metrics(page.locator(`.markdown-content ${selector}`));
|
||||
expect(heading.size).toBeCloseTo(bodySize * ratio);
|
||||
expect(heading.weight).toBe("600");
|
||||
@@ -128,7 +130,7 @@ test("keyboard, tooltip, persistence and unchanged preferences", async ({ page }
|
||||
const large = page.getByRole("radio", { name: "Large reading text", exact: true });
|
||||
await expect(large).toBeFocused();
|
||||
await expect(large).toBeChecked();
|
||||
await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${20 * 1.625}px`);
|
||||
await expect(page.locator(".markdown-content p").first()).toHaveCSS("line-height", `${18 * 1.6}px`);
|
||||
await page.reload();
|
||||
await expect(page.getByRole("radio", { name: "Large reading text", exact: true })).toBeChecked();
|
||||
expect(await page.evaluate(() => JSON.parse(localStorage.getItem("nanobot-webui.settings-preferences")!))).toMatchObject({
|
||||
|
||||
Reference in new issue
Block a user