mirror of
https://github.com/Minireel/HGhub.git
synced 2026-12-02 04:20:34 +08:00
93 lines
7.7 KiB
JavaScript
93 lines
7.7 KiB
JavaScript
import { openRecommendations, selectCategorySource } from "./frontend-navigation.mjs";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
export async function testPluginBrowsing({ page, dispatch, root, output, report, rail }) {
|
|
const template = await readFile(join(root, "src-tauri/crates/hpp/tests/fixtures/browsing.js"), "utf8");
|
|
const ids = ["fixture.browse-a", "fixture.browse-b"], names = ["分页影院甲", "分页影院乙"];
|
|
const call = async (id, actionId = "inspect") => {
|
|
const r = await dispatch({ action: "call", params: { id, method: "ui.submit", args: { actionId, values: {} }, requestId: crypto.randomUUID() } });
|
|
assert(r.ok, JSON.stringify(r)); return JSON.parse(r.value.message);
|
|
};
|
|
for (let i = 0; i < ids.length; i++) {
|
|
const result = await dispatch({ action: "import", params: { code: template.replaceAll("__PLUGIN_ID__", ids[i]).replaceAll("__PLUGIN_NAME__", names[i]) } });
|
|
assert(result.ok && result.value.status === "ready", JSON.stringify(result));
|
|
}
|
|
await page.reload();
|
|
await selectCategorySource(page,names[0]);
|
|
const tabs = page.getByRole("navigation", {name:"分类片源"});
|
|
for (const name of names) await tabs.getByRole("button", { name, exact: true }).waitFor();
|
|
await tabs.getByRole("button", { name: names[0], exact: true }).click();
|
|
await page.getByRole("button", { name: /分页影院甲 · 分类默认 · 0/ }).waitFor();
|
|
await page.locator(".legacy-category-heading").first().click();
|
|
const scrollToBottom = async () => { await page.locator(".hpp-media-card:visible, .legacy-search-poster:visible").first().waitFor(); await page.locator(".hpp-more:visible").last().scrollIntoViewIfNeeded(); };
|
|
await scrollToBottom();
|
|
await page.getByRole("alert").filter({ hasText: "虚构下一页失败" }).waitFor();
|
|
assert.equal(await page.locator(".hpp-media-card:visible").count(), 18, "Failed append retains the first page");
|
|
await page.getByRole("button", { name: "重试分类", exact: true }).click();
|
|
await page.getByRole("button", { name: /分页影院甲 · 分类默认 · 21/ }).waitFor();
|
|
await scrollToBottom();
|
|
await page.getByRole("alert").filter({ hasText: "重复分页游标" }).waitFor();
|
|
assert.equal(await page.locator(".hpp-media-card:visible").count(), 23, "All pages deduplicate IDs");
|
|
const catalogCalls = (await call(ids[0])).filter(c => c.method === "catalog.list");
|
|
assert.equal(catalogCalls.filter(c => c.args.cursor === "opaque:second").length, 2);
|
|
assert.equal(catalogCalls.filter(c => c.args.cursor === "opaque:third").length, 1);
|
|
await page.getByLabel("分类排序", { exact: true }).selectOption("slow");
|
|
await page.getByLabel("分类排序", { exact: true }).selectOption("fast");
|
|
await page.getByRole("button", { name: /分类fast · 0/ }).waitFor();
|
|
assert.equal(await page.getByRole("button", { name: /分类slow/ }).count(), 0);
|
|
await page.getByLabel("2026", { exact: true }).check();
|
|
await page.getByRole("button", { name: /分类fast2026 · 0/ }).waitFor();
|
|
assert.equal(await page.getByRole("button", { name: /分类fast · / }).count(), 0, "Filter starts a separate cursor chain");
|
|
const metadataCalls = (await call(ids[0])).filter(c => c.method === "catalog.getCategories").length;
|
|
await rail.getByRole("button", { name: "搜索", exact: true }).click();
|
|
await page.locator(".refined-scope-segments").getByRole("button", { name: "单个来源", exact: true }).click();
|
|
await page.locator(".hpp-scope").getByRole("radio", { name: names[0], exact: true }).check();
|
|
const search = async q => { await page.getByRole("textbox", { name: "搜索所有插件", exact: true }).fill(q); await page.locator(".hpp-search").getByRole("button", { name: "搜索", exact: true }).click(); };
|
|
await search("slow"); await search("fast");
|
|
await page.getByRole("button", { name: /搜索fast · 0/ }).waitFor();
|
|
await scrollToBottom(); await page.getByRole("alert").filter({ hasText: "虚构下一页失败" }).waitFor();
|
|
await page.getByRole("button", { name: "重试搜索", exact: true }).click();
|
|
await page.getByRole("button", { name: /搜索fast · 21/ }).waitFor();
|
|
await scrollToBottom(); await page.getByRole("alert").filter({ hasText: "重复分页游标" }).waitFor();
|
|
assert.equal(await page.locator(".legacy-search-poster:visible").count(), 23);
|
|
assert.equal(await page.getByRole("button", { name: /搜索slow/ }).count(), 0);
|
|
await page.screenshot({ path: join(output, "browsing-pagination.png") });
|
|
await page.locator(".refined-scope-segments").getByRole("button", { name: "多个来源", exact: true }).click();
|
|
await page.locator(".hpp-scope").getByRole("checkbox", { name: names[1], exact: true }).check();
|
|
await search("partial");
|
|
await page.getByRole("button", { name: `${names[1]} · 0`, exact: true }).waitFor();
|
|
await page.getByRole("button", { name: `${names[1]} · 0`, exact: true }).click();
|
|
await page.getByRole("alert").filter({ hasText: "虚构单源搜索失败" }).waitFor();
|
|
await page.getByRole("button", { name: `${names[0]} · 18`, exact: true }).click();
|
|
await page.getByRole("button", { name: /搜索partial · 0/ }).waitFor();
|
|
await openRecommendations(page,names[0]);
|
|
const alpha = page.getByLabel(`${names[0]}的推荐`, {exact:true});
|
|
await alpha.getByRole("heading", {name:`分页推荐${names[0]}`,exact:true}).waitFor();
|
|
await call(ids[0], "failHome");
|
|
await page.getByRole("button", { name: "刷新推荐", exact: true }).click();
|
|
await alpha.getByRole("alert").filter({ hasText: "虚构推荐刷新失败" }).waitFor();
|
|
await alpha.getByRole("heading", { name: `分页推荐${names[0]}`, exact: true }).waitFor();
|
|
// Full-section list shares viewport loading, retries and opaque cursor behavior.
|
|
await alpha.getByRole("button", { name: "查看更多", exact: true }).click();
|
|
await page.getByRole("button", { name: /分页影院甲 · 分区 · 0/ }).waitFor();
|
|
await scrollToBottom(); await page.getByRole("alert").filter({ hasText: "虚构下一页失败" }).waitFor();
|
|
await page.getByRole("button", { name: "重试分区", exact: true }).click();
|
|
await page.getByRole("button", { name: /分区 · 21/ }).waitFor();
|
|
await scrollToBottom(); await page.getByRole("alert").filter({ hasText: "重复分页游标" }).waitFor();
|
|
assert.equal(await page.locator(".hpp-media-card:visible").count(), 23);
|
|
await rail.getByRole("button", { name: "分类", exact: true }).click();
|
|
await tabs.getByRole("button", { name: names[0], exact: true }).click();
|
|
await page.getByRole("button", { name: /分页影院甲 · 分类默认 · 0/ }).waitFor();
|
|
assert.equal((await call(ids[0])).filter(c => c.method === "catalog.getCategories").length, metadataCalls, "Fulfilled category metadata is cached for the plugin revision");
|
|
const revised = template.replaceAll("__PLUGIN_ID__", ids[0]).replaceAll("__PLUGIN_NAME__", names[0]).replace("分页短剧", "修订后的分类");
|
|
await page.evaluate(async code => { const { pluginCommand } = await import("/src/plugins/client.ts"); await pluginCommand("import", { code }); }, revised);
|
|
await page.locator(".legacy-category-heading").filter({hasText:"修订后的分类"}).waitFor();
|
|
assert((await call(ids[0])).filter(c => c.method === "catalog.getCategories").length > metadataCalls, "Same-version replacement invalidates category metadata");
|
|
await rail.getByRole("button", { name: "首页", exact: true }).click();
|
|
for (const id of ids) assert((await dispatch({ action: "remove", params: { id } })).ok);
|
|
await page.reload();
|
|
report.passed.push("Category provider tabs, category preview/drilldown, recommendation refresh preserving existing content, viewport pagination with failed-cursor retry, ID deduplication, repeated-cursor termination, filter/query cancellation and independent multi-source search all use production UI");
|
|
}
|