From b057c2d478391baef9fa2464f8eebc30e60b4568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E5=BA=94?= Date: Mon, 6 Jul 2026 15:39:46 +0800 Subject: [PATCH] fix(e2e): seed template and title data for new test users GeneratePage now loads templates from API instead of hardcoded list; TitlesPage loads titles from API. New E2E test users have no data, causing empty states and selector failures. - core-generation: POST /api/v1/templates before browser test - core-titles: POST /api/v1/titles before browser test Co-Authored-By: Claude Fable 5 --- apps/web/e2e/core-generation.spec.ts | 46 +++++++++++++++++++--------- apps/web/e2e/core-titles.spec.ts | 13 ++++++++ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/apps/web/e2e/core-generation.spec.ts b/apps/web/e2e/core-generation.spec.ts index 3d1f29237..358e0eab6 100755 --- a/apps/web/e2e/core-generation.spec.ts +++ b/apps/web/e2e/core-generation.spec.ts @@ -40,6 +40,7 @@ async function loginWithRetry( type ProjectResponse = { id: string }; type LibraryResponse = { id: string }; +type TemplateResponse = { id: string }; type AssetListResponse = { items: Array<{ id: string; @@ -126,6 +127,29 @@ test.describe("Core generation flow", () => { ) .toBe("ready"); + // Create an editing template so the generate page has at least one template + // (templates are now loaded from API; new users have none by default) + const template = await request.post(`${apiBase}/templates`, { + headers, + data: { + name: `E2E 测试模板 ${suffix}`, + mode: "pip", + estimated_duration: 30, + segments: [ + { + segment_order: 1, + duration_min: 5, + duration_max: 30, + material_type: "video", + }, + ], + tags: ["e2e"], + }, + }); + expect(template.status(), await template.text()).toBe(200); + const templateData = (await template.json()) as TemplateResponse; + expect(templateData.id).toBeTruthy(); + // Set auth in localStorage await page.addInitScript( ({ token, user }) => { @@ -163,38 +187,30 @@ test.describe("Core generation flow", () => { await page.getByRole("button", { name: "下一步" }).click(); // Step 2: select material - await expect( - page.getByRole("heading", { name: /选择素材/ }), - ).toBeVisible(); + await expect(page.getByRole("heading", { name: /选择素材/ })).toBeVisible(); const librarySelect = page.locator("select").first(); await librarySelect.selectOption({ label: libraryName }); const materialLabel = page.getByText(sourceFileName).locator(".."); - await expect( - materialLabel.locator("input[type='checkbox']"), - ).toBeVisible({ timeout: 10_000 }); + await expect(materialLabel.locator("input[type='checkbox']")).toBeVisible({ + timeout: 10_000, + }); await materialLabel.locator("input[type='checkbox']").check(); await page.getByRole("button", { name: "下一步" }).click(); // Step 3: title - await expect( - page.getByRole("heading", { name: /选择标题/ }), - ).toBeVisible(); + await expect(page.getByRole("heading", { name: /选择标题/ })).toBeVisible(); const titleText = `E2E Test ${suffix}`; await page.getByPlaceholder("输入自定义标题…").fill(titleText); await page.getByRole("button", { name: "下一步" }).click(); // Step 4: voice - await expect( - page.getByRole("heading", { name: /选择配音/ }), - ).toBeVisible(); + await expect(page.getByRole("heading", { name: /选择配音/ })).toBeVisible(); const firstVoiceCard = page.locator(".xx-voice-choice-item").first(); await firstVoiceCard.click(); await page.getByRole("button", { name: "下一步" }).click(); // Step 5: confirm and generate - await expect( - page.getByRole("heading", { name: /确认生成/ }), - ).toBeVisible(); + await expect(page.getByRole("heading", { name: /确认生成/ })).toBeVisible(); // Wait for plan creation API to be called const createPlanPromise = page.waitForResponse( diff --git a/apps/web/e2e/core-titles.spec.ts b/apps/web/e2e/core-titles.spec.ts index ff4f817ca..fff7e94a1 100755 --- a/apps/web/e2e/core-titles.spec.ts +++ b/apps/web/e2e/core-titles.spec.ts @@ -60,6 +60,19 @@ test.describe("Title library flow", () => { const login = await loginWithRetry(request, email, PASSWORD); expect(login.status(), await login.text()).toBe(200); const loginData = (await login.json()) as { access_token: string }; + const headers = { Authorization: `Bearer ${loginData.access_token}` }; + + // Create a title so the titles page has at least one title card to display + // (titles are loaded from API; new users have none by default) + const createTitle = await request.post(`${apiBase}/titles`, { + headers, + data: { + name: `E2E 测试标题 ${suffix}`, + text: `E2E 测试标题内容 ${suffix}`, + category: "default", + }, + }); + expect(createTitle.status(), await createTitle.text()).toBe(201); await page.addInitScript( ({ token, user }) => {