import { expect, test } from '@playwright/test' test.use({ serviceWorkers: 'block' }) test('saves contact changes with optional fields blank and preserves existing identity information', async ({ page }) => { const user = { id: 'student', userName: 'student', displayName: '测试学生', roles: ['Student'], permissions: [], effectiveDataScope: 'Self', } const profile = { studentNumber: '2026001', name: user.displayName, className: '测试班', status: 'Active', enrollmentYear: 2026, gender: 'Female', dateOfBirth: null, email: null, phone: null as string | null, nationality: '美国', ethnicity: '汉族', politicalStatus: '群众', nativePlace: '山东济南', } await page.addInitScript(savedUser => { localStorage.setItem('jiaowu_token', 'test-token') localStorage.setItem('jiaowu_user', JSON.stringify(savedUser)) localStorage.setItem('jiaowu_access_expires_at', '2099-01-01T00:00:00Z') localStorage.setItem('jiaowu_session_expires_at', '2099-01-01T00:00:00Z') }, user) await page.route(url => url.pathname.startsWith('/api/'), async route => { const path = new URL(route.request().url()).pathname if (path === '/api/auth/me') return route.fulfill({ json: user }) if (path === '/api/plugins/runtime' || path === '/api/student-identity-changes/mine') { return route.fulfill({ json: [] }) } if (path === '/api/student/profile') { if (route.request().method() === 'PUT') { profile.phone = route.request().postDataJSON().phone return route.fulfill({ json: { approvalSubmitted: false } }) } return route.fulfill({ json: profile }) } return route.fulfill({ json: {} }) }) await page.goto('/my-profile') await page.getByRole('button', { name: '修改信息' }).click() const phone = page.getByRole('textbox', { name: '联系电话', exact: true }) await phone.fill('13800000000') const saveRequest = page.waitForRequest(request => new URL(request.url()).pathname === '/api/student/profile' && request.method() === 'PUT', ) await page.getByRole('button', { name: '保存', exact: true }).click() expect((await saveRequest).postDataJSON()).toMatchObject({ phone: '13800000000', dateOfBirth: null, email: null, nationality: '美国', ethnicity: '汉族', politicalStatus: '群众', nativePlace: '山东济南', }) await expect(page.getByText('个人信息已保存。')).toBeVisible() await expect(phone).toHaveValue('13800000000') })