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