|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +test.describe('form组件xdesign规范', () => { |
| 4 | + test('默认--UI截图', async ({ page }) => { |
| 5 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 6 | + await page.goto('form#basic-usage') |
| 7 | + const demo = page.locator('#basic-usage .pc-demo') |
| 8 | + await expect(demo).toBeInViewport() |
| 9 | + await expect(demo).toHaveScreenshot('basic-usage.png') |
| 10 | + }) |
| 11 | + |
| 12 | + test('行内表单--UI截图', async ({ page }) => { |
| 13 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 14 | + await page.goto('form#form-in-row') |
| 15 | + const demo = page.locator('#form-in-row .pc-demo') |
| 16 | + await expect(demo).toBeInViewport() |
| 17 | + await expect(demo).toHaveScreenshot('inline.png') |
| 18 | + }) |
| 19 | + |
| 20 | + test('标签位置--UI截图', async ({ page }) => { |
| 21 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 22 | + await page.goto('form#label-position') |
| 23 | + const demo = page.locator('#label-position .pc-demo') |
| 24 | + const form = demo.locator('form') |
| 25 | + const btn = demo.locator('button').filter({ hasText: 'top' }) |
| 26 | + await btn.click() |
| 27 | + await expect(form).toBeInViewport() |
| 28 | + await expect(form).toHaveScreenshot('top.png') |
| 29 | + }) |
| 30 | + |
| 31 | + test('校验--UI截图', async ({ page }) => { |
| 32 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 33 | + await page.goto('form#form-validation') |
| 34 | + const demo = page.locator('#form-validation .pc-demo') |
| 35 | + const btn = demo.locator('button').filter({ hasText: '提交' }) |
| 36 | + await btn.click() |
| 37 | + await expect(demo).toBeInViewport() |
| 38 | + await page.locator('button').filter({ hasText: '确定' }).nth(1).click() |
| 39 | + await expect(demo).toHaveScreenshot('tip-validate.png') |
| 40 | + }) |
| 41 | + |
| 42 | + test('text校验--UI截图', async ({ page }) => { |
| 43 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 44 | + await page.goto('form#validate-type') |
| 45 | + const demo = page.locator('#validate-type .pc-demo') |
| 46 | + const form = demo.locator('form') |
| 47 | + await expect(form).toBeInViewport() |
| 48 | + await expect(form).toHaveScreenshot('text-validate.png') |
| 49 | + }) |
| 50 | + |
| 51 | + test('尺寸--UI截图', async ({ page }) => { |
| 52 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 53 | + await page.goto('form#size') |
| 54 | + const demo = page.locator('#size .pc-demo') |
| 55 | + const form = demo.locator('form') |
| 56 | + await expect(form).toBeInViewport() |
| 57 | + await demo.locator('button').filter({ hasText: 'medium' }).click() |
| 58 | + await expect(form).toHaveScreenshot('medium.png') |
| 59 | + await demo.locator('button').filter({ hasText: 'small' }).click() |
| 60 | + await expect(form).toHaveScreenshot('small.png') |
| 61 | + await demo.locator('button').filter({ hasText: 'mini' }).click() |
| 62 | + await expect(form).toHaveScreenshot('mini.png') |
| 63 | + }) |
| 64 | + |
| 65 | + test('禁用--UI截图', async ({ page }) => { |
| 66 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 67 | + await page.goto('form#form-disabled') |
| 68 | + await page.setViewportSize({ |
| 69 | + width: 1400, |
| 70 | + height: 1500 |
| 71 | + }) |
| 72 | + const demo = page.locator('#form-disabled .pc-demo') |
| 73 | + const form = demo.locator('form') |
| 74 | + await demo.locator('.tiny-switch').first().click() |
| 75 | + await expect(form).toBeInViewport() |
| 76 | + await expect(form).toHaveScreenshot('disabled.png') |
| 77 | + }) |
| 78 | + |
| 79 | + test('仅展示--UI截图', async ({ page }) => { |
| 80 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 81 | + await page.goto('form#display-only') |
| 82 | + page.setViewportSize({ |
| 83 | + width: 1400, |
| 84 | + height: 1500 |
| 85 | + }) |
| 86 | + const demo = page.locator('#display-only .pc-demo') |
| 87 | + const form = demo.locator('form') |
| 88 | + await expect(form).toBeInViewport() |
| 89 | + await expect(form).toHaveScreenshot('display-only.png') |
| 90 | + }) |
| 91 | + |
| 92 | + |
| 93 | + test('额外提示--UI截图', async ({ page }) => { |
| 94 | + page.on('pageerror', (exception) => expect(exception).toBeNull()) |
| 95 | + await page.goto('form#extra-tip') |
| 96 | + const demo = page.locator('#extra-tip .pc-demo') |
| 97 | + await expect(demo).toBeInViewport() |
| 98 | + await expect(demo).toHaveScreenshot('extra-tip.png') |
| 99 | + }) |
| 100 | + |
| 101 | +}) |
0 commit comments