Files
HGhubX/scripts/test-post-toast.mjs
makisekurisu-jp 5fa6132abd fix(ui): unify tag-pin and post action toasts into a single slot (#260)
## 改了什么

标签结果页快速连点置顶按钮时,提示会按无 tag 队列堆叠,最多 3 张。现在置顶、播放状态、Feed/帖子页点赞/收藏/关注统一使用
`ACTION_TOAST_SLOT`(值 `playback-hint`):同槽提示原地替换并重置计时,只保留最后一张。

帖子详情页的点赞/收藏成功与失败提示也接入同一槽,跨页面不再各自堆叠。

Before / After(真实 TagPage / PostDetail,Chromium 390×844):

![标签结果页置顶提示
before/after](https://raw.githubusercontent.com/makisekurisu-jp/HGhubX/e15aeb2/docs/design/tag-toast-slot-before-after.png)

![帖子页点赞收藏提示
before/after](https://raw.githubusercontent.com/makisekurisu-jp/HGhubX/e15aeb2/docs/design/post-toast-slot-before-after.png)

## 影响子系统

- [ ] `docs/subsystems/` page updated in this PR, or this is a pure move
that preserves its contracts — N/A:本次是 toast 生命周期修复,不改子系统契约
- Page: 标签结果页、标签聚合页、帖子详情页;共用 Feed 播放提示槽

## 验证

- Command: `npm run build`;`BROWSER_EXECUTABLE=/usr/local/bin/chromium
node
scripts/test-tag-pins.mjs`;`BROWSER_EXECUTABLE=/usr/local/bin/chromium
node
scripts/test-post-toast.mjs`;`BROWSER_EXECUTABLE=/usr/local/bin/chromium
npm run test:ui-feedback`
- Input / scenario: TagPage 快速连点置顶 3 次;PostDetail 连续点赞 +
收藏;再验证播放提示与置顶提示互相替换。
- Literal result and exit status: build exit 0;`PASS: tag-pins (13
checks)`;`PASS: post-toast (1 check)`;`test:ui-feedback` PASS。
- Which test fails without this change? `scripts/test-tag-pins.mjs`
在旧代码打印 `AssertionError: rapid pin taps must replace the same toast slot`
/ `3 !== 1`;`scripts/test-post-toast.mjs` 在旧代码打印 `post like and favorite
must share one toast slot` / `2 !== 1`。

## Rollback

回退本 PR 的提交即可恢复:置顶和帖子点赞/收藏提示回到无 tag 队列,置顶连点最多显示 3 张,帖子页点赞与收藏可同时堆叠。

## Checklist

- [x] One change, one goal; pure moves and behavior changes are separate
PRs
- [x] No new network origin, no weakened CSP/origin check, no secret in
logs
- [x] A behavior change comes with a test that fails on the old code
- [x] No size budget was raised without moving a concern out first
2026-11-25 22:53:06 +08:00

55 lines
2.7 KiB
JavaScript

import assert from "node:assert/strict";
import { access, mkdir } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import { createServer } from "vite";
import { chromium } from "playwright-core";
const root = fileURLToPath(new URL("../", import.meta.url));
const output = new URL("../test-results/post-toast/", import.meta.url);
await mkdir(output, { recursive: true });
const report = { environment: "Real PostDetail/AppProvider with mocked Tauri IPC", checks: [], errors: [] };
let vite, browser;
try {
vite = await createServer({ root, server: { host: "127.0.0.1", port: 0, strictPort: false, hmr: false } });
await vite.listen();
const origin = vite.resolvedUrls.local[0];
let executablePath = process.env.BROWSER_EXECUTABLE;
if (!executablePath) {
for (const candidate of ["/usr/bin/google-chrome", "/usr/bin/chromium", "/usr/bin/chromium-browser"]) {
if (await access(candidate).then(() => true, () => false)) { executablePath = candidate; break; }
}
}
browser = await chromium.launch({ headless: true, executablePath });
const context = await browser.newContext({ viewport: { width: 390, height: 844 } });
const page = await context.newPage();
page.on("pageerror", error => report.errors.push(error.message));
await page.route("**/*", route => {
const url = new URL(route.request().url());
if (url.origin === new URL(origin).origin) return route.continue();
return route.abort();
});
await page.goto(new URL("/tests/post-toast.html", origin).href, { waitUntil: "networkidle" });
await page.getByText("示例帖子").waitFor();
const actions = page.locator("button[aria-pressed]");
assert.equal(await actions.count(), 2, "post detail must expose like and favorite actions");
await actions.nth(0).click();
await page.waitForFunction(() => document.querySelector(".a-toast")?.textContent?.includes("已加入喜欢"));
await actions.nth(1).click();
await page.waitForTimeout(180);
assert.equal(await page.locator(".a-toast").count(), 1, "post like and favorite must share one toast slot");
assert.equal((await page.locator(".a-toast").innerText()).trim(), "已收藏", "the latest post action must replace the previous toast");
report.checks.push("post like and favorite share one toast slot");
await page.screenshot({ path: fileURLToPath(new URL("post-action-toast.png", output)), animations: "disabled" });
assert.deepEqual(report.errors, []);
report.passed = true;
console.log(`PASS: post-toast (${report.checks.length} check)`);
} catch (error) {
report.failure = String(error?.stack || error);
console.error(report.failure);
process.exitCode = 1;
} finally {
await browser?.close();
await vite?.close();
}