journey-03-book-generate.spec.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * 关键旅程 E2E 测试 03: 书籍生成完整流水线
  3. * Journey: 预估字数 → 检测书籍类型 → 创建书籍 → 查询进度 → 获取书籍列表
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, initApiClient, disposeApiClient, setAuthToken } from '../../../helpers/api-client';
  7. const FRONTEND_URL = process.env.FRONTEND_URL || 'http://localhost:5173';
  8. test.describe('关键旅程 03: 书籍生成流水线', () => {
  9. let phone: string;
  10. let authToken: string;
  11. let bookId: string;
  12. test.beforeAll(async () => {
  13. await initApiClient();
  14. phone = `138${String(Date.now()).slice(-8)}`;
  15. await apiPost('/api/auth/send-code', { phone });
  16. const loginRes = await apiPost('/api/auth/login', { phone, code: '123456' });
  17. authToken = loginRes.data?.token;
  18. setAuthToken(authToken);
  19. });
  20. test.afterAll(async () => {
  21. await disposeApiClient();
  22. });
  23. test('C03-1: 预估字数和时长', async () => {
  24. const res = await apiGet('/api/book-generator/langgraph/estimate', {
  25. scale: '5000',
  26. });
  27. expect(res.code).toBe(0);
  28. expect(res.data?.audioMinutes).toBeDefined();
  29. expect(res.data?.estimatedChapters).toBeGreaterThan(0);
  30. });
  31. test('C03-2: 检测书籍类型', async () => {
  32. const res = await apiPost('/api/book-generator/langgraph/detect-book-type', {
  33. topic: '人工智能简史',
  34. });
  35. expect(res.code).toBe(0);
  36. expect(['技术', '科普', '学术', '其他']).toContain(res.data?.bookType);
  37. });
  38. test('C03-3: 创建书籍', async () => {
  39. const res = await apiPost('/api/book-generator/langgraph/books', {
  40. title: `自动化测试书籍_${Date.now()}`,
  41. topic: '人工智能发展史',
  42. wordCount: 30000,
  43. strategy: 'deep-plan-parallel',
  44. });
  45. expect(res.code).toBe(0);
  46. bookId = res.data?.book?.id;
  47. expect(bookId).toBeDefined();
  48. });
  49. test('C03-4: 获取书籍详情', async () => {
  50. if (!bookId) return test.skip();
  51. const res = await apiGet(`/api/book-generator/langgraph/books/${bookId}`);
  52. expect(res.code).toBe(0);
  53. expect(res.data?.id).toBe(bookId);
  54. });
  55. test('C03-5: 获取章节列表', async () => {
  56. if (!bookId) return test.skip();
  57. const res = await apiGet(`/api/book-generator/langgraph/books/${bookId}/chapters`);
  58. expect(res.code).toBe(0);
  59. });
  60. test('C03-6: 获取用户书籍列表', async () => {
  61. const res = await apiGet('/api/book-generator/langgraph/books');
  62. expect(res.code).toBe(0);
  63. expect(Array.isArray(res.data?.books)).toBe(true);
  64. });
  65. test('C03-7: 书籍生成列表页可访问', async ({ page }) => {
  66. await page.goto(`${FRONTEND_URL}/#/pages/book-generator/index`, { waitUntil: 'networkidle', timeout: 30000 });
  67. await page.waitForTimeout(3000);
  68. await expect(page.locator('text=书籍生成').first()).toBeVisible();
  69. });
  70. test('C03-8: 书籍创建页可访问', async ({ page }) => {
  71. await page.goto(`${FRONTEND_URL}/#/pages/book-generator/create`, { waitUntil: 'networkidle', timeout: 30000 });
  72. await page.waitForTimeout(3000);
  73. await expect(page.locator('text=创建书籍').first()).toBeVisible();
  74. });
  75. });