| @@ -212,6 +212,46 @@ const expectElementSelectPlaceholder = async (select: Locator, placeholder: stri | |||||
| } | } | ||||
| test.describe('登录上下文 UI 契约', () => { | test.describe('登录上下文 UI 契约', () => { | ||||
| test('恢复上次成功登录的部门和账号但不保存密码', async ({ page }, testInfo) => { | |||||
| await page.addInitScript(() => { | |||||
| window.localStorage.setItem('unreal-tran:web:login-identity-preference:v1', JSON.stringify({ | |||||
| lastRoleCode: 'teacher', | |||||
| selections: { | |||||
| teacher: { departmentId: '110', userId: '402', username: '' }, | |||||
| }, | |||||
| })) | |||||
| }) | |||||
| await openLoginWithContext(page) | |||||
| await expect(page.locator('[data-role-code="teacher"]')).toHaveAttribute('aria-pressed', 'true') | |||||
| await expect(page.getByTestId('login-organization')).toContainText('工程装备系') | |||||
| await expect(page.getByTestId('login-department')).toContainText('维修教研室') | |||||
| await expect(identitySelect(page)).toContainText('杜晴') | |||||
| await expect(passwordInput(page)).toHaveValue('') | |||||
| await expect(submitButton(page)).toBeDisabled() | |||||
| await captureScreenshot(page, testInfo, 'restored-login-identity-without-password') | |||||
| }) | |||||
| test('已删除的部门或账号不会被本地偏好错误回填', async ({ page }) => { | |||||
| await page.addInitScript(() => { | |||||
| window.localStorage.setItem('unreal-tran:web:login-identity-preference:v1', JSON.stringify({ | |||||
| lastRoleCode: 'teacher', | |||||
| selections: { | |||||
| teacher: { departmentId: '999', userId: '999', username: '' }, | |||||
| }, | |||||
| })) | |||||
| }) | |||||
| await openLoginWithContext(page) | |||||
| await expect(page.locator('[data-role-code="teacher"]')).toHaveAttribute('aria-pressed', 'true') | |||||
| await expectElementSelectPlaceholder(page.getByTestId('login-organization'), '请选择教学系') | |||||
| await expect(page.getByTestId('login-department')).toBeDisabled() | |||||
| await expect(identitySelect(page)).toBeDisabled() | |||||
| await expect(passwordInput(page)).toHaveValue('') | |||||
| }) | |||||
| test('默认管理员且四个身份展示各自约定字段', async ({ page }, testInfo) => { | test('默认管理员且四个身份展示各自约定字段', async ({ page }, testInfo) => { | ||||
| await openLoginWithContext(page) | await openLoginWithContext(page) | ||||