fix: add CSRF token mocking to all form tests
This commit is contained in:
@@ -15,6 +15,10 @@ test.describe('表单验证测试', () => {
|
||||
test('联系表单 - 有效数据提交', async ({ page }) => {
|
||||
const contactPage = new ContactPage(page);
|
||||
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('csrf_token', 'test-csrf-token');
|
||||
});
|
||||
|
||||
await page.route('**/api/contact', async route => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
@@ -44,6 +48,10 @@ test.describe('表单验证测试', () => {
|
||||
test('联系表单 - 必填字段验证', async ({ page }) => {
|
||||
const contactPage = new ContactPage(page);
|
||||
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('csrf_token', 'test-csrf-token');
|
||||
});
|
||||
|
||||
await contactPage.navigate();
|
||||
await contactPage.fillContactForm({
|
||||
name: '',
|
||||
@@ -62,6 +70,10 @@ test.describe('表单验证测试', () => {
|
||||
test('联系表单 - 邮箱格式验证', async ({ page }) => {
|
||||
const contactPage = new ContactPage(page);
|
||||
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('csrf_token', 'test-csrf-token');
|
||||
});
|
||||
|
||||
await contactPage.navigate();
|
||||
await contactPage.fillContactForm({
|
||||
name: '测试用户',
|
||||
@@ -80,6 +92,10 @@ test.describe('表单验证测试', () => {
|
||||
test('联系表单 - API错误处理', async ({ page }) => {
|
||||
const contactPage = new ContactPage(page);
|
||||
|
||||
await page.addInitScript(() => {
|
||||
localStorage.setItem('csrf_token', 'test-csrf-token');
|
||||
});
|
||||
|
||||
await page.route('**/api/contact', async route => {
|
||||
await route.fulfill({
|
||||
status: 500,
|
||||
|
||||
Reference in New Issue
Block a user