workbench.spec.ts 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { expect, test } from '@playwright/test'
  2. test('home, local previews and profile work without business API requests', async ({ page }) => {
  3. const failures: string[] = []
  4. const apiRequests: string[] = []
  5. page.on('pageerror', (error) => failures.push(error.message))
  6. page.on('request', (request) => {
  7. if (['fetch', 'xhr'].includes(request.resourceType()) && !request.url().includes('/@vite/')) apiRequests.push(request.url())
  8. })
  9. await page.goto('/')
  10. await expect(page.locator('.home-header').getByText('教师工作台', { exact: true })).toBeVisible()
  11. await expect(page.locator('.home-header').getByText(/开发环境|测试环境|正式环境/)).toHaveCount(0)
  12. await expect(page.locator('.notification-button .bell-icon')).toBeVisible()
  13. await expect(page.locator('.notification-button .notification-dot')).toBeVisible()
  14. await page.locator('.notification-button').click()
  15. await expect(page.getByText('视频讲解已生成').first()).toBeVisible()
  16. await page.locator('.taro_page').last().locator('.back-button').click()
  17. for (const title of ['上传错题', '上传试卷', '上传答题卡', '题目讲解']) {
  18. await expect(page.getByText(title, { exact: true })).toBeVisible()
  19. }
  20. const cards = await page.locator('.workbench-card').all()
  21. const firstCard = await cards[0].boundingBox()
  22. const secondCard = await cards[1].boundingBox()
  23. expect(firstCard).not.toBeNull()
  24. expect(secondCard).not.toBeNull()
  25. if (firstCard && secondCard) expect(secondCard.y - firstCard.y - firstCard.height).toBeLessThan(16)
  26. await page.locator('.workbench-card').filter({ hasText: '上传错题' }).click()
  27. await expect(page.getByText('识别前请选择学生,支持跨班级多选')).toBeVisible()
  28. await page.locator('.taro_page').last().locator('.back-button').click()
  29. await page.locator('.workbench-card').filter({ hasText: '题目讲解' }).click()
  30. await expect(page.locator('.taro_page').last().getByText('函数图像平移', { exact: true })).toBeVisible()
  31. await page.locator('.taro_page').last().locator('.back-button').click()
  32. await page.getByRole('link', { name: '我的', exact: true }).click()
  33. await expect(page.getByText('张老师', { exact: true })).toBeVisible()
  34. await expect(page.locator('.profile-header').getByText(/开发环境|测试环境|正式环境/)).toHaveCount(0)
  35. await page.locator('.settings-row').filter({ hasText: '账号信息' }).click()
  36. await expect(page.getByText('10000001', { exact: true })).toBeVisible()
  37. await page.locator('.sheet-close').click()
  38. await page.locator('.settings-row').filter({ hasText: '修改密码' }).click()
  39. await page.locator('input[placeholder="输入当前演示密码"]').fill('old-demo123')
  40. await page.locator('input[placeholder="输入至少 8 位演示密码"]').fill('demo12345')
  41. await page.locator('input[placeholder="再次输入演示密码"]').fill('demo12345')
  42. await page.getByText('演示确认', { exact: true }).click()
  43. await expect(page.getByText('校验通过,展示模式不会修改密码')).toBeHidden()
  44. await page.locator('.settings-row').filter({ hasText: '关于知了数学' }).click()
  45. await expect(page.getByText('版本 0.1.0')).toBeVisible()
  46. await page.locator('.sheet-close').click()
  47. await page.screenshot({ path: `test-results/profile-${test.info().project.name}.png`, fullPage: true, scale: 'css' })
  48. await page.getByText('退出登录', { exact: true }).click()
  49. await page.getByText('退出', { exact: true }).click()
  50. await expect(page.getByText('游客', { exact: true })).toBeVisible()
  51. await page.getByText('进入演示账号', { exact: true }).click()
  52. await expect(page.getByText('张老师', { exact: true })).toBeVisible()
  53. await page.getByRole('link', { name: '首页', exact: true }).click()
  54. await page.screenshot({ path: `test-results/home-${test.info().project.name}.png`, fullPage: true, scale: 'css' })
  55. expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBeTruthy()
  56. expect(failures).toEqual([])
  57. expect(apiRequests).toEqual([])
  58. })