mirror of
https://github.com/Minireel/HGhub.git
synced 2026-12-06 14:19:36 +08:00
131 lines
11 KiB
JavaScript
131 lines
11 KiB
JavaScript
import { openRecommendations, selectCategorySource, playerPanel, chooseEpisode } from "./frontend-navigation.mjs";
|
|
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
export async function testPluginSocial({ page, dispatch, root, base, output, report, rail }) {
|
|
const code = (await readFile(join(root, "src-tauri/crates/hpp/tests/fixtures/social.js"), "utf8")).replaceAll("__FIXTURE_BASE__", base);
|
|
assert((await dispatch({ action: "import", params: { code } })).ok);
|
|
assert((await dispatch({ action: "library.put", params: { pluginId: "fixture.social", item: { id: "social:media", title: "虚构互动作品" }, favorite: true } })).ok);
|
|
const events = async () => {
|
|
const response = await dispatch({ action: "call", params: { id: "fixture.social", method: "ui.submit", args: { actionId: "events", values: {} }, requestId: crypto.randomUUID() } });
|
|
assert(response.ok); return JSON.parse(response.value.message);
|
|
};
|
|
const openDetail = async () => {
|
|
await rail.getByRole("button", { name: "我的", exact: true }).click();
|
|
await page.getByRole("button", {name:"收藏",exact:true}).click();
|
|
await page.locator(".hpp-local-entry").filter({ has: page.getByRole("heading", { name: "虚构互动作品", exact: true }) }).getByRole("button", { name: "查看作品", exact: true }).click();
|
|
await playerPanel(page, '详情');
|
|
await page.getByRole("heading", { name: "虚构互动作品", exact: true }).first().waitFor();
|
|
};
|
|
await page.reload(); await openDetail();
|
|
// The state machine is checked with a monotonic fake clock, without a 30-second sleep.
|
|
const reports = await page.evaluate(async () => {
|
|
const { createProgressReporter } = await import("/src/plugins/progressReporter.ts");
|
|
let now = 0; const sent = [];
|
|
const reporter = createProgressReporter("media:opaque", value => sent.push(value), () => now);
|
|
reporter.select("ep:one"); reporter.update(2, 90); reporter.playing(); reporter.playing();
|
|
now = 29_999; reporter.update(31, 90); now = 30_000; reporter.update(32, 90); reporter.update(33, 90);
|
|
reporter.pause(); reporter.pause(); reporter.playing(); now = 60_000; reporter.update(60, 90);
|
|
reporter.end(); reporter.end(); reporter.select("ep:two", 4); reporter.playing(); reporter.pause();
|
|
return sent;
|
|
});
|
|
assert.deepEqual(reports.map(r => [r.episodeId, r.event]), [["ep:one", "start"], ["ep:one", "heartbeat"], ["ep:one", "pause"], ["ep:one", "heartbeat"], ["ep:one", "end"], ["ep:two", "start"], ["ep:two", "pause"]]);
|
|
assert.equal(reports[0].positionSec, 2); assert.equal(reports[0].durationSec, 90); assert.equal(reports[5].positionSec, 4);
|
|
await chooseEpisode(page, '互动第一集');
|
|
await page.waitForFunction(() => document.querySelector("video")?.currentTime > 0.5);
|
|
await page.evaluate(() => document.querySelector("video").pause());
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await page.getByRole("button", { name: "前往插件登录", exact: true }).count(), 0);
|
|
const initialEvents = await events();
|
|
assert(initialEvents.some(e => e.method === "progress.report" && e.args.event === "start" && e.args.episodeId === "ep:one"));
|
|
assert(initialEvents.some(e => e.method === "progress.report" && e.args.event === "pause"));
|
|
await playerPanel(page, '评论');
|
|
await page.getByText("<b>评论纯文本</b>", { exact: true }).waitFor();
|
|
assert.equal(await page.locator(".hpp-comment-text b").count(), 0);
|
|
await page.getByLabel("评论内容", { exact: true }).fill("保留未登录评论");
|
|
await page.getByRole("button", { name: "发送评论", exact: true }).click();
|
|
await page.getByRole("button", { name: "前往插件登录", exact: true }).waitFor();
|
|
assert.equal(await page.getByLabel("评论内容", { exact: true }).inputValue(), "保留未登录评论");
|
|
await page.getByRole("button", { name: "前往插件登录", exact: true }).click();
|
|
await page.getByRole("button", { name: "登录互动账号", exact: true }).click();
|
|
await page.getByText("互动观众", { exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "返回", exact: true }).click();
|
|
await playerPanel(page, '详情'); await page.locator('.legacy-panel-body').getByRole('button', { name: '云端点赞', exact: true }).click();
|
|
await page.getByRole("button", { name: "取消云端点赞", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "云端收藏", exact: true }).click();
|
|
await page.getByRole("button", { name: "取消云端收藏", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "关注作者 · 虚构作者", exact: true }).click();
|
|
await page.getByRole("button", { name: "取消关注作者 · 虚构作者", exact: true }).waitFor();
|
|
await playerPanel(page, '评论');
|
|
await page.getByRole("button", { name: "更多评论", exact: true }).click();
|
|
await page.getByText("分页评论二", { exact: true }).waitFor();
|
|
const parent = page.locator("article.hpp-comment").filter({ has: page.getByText("<b>评论纯文本</b>", { exact: true }) });
|
|
await parent.getByRole("button", { name: "点赞评论 · 0", exact: true }).click();
|
|
await parent.getByRole("button", { name: "取消评论点赞 · 1", exact: true }).waitFor();
|
|
await parent.getByRole("button", { name: "查看回复 · 2", exact: true }).click();
|
|
await parent.getByText("分页回复一", { exact: true }).waitFor();
|
|
await parent.getByRole("button", { name: "更多评论", exact: true }).click();
|
|
await parent.getByText("分页回复二", { exact: true }).waitFor();
|
|
const unsupportedReply = parent.locator("article.hpp-comment").filter({ has: page.getByText("分页回复二", { exact: true }) });
|
|
await unsupportedReply.getByRole("button", { name: "点赞评论 · 0", exact: true }).click();
|
|
await unsupportedReply.getByRole("button", { name: "点赞评论 · 0", exact: true }).waitFor({ state: "hidden" });
|
|
await parent.getByLabel("回复内容", { exact: true }).fill("给父评论的回复");
|
|
await parent.getByRole("button", { name: "发送回复", exact: true }).click();
|
|
await parent.getByText("给父评论的回复", { exact: true }).waitFor();
|
|
await page.getByLabel("评论内容", { exact: true }).fill("返回的新评论");
|
|
await page.getByRole("button", { name: "发送评论", exact: true }).click();
|
|
await page.getByText("返回的新评论", { exact: true }).waitFor();
|
|
await page.getByLabel("评论内容", { exact: true }).fill("无返回评论");
|
|
await page.getByRole("button", { name: "发送评论", exact: true }).click();
|
|
await page.waitForFunction(() => document.querySelector('[aria-label="评论内容"]')?.value === "");
|
|
await page.getByRole("button", { name: "当前分集评论", exact: true }).click();
|
|
await page.getByText("<b>评论纯文本</b>", { exact: true }).waitFor();
|
|
await chooseEpisode(page, '互动第二集');
|
|
await playerPanel(page, '评论');
|
|
await page.getByRole('button', {name:'当前分集评论',exact:true}).click();
|
|
await page.getByText("此来源不支持这类评论。", { exact: true }).waitFor();
|
|
assert.equal(await page.getByRole("button", { name: "发送评论", exact: true }).count(), 0);
|
|
await page.waitForFunction(() => document.querySelector("video")?.currentTime > 0.5);
|
|
await page.evaluate(() => { const video = document.querySelector("video"); video.pause(); video.currentTime = 2; video.dispatchEvent(new Event("ended", { bubbles: true })); });
|
|
await page.getByRole("button", { name: "作品评论", exact: true }).click();
|
|
await page.getByText("<b>评论纯文本</b>", { exact: true }).waitFor();
|
|
await page.screenshot({ path: join(output, "social-comments.png") });
|
|
await page.getByLabel("评论内容", { exact: true }).fill("发送不支持");
|
|
await page.getByRole("button", { name: "发送评论", exact: true }).click();
|
|
await page.getByText("此来源不支持向这里发送评论。", { exact: true }).waitFor();
|
|
assert.equal(await page.getByRole("button", { name: "发送评论", exact: true }).count(), 0);
|
|
assert.equal(await page.getByText("<b>评论纯文本</b>", { exact: true }).count(), 1);
|
|
const allEvents = await events();
|
|
assert(allEvents.some(e => e.method === "comments.send" && e.args.target.kind === "replies" && e.args.target.commentId === "comment-one"));
|
|
assert(allEvents.some(e => e.method === "comments.list" && e.args.target.episodeId === "ep:one"));
|
|
assert(allEvents.some(e => e.method === "interact.like" && e.args.target.mediaId === "social:media" && e.args.on));
|
|
assert(allEvents.some(e => e.method === "interact.follow" && e.args.authorId === "creator:opaque"));
|
|
assert(allEvents.some(e => e.method === "progress.report" && e.args.event === "end" && e.args.episodeId === "ep:two"));
|
|
await page.getByRole("button", { name: "返回", exact: true }).click();
|
|
await page.getByRole("button", { name: "来自片源", exact: true }).click();
|
|
const account = page.locator("section.hpp-account").filter({ has: page.getByRole("heading", { name: "虚构评论影院", exact: true }) });
|
|
await account.getByRole("button", { name: "云端收藏", exact: true }).click();
|
|
await account.getByLabel("虚构评论影院收藏目录", { exact: true }).selectOption("folder:opaque");
|
|
await account.getByRole("button", { name: /目录内作品/ }).waitFor();
|
|
await account.getByRole("button", { name: "云端关注", exact: true }).click();
|
|
await account.getByText("虚构作者", { exact: true }).waitFor();
|
|
await account.getByRole("button", { name: "更多关注", exact: true }).click();
|
|
await account.getByText("第二位作者", { exact: true }).waitFor();
|
|
await account.getByRole("button", { name: "取消关注 · 虚构作者", exact: true }).click();
|
|
await account.getByText("虚构作者", { exact: true }).waitFor({ state: "hidden" });
|
|
const libraryEvents = await events();
|
|
assert(libraryEvents.some(e => e.method === "library.listMedia" && e.args.folderId === "folder:opaque"));
|
|
assert(libraryEvents.some(e => e.method === "interact.follow" && e.args.authorId === "creator:opaque" && e.args.on === false));
|
|
await openDetail();
|
|
await playerPanel(page, '评论');
|
|
await page.getByLabel("评论内容", { exact: true }).fill("取消中的评论");
|
|
await page.getByRole("button", { name: "发送评论", exact: true }).click();
|
|
await page.getByRole("button", { name: "正在发送…", exact: true }).waitFor();
|
|
await page.getByRole("button", { name: "返回", exact: true }).click();
|
|
await page.waitForTimeout(1800);
|
|
assert(!(await events()).some(e => e.method === "comments.send" && e.args.text === "取消中的评论"));
|
|
report.passed.push("Comments/replies use opaque targets, page independently, render text literally, preserve failed drafts, insert returned comments or reload on void, hide unsupported episode actions; cloud interactions and folders/following stay provider-scoped");
|
|
report.passed.push("Playback reports actual start/pause/end silently on auth failure; monotonic 30-second heartbeat, no duplicate start during stream reload/resume, and real episode identity are verified");
|
|
}
|