test(frontend): text search e2e with txt fixture (B2)
This commit is contained in:
@@ -4,6 +4,7 @@ import { request, type APIRequestContext } from "@playwright/test";
|
||||
|
||||
export const BASE = process.env.E2E_BASE_URL ?? "http://localhost:5173";
|
||||
export const FIXTURE_CBZ = fileURLToPath(new URL("../fixtures/e2e-sample.cbz", import.meta.url));
|
||||
export const FIXTURE_TXT = fileURLToPath(new URL("../fixtures/e2e-sample-txt.txt", import.meta.url));
|
||||
|
||||
/** UI 登录与 API fixture 共用同一管理员凭据:E2E_ADMIN_* 优先,回落 deploy/.env 注入的 ADMIN_*。 */
|
||||
export function creds(): { user: string; pass: string } {
|
||||
@@ -45,14 +46,19 @@ async function findBook(ctx: APIRequestContext, q: string): Promise<{ id: number
|
||||
}
|
||||
|
||||
/** 幂等:书已存在直接返回 id;否则上传 fixture → 触发扫描 → 轮询等书出现(扫描是 fire-and-forget)。 */
|
||||
export async function ensureSampleBook(ctx: APIRequestContext, libName: string): Promise<number> {
|
||||
const title = "e2e-sample";
|
||||
export async function ensureBook(
|
||||
ctx: APIRequestContext,
|
||||
libName: string,
|
||||
fileName: string,
|
||||
absPath: string,
|
||||
): Promise<number> {
|
||||
const title = fileName.replace(/\.[a-z]+$/i, "");
|
||||
const existing = await findBook(ctx, title);
|
||||
if (existing) return existing.id;
|
||||
const libId = await ensureLibrary(ctx, libName);
|
||||
const up = await ctx.post(`/api/libraries/${libId}/upload`, {
|
||||
multipart: {
|
||||
file: { name: "e2e-sample.cbz", mimeType: "application/zip", buffer: readFileSync(FIXTURE_CBZ) },
|
||||
file: { name: fileName, mimeType: "application/octet-stream", buffer: readFileSync(absPath) },
|
||||
},
|
||||
});
|
||||
if (!up.ok()) throw new Error(`上传失败:HTTP ${up.status()} ${await up.text()}`);
|
||||
@@ -66,3 +72,8 @@ export async function ensureSampleBook(ctx: APIRequestContext, libName: string):
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
/** CBZ 样本书便捷封装(auth-shelf 沿用)。 */
|
||||
export async function ensureSampleBook(ctx: APIRequestContext, libName: string): Promise<number> {
|
||||
return ensureBook(ctx, libName, "e2e-sample.cbz", FIXTURE_CBZ);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user