|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +test.beforeEach(async ({ context }) => { |
| 4 | + await context.route(/^https:\/\//, (route) => |
| 5 | + route.fulfill({ status: 204, contentType: 'text/plain', body: '' }) |
| 6 | + ); |
| 7 | +}); |
| 8 | + |
| 9 | +test('QR generator exposes labelled controls and a semantic generate button', async ({ page }) => { |
| 10 | + await page.setViewportSize({ width: 390, height: 844 }); |
| 11 | + await page.goto('/tools/generator/qrcode-generator.html'); |
| 12 | + |
| 13 | + const textInput = page.getByLabel('文本或 URL', { exact: true }); |
| 14 | + await expect(textInput).toBeVisible(); |
| 15 | + await expect(textInput).toHaveAttribute('name', 'qr-text'); |
| 16 | + await expect(textInput).toHaveAttribute('autocomplete', 'off'); |
| 17 | + await expect(textInput).toHaveAttribute('placeholder', '输入要编码的文本或 URL…'); |
| 18 | + |
| 19 | + const sizeInput = page.getByLabel('二维码大小 (px)', { exact: true }); |
| 20 | + await expect(sizeInput).toHaveValue('256'); |
| 21 | + await expect(sizeInput).toHaveAttribute('name', 'qr-size'); |
| 22 | + await expect(sizeInput).toHaveAttribute('autocomplete', 'off'); |
| 23 | + await expect(sizeInput).toHaveAttribute('placeholder', '例如 256'); |
| 24 | + |
| 25 | + const foregroundColor = page.getByLabel('前景色', { exact: true }); |
| 26 | + await expect(foregroundColor).toHaveValue('#000000'); |
| 27 | + await expect(foregroundColor).toHaveAttribute('name', 'foreground-color'); |
| 28 | + await expect(foregroundColor).toHaveAttribute('autocomplete', 'off'); |
| 29 | + |
| 30 | + const backgroundColor = page.getByLabel('背景色', { exact: true }); |
| 31 | + await expect(backgroundColor).toHaveValue('#ffffff'); |
| 32 | + await expect(backgroundColor).toHaveAttribute('name', 'background-color'); |
| 33 | + await expect(backgroundColor).toHaveAttribute('autocomplete', 'off'); |
| 34 | + |
| 35 | + const generateButton = page.getByRole('button', { name: '生成二维码', exact: true }); |
| 36 | + await expect(generateButton).toBeVisible(); |
| 37 | + await expect(generateButton).toHaveAttribute('type', 'button'); |
| 38 | +}); |
0 commit comments