- Raise use-swipe-gesture mutation score to 66.13% (target 65%+) - Maintain use-reduced-motion mutation score at 76.32% (target 50%+) - Fix use-reduced-motion.ts ESLint set-state-in-effect warning - Add UJ-10 deep searcher journey (category browse → article read → content discovery) - Add 40 new test files (analytics, detail, sections, ui, lib components) - Update test-strategy-plan.md to v2.0 (sync test count to 1591) - Sync README.md with final release metrics Quality gates: TS 0 errors, ESLint 0 errors, 121 suites / 1591 tests passed
122 lines
3.5 KiB
TypeScript
122 lines
3.5 KiB
TypeScript
// @ts-nocheck
|
|
import { test, expect } from '@playwright/test';
|
|
import { ContactPage } from '../../shared/pages';
|
|
import { formData } from '../../shared/config/test-data';
|
|
import { TestDataFactory } from '../../shared/utils/testing/TestDataFactory';
|
|
import { TestDataCleaner } from '../../shared/utils/testing/TestDataCleaner';
|
|
|
|
test.describe('表单验证测试', () => {
|
|
test.beforeAll(async () => {
|
|
TestDataFactory.createContactForm();
|
|
});
|
|
|
|
test.afterAll(async () => {
|
|
await TestDataCleaner.cleanupAll();
|
|
});
|
|
test('联系表单 - 有效数据提交', async ({ page }) => {
|
|
const contactPage = new ContactPage(page);
|
|
|
|
await page.route('**/api/contact', async route => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: true, message: '消息已发送' })
|
|
});
|
|
});
|
|
|
|
await page.addInitScript(() => {
|
|
sessionStorage.setItem('csrf_token', 'test-csrf-token');
|
|
});
|
|
|
|
await contactPage.navigate();
|
|
await contactPage.fillContactForm({
|
|
name: formData.valid.name,
|
|
email: formData.valid.email,
|
|
phone: formData.valid.phone,
|
|
message: formData.valid.message,
|
|
subject: '测试主题'
|
|
});
|
|
|
|
await contactPage.submitForm();
|
|
await page.waitForTimeout(3000);
|
|
|
|
const bodyContent = await page.content();
|
|
expect(bodyContent).toBeTruthy();
|
|
expect(bodyContent.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('联系表单 - 必填字段验证', async ({ page }) => {
|
|
const contactPage = new ContactPage(page);
|
|
|
|
await page.addInitScript(() => {
|
|
sessionStorage.setItem('csrf_token', 'test-csrf-token');
|
|
});
|
|
|
|
await contactPage.navigate();
|
|
await contactPage.fillContactForm({
|
|
name: '',
|
|
email: '',
|
|
phone: '',
|
|
message: '',
|
|
subject: ''
|
|
});
|
|
await contactPage.submitForm();
|
|
|
|
await page.waitForTimeout(1000);
|
|
const formStillExists = await page.locator('form').count();
|
|
expect(formStillExists).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('联系表单 - 邮箱格式验证', async ({ page }) => {
|
|
const contactPage = new ContactPage(page);
|
|
|
|
await page.addInitScript(() => {
|
|
sessionStorage.setItem('csrf_token', 'test-csrf-token');
|
|
});
|
|
|
|
await contactPage.navigate();
|
|
await contactPage.fillContactForm({
|
|
name: '测试用户',
|
|
email: formData.invalid.email,
|
|
phone: '13800138000',
|
|
message: '测试消息',
|
|
subject: '测试主题'
|
|
});
|
|
await contactPage.submitForm();
|
|
|
|
await page.waitForTimeout(1000);
|
|
const formStillExists = await page.locator('form').count();
|
|
expect(formStillExists).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('联系表单 - API错误处理', async ({ page }) => {
|
|
const contactPage = new ContactPage(page);
|
|
|
|
await page.route('**/api/contact', async route => {
|
|
await route.fulfill({
|
|
status: 500,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ success: false, message: '服务器错误' })
|
|
});
|
|
});
|
|
|
|
await page.addInitScript(() => {
|
|
sessionStorage.setItem('csrf_token', 'test-csrf-token');
|
|
});
|
|
|
|
await contactPage.navigate();
|
|
await contactPage.fillContactForm({
|
|
name: formData.valid.name,
|
|
email: formData.valid.email,
|
|
phone: formData.valid.phone,
|
|
message: formData.valid.message,
|
|
subject: '测试主题'
|
|
});
|
|
await contactPage.submitForm();
|
|
|
|
await page.waitForTimeout(3000);
|
|
const formStillExists = await page.locator('form').count();
|
|
expect(formStillExists).toBeGreaterThan(0);
|
|
});
|
|
});
|