From 0fa0b91929a81875d77b066f4811c885b5f6bebf Mon Sep 17 00:00:00 2001 From: leiyun Date: Sat, 29 Aug 2026 01:09:31 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A6=86=E7=9B=96=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=BA=AB=E4=BB=BD=E8=AE=B0=E5=BF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/auth-login-contract.spec.ts | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/auth-login-contract.spec.ts b/tests/auth-login-contract.spec.ts index 1572af2..2e355bf 100644 --- a/tests/auth-login-contract.spec.ts +++ b/tests/auth-login-contract.spec.ts @@ -212,6 +212,46 @@ const expectElementSelectPlaceholder = async (select: Locator, placeholder: stri } 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) => { await openLoginWithContext(page)