From a551d0e0d8219bcb9a3e4e0bc5bde0b7adc90612 Mon Sep 17 00:00:00 2001 From: leiyun Date: Sun, 30 Aug 2026 11:09:53 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=AE=B0=E5=BF=86=E4=B8=8ELogo=E5=9B=9E=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/auth-login-contract.spec.ts | 72 +++++++++++++++++++++++++++++++ tests/system-config.spec.ts | 21 +++++++++ 2 files changed, 93 insertions(+) diff --git a/tests/auth-login-contract.spec.ts b/tests/auth-login-contract.spec.ts index 2e355bf..a3f6686 100644 --- a/tests/auth-login-contract.spec.ts +++ b/tests/auth-login-contract.spec.ts @@ -233,6 +233,78 @@ test.describe('登录上下文 UI 契约', () => { 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: '110', userId: '402', username: '', + password: 'Teacher-Remembered-1', remember: true, + }, + admin: { + departmentId: '', userId: '', username: 'admin.remembered', + password: 'Admin-Remembered-2', remember: true, + }, + }, + })) + }) + + await openLoginWithContext(page) + + await expect(identitySelect(page)).toContainText('杜晴') + await expect(passwordInput(page)).toHaveValue('Teacher-Remembered-1') + await expect(page.locator('input[name="rememberMe"]')).toBeChecked() + + await page.locator('[data-role-code="admin"]').click() + await expect(adminUsernameInput(page)).toHaveValue('admin.remembered') + await expect(passwordInput(page)).toHaveValue('Admin-Remembered-2') + await expect(page.locator('input[name="rememberMe"]')).toBeChecked() + + await page.locator('[data-role-code="teacher"]').click() + await expect(identitySelect(page)).toContainText('杜晴') + await expect(passwordInput(page)).toHaveValue('Teacher-Remembered-1') + }) + + test('成功登录后按勾选状态保存账号密码', async ({ page }) => { + await page.route('**/api/auth/v1/auth/login', (route) => route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + code: 200, + message: '成功', + data: { accessToken: 'remember-access-token', refreshToken: 'remember-refresh-token', expiresIn: 3600 }, + }), + })) + await page.route('**/api/auth/v1/auth/me', (route) => route.fulfill({ + status: 200, + contentType: 'application/json', + body: JSON.stringify({ + code: 200, + message: '成功', + data: { + user: { id: '1', username: 'admin.saved', displayName: '系统管理员', mustChangePassword: true }, + activeRoleId: '1', roles: [{ id: '1', code: 'admin', name: '管理员', enabled: true }], + permissions: [], authorizationMode: 'SINGLE_ACTIVE', + }, + }), + })) + await openLoginWithContext(page) + + await adminUsernameInput(page).fill('admin.saved') + await passwordInput(page).fill('Saved-Password-3') + await page.locator('input[name="rememberMe"]').check() + await submitButton(page).click() + + await expect.poll(() => page.evaluate(() => { + const raw = window.localStorage.getItem('unreal-tran:web:login-identity-preference:v1') || '{}' + return JSON.parse(raw).selections?.admin + })).toEqual({ + departmentId: '', userId: '', username: 'admin.saved', + password: 'Saved-Password-3', remember: true, + }) + }) + test('已删除的部门或账号不会被本地偏好错误回填', async ({ page }) => { await page.addInitScript(() => { window.localStorage.setItem('unreal-tran:web:login-identity-preference:v1', JSON.stringify({ diff --git a/tests/system-config.spec.ts b/tests/system-config.spec.ts index 3b6c6b6..8db9f35 100644 --- a/tests/system-config.spec.ts +++ b/tests/system-config.spec.ts @@ -223,6 +223,27 @@ test.describe('系统配置(状态化 Mock,不访问真实 API/数据库)' expect(mock.mutations).toEqual([]) }) + test('已配置的平台 LOGO 保持透明且不显示边框', async ({ page }) => { + const mock = new SystemConfigurationMock() + Object.assign(mock.state, { + logoConfigured: true, + logoUrl: '/api/auth/v1/system-config/assets/logo?v=1', + logoMediaType: 'image/png', + logoOriginalName: 'brand-logo.png', + logoSize: PNG_BYTES.length, + logoSha256: 'mock-logo-sha256', + logoDataVersion: 1, + }) + await mock.install(page) + + await page.goto('/system/config') + await expect(page.getByTestId('system-config-page')).toHaveAttribute('data-ready', 'true') + const configuredBrandMark = configuredBrandImage(page).locator('..') + await expect(configuredBrandMark).toHaveCSS('border-top-width', '0px') + await expect(configuredBrandMark).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)') + await expect(configuredBrandMark).toHaveCSS('box-shadow', 'none') + }) + test('管理员可从菜单进入并保存、清空名称以及上传、移除 PNG 品牌资源', async ({ page }, testInfo) => { const mock = new SystemConfigurationMock() await mock.install(page)