| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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('有 3 条题目讲解待查看')).toBeVisible()
- await page.locator('.sheet-close').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.getByText('选择演示图片').click()
- await expect(page.getByText('演示图片已选择')).toBeVisible()
- await page.getByText('完成演示', { exact: true }).click()
- await page.locator('.workbench-card').filter({ hasText: '题目讲解' }).click()
- await expect(page.getByText('一元一次方程的解法')).toBeVisible()
- await page.locator('.sheet-close').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="输入至少 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([])
- })
|