mini-games-full.spec.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * ================================================================
  3. * 场景:小游戏完整流程 E2E 测试
  4. * ================================================================
  5. * 用户故事:孩子完成小游戏任务(舒尔特方格/猜数字/数独)
  6. *
  7. * 流程步骤:
  8. * 1. 查看可选小游戏
  9. * 2. 完成舒尔特方格
  10. * 3. 完成猜数字
  11. * 4. 完成数独
  12. * 5. 进行认知训练
  13. *
  14. * 关键里程碑:
  15. * - [Milestone-1] 游戏1完成
  16. * - [Milestone-2] 认知训练完成
  17. * ================================================================
  18. *
  19. * 运行:npx playwright test tests/e2e/mini-games-full.spec.js
  20. */
  21. const { test, expect } = require('@playwright/test');
  22. test.describe('【场景流程】小游戏完整流程', () => {
  23. // ===== 场景1:查看可选小游戏 =====
  24. test('[场景1] 查看可选小游戏 - 期望返回游戏列表', async ({ page }) => {
  25. // ========== Given:创建任务时 ==========
  26. await page.goto('/#/pages/tasks/create-task');
  27. await page.waitForLoadState('networkidle');
  28. // ========== When:选择小游戏类型 ==========
  29. const gameSelect = page.locator('.minigame-picker, .game-type-select');
  30. if (await gameSelect.isVisible()) {
  31. await gameSelect.click();
  32. }
  33. // ========== Then:返回游戏列表 ========
  34. await page.waitForSelector('.game-option, .minigame-item', { timeout: 5000 });
  35. const gameOptions = page.locator('.game-option, .minigame-item');
  36. const count = await gameOptions.count();
  37. expect(count).toBeGreaterThan(0);
  38. });
  39. // ===== 场景2:完成舒尔特方格 =====
  40. test('[场景2] 完成舒尔特方格 - 期望游戏完成', async ({ page }) => {
  41. // ========== Given:进入舒尔特方格游戏 ==========
  42. await page.goto('/#/pages/games/schulte');
  43. await page.waitForLoadState('networkidle');
  44. // ========== When:完成游戏 ==========
  45. await page.waitForSelector('.schulte-grid, .game-grid', { timeout: 5000 });
  46. // 获取所有格子并按顺序点击
  47. const cells = page.locator('.grid-cell, .cell');
  48. const count = await cells.count();
  49. // 按数字顺序点击(假设数字从1开始显示)
  50. for (let i = 0; i < Math.min(count, 9); i++) {
  51. await cells.nth(i).click();
  52. await page.waitForTimeout(100);
  53. }
  54. // ========== Then:Milestone-1 - 游戏完成 ========
  55. await page.waitForSelector('.game-complete, .result-card', { timeout: 10000 });
  56. const resultCard = page.locator('.game-complete, .result-card');
  57. expect(await resultCard.isVisible()).toBeTruthy();
  58. });
  59. // ===== 场景3:完成猜数字 =====
  60. test('[场景3] 完成猜数字 - 期望游戏完成', async ({ page }) => {
  61. // ========== Given:进入猜数字游戏 ==========
  62. await page.goto('/#/pages/games/1a2b');
  63. await page.waitForLoadState('networkidle');
  64. // ========== When:进行游戏 ==========
  65. await page.waitForSelector('.guess-input, .input-area', { timeout: 5000 });
  66. // 输入猜测
  67. const input = page.locator('.guess-input, .number-input');
  68. if (await input.isVisible()) {
  69. await input.fill('1234');
  70. }
  71. // 提交猜测
  72. const submitBtn = page.locator('.submit-btn, .guess-btn');
  73. if (await submitBtn.isVisible()) {
  74. await submitBtn.click();
  75. }
  76. // ========== Then:返回猜测结果 ========
  77. await page.waitForSelector('.result-hint, .guess-result', { timeout: 5000 });
  78. const resultHint = page.locator('.result-hint, .guess-result');
  79. expect(await resultHint.isVisible()).toBeTruthy();
  80. });
  81. // ===== 场景4:完成数独 =====
  82. test('[场景4] 完成数独 - 期望游戏完成', async ({ page }) => {
  83. // ========== Given:进入数独游戏 ==========
  84. await page.goto('/#/pages/games/sudoku');
  85. await page.waitForLoadState('networkidle');
  86. // ========== When:进行游戏 ==========
  87. await page.waitForSelector('.sudoku-grid, .game-board', { timeout: 5000 });
  88. // 点击一个空格
  89. const emptyCell = page.locator('.cell.empty, .cell:not(.fixed)').first();
  90. if (await emptyCell.isVisible()) {
  91. await emptyCell.click();
  92. }
  93. // 选择数字
  94. const numBtn = page.locator('.num-btn:has-text("1")').first();
  95. if (await numBtn.isVisible()) {
  96. await numBtn.click();
  97. }
  98. // ========== Then:数字填入 ========
  99. await page.waitForTimeout(500);
  100. const filledCell = page.locator('.cell.filled');
  101. const hasFilled = await filledCell.count() > 0;
  102. expect(hasFilled).toBeTruthy();
  103. });
  104. // ===== 场景5:进行认知训练 =====
  105. test('[场景5] 进行认知训练 - 期望训练记录生成', async ({ page }) => {
  106. // ========== Given:进入智维度 ==========
  107. await page.goto('/#/pages/wisdom/training-hub');
  108. await page.waitForLoadState('networkidle');
  109. // ========== When:开始训练 ==========
  110. const startBtn = page.locator('.start-btn, .start-training');
  111. if (await startBtn.isVisible()) {
  112. await startBtn.click();
  113. }
  114. // 等待训练开始
  115. await page.waitForSelector('.training-content, .quiz-area', { timeout: 5000 });
  116. // 完成一道题目
  117. const answerBtn = page.locator('.answer-btn, .option').first();
  118. if (await answerBtn.isVisible()) {
  119. await answerBtn.click();
  120. }
  121. // ========== Then:Milestone-2 - 训练记录生成 ========
  122. await page.waitForSelector('.training-complete, .result-saved', { timeout: 10000 });
  123. const completeTip = page.locator('.training-complete, .result-saved');
  124. expect(await completeTip.isVisible()).toBeTruthy();
  125. });
  126. });