diff --git a/tests/audit-logs.spec.ts b/tests/audit-logs.spec.ts index 51d9b37..7bcf1ee 100644 --- a/tests/audit-logs.spec.ts +++ b/tests/audit-logs.spec.ts @@ -254,4 +254,25 @@ test.describe('审计日志页面', () => { expect(auditRequests).toHaveLength(0) await captureScreenshot(page, testInfo, '03-audit-route-forbidden') }) + + test('当前筛选没有数据时提示不可导出且不请求导出接口', async ({ page }, testInfo) => { + const { auditRequests, exportRequests } = await mockPlatform(page, { + permissions: ['ai.overview.view', 'system.audit', 'system.audit.export'], + includeAuditMenu: true, + }) + let downloadCount = 0 + page.on('download', () => { downloadCount += 1 }) + + await page.goto('/settings/audit') + await page.getByTestId('audit-filter-keyword').fill('no-matching-audit-record') + await page.getByTestId('audit-search').click() + await expect.poll(() => auditRequests.at(-1)?.keyword).toBe('no-matching-audit-record') + await expect(page.getByText('暂无符合当前条件的审计日志', { exact: true })).toBeVisible() + + await page.getByTestId('audit-export').click() + await expect(page.getByText('暂无符合当前条件的审计日志,不可导出', { exact: true })).toBeVisible() + expect(exportRequests).toHaveLength(0) + expect(downloadCount).toBe(0) + await captureScreenshot(page, testInfo, '04-audit-empty-export-blocked') + }) }) diff --git a/tests/auth-navigation.spec.ts b/tests/auth-navigation.spec.ts index aca13a5..e90b550 100644 --- a/tests/auth-navigation.spec.ts +++ b/tests/auth-navigation.spec.ts @@ -18,7 +18,7 @@ test('登录页按行政、教员、学员、管理员展示真实身份控件', await expect(page.locator('.login-role-options > button')).toHaveCount(4) expect((await page.locator('.login-role-options > button').allTextContents()).map((item) => item.trim())) .toEqual(roleCases.map((item) => item.label)) - await expect(page.getByRole('button', { name: /登录系统/ })).toBeDisabled() + await expect(page.getByRole('button', { name: '登录', exact: true })).toBeDisabled() await expect(page.getByText('管理员输入账号登录,其他身份请选择对应账号后输入密码。')).toBeVisible() for (const role of roleCases) { @@ -47,14 +47,57 @@ test('登录页按行政、教员、学员、管理员展示真实身份控件', await expect(passwordToggle).toHaveCount(1) await expect(passwordToggle.locator('svg')).toHaveCount(1) await expect(password).toHaveAttribute('type', 'password') + await expect(page.getByTestId('password-hidden-icon')).toBeVisible() + await expect(page.getByTestId('password-visible-icon')).toHaveCount(0) await page.getByRole('button', { name: '显示密码' }).click() await expect(password).toHaveAttribute('type', 'text') + await expect(page.getByTestId('password-visible-icon')).toBeVisible() + await expect(page.getByTestId('password-hidden-icon')).toHaveCount(0) await page.getByRole('button', { name: '隐藏密码' }).click() await expect(password).toHaveAttribute('type', 'password') + await expect(page.getByTestId('password-hidden-icon')).toBeVisible() await captureScreenshot(page, testInfo, 'login-four-identities') }) +test('深色主题下浏览器自动填充保持深色输入样式', async ({ page }, testInfo) => { + await page.addInitScript(() => { + window.localStorage.setItem('digital-human-theme', 'dark') + }) + await page.goto('/login') + await expect(page.locator('.login-shell')).toHaveAttribute('data-theme', 'dark') + + const username = page.locator('input[name="username"]') + await username.fill('saved-admin-preview') + const client = await page.context().newCDPSession(page) + await client.send('DOM.enable') + await client.send('CSS.enable') + const documentNode = await client.send('DOM.getDocument') + const usernameNode = await client.send('DOM.querySelector', { + nodeId: documentNode.root.nodeId, + selector: 'input[name="username"]', + }) + await client.send('CSS.forcePseudoState', { + nodeId: usernameNode.nodeId, + forcedPseudoClasses: ['autofill'], + }) + + const autofillStyle = await username.evaluate((element) => { + const style = window.getComputedStyle(element) + return { + background: style.getPropertyValue('--login-autofill-background').trim(), + boxShadow: style.webkitBoxShadow, + textFill: style.webkitTextFillColor, + } + }) + expect(autofillStyle.background).toBe('rgb(9 42 34 / 96%)') + expect(autofillStyle.textFill).toBe('rgb(223, 244, 238)') + expect(autofillStyle.boxShadow).toContain('9, 42, 34') + + await username.fill('') + await captureScreenshot(page, testInfo, 'login-dark-autofill-theme') +}) + test('错误密码被拒绝且不会建立登录会话', async ({ page }, testInfo) => { const credentials = readAdminCredentials() await page.goto('/login')