优化前端按钮对比度与响应式布局
This commit is contained in:
1 parent
a2fd08fe7e
commit
e14939edb9
21 files changed
+278
-50
No files matched your search
@@ -9,7 +9,7 @@ const cases: { type: string; stage: string | null; secondaryId?: string; endpoin
|
||||
{ type: 'DormitoryApplication', stage: 'counselor', endpoint: '/api/dormitory-services/applications/item-1/counselor-review', body: { approved: true, comment: null }, progress: true },
|
||||
{ type: 'AttendanceAppeal', stage: null, secondaryId: 'sheet-1', endpoint: '/api/attendance/appeals/sheet-1/item-1/review', body: { approve: false, comment: '理由不充分' }, reject: true },
|
||||
{ type: 'TeacherCourseApplication', stage: null, endpoint: '/api/teacher-course-applications/item-1/review', body: { status: 'Rejected', reviewComment: '理由不充分' }, reject: true },
|
||||
{ type: 'CourseExemption', stage: null, endpoint: '/api/approvals/exemptions/item-1/approve', body: null, progress: true },
|
||||
{ type: 'CourseExemption', stage: null, endpoint: '/api/approvals/exemptions/item-1/approve', body: { comment: '' }, progress: true },
|
||||
{ type: 'CourseAdjustment', stage: null, endpoint: '/api/course-adjustments/item-1/approve', body: null, progress: true },
|
||||
]
|
||||
|
||||
@@ -28,6 +28,8 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
|
||||
let overdueRequested = false
|
||||
await page.route(url => url.pathname.startsWith('/api/'), async route => {
|
||||
const url = new URL(route.request().url())
|
||||
if (url.pathname === '/api/approvals/reviewed') return route.fulfill({ json: { items: [], total: 0 } })
|
||||
if (url.pathname === '/api/student-leaves/pending') return route.fulfill({ json: [] })
|
||||
if (url.pathname === '/api/approvals/pending') {
|
||||
if (url.searchParams.has('overdueHours')) {
|
||||
expect(url.searchParams.get('overdueHours')).toBe('72')
|
||||
@@ -77,7 +79,10 @@ for (const scenario of cases) test(`${scenario.type} can be ${scenario.reject ?
|
||||
const dialog = page.getByRole('dialog')
|
||||
await dialog.locator('textarea').fill('理由不充分')
|
||||
await dialog.getByRole('button', { name: '确认驳回' }).click()
|
||||
} else await card.getByRole('button', { name: '通过' }).click()
|
||||
} else {
|
||||
await card.getByRole('button', { name: '通过' }).click()
|
||||
if (scenario.type === 'CourseExemption') await page.getByRole('dialog').getByRole('button', { name: '通过', exact: true }).click()
|
||||
}
|
||||
await expect(card).toHaveCount(0)
|
||||
expect(reviewed).toBe(true)
|
||||
expect(pageErrors).toEqual([])
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { test, expect } from '@playwright/test'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
// Exercise the real Element Plus selectors in either stylesheet order: Vite may
|
||||
// load a component's on-demand CSS after the application's global stylesheet.
|
||||
for (const componentCssLast of [false, true]) {
|
||||
test(`button variants stay legible (component CSS ${componentCssLast ? 'last' : 'first'})`, async ({ page }) => {
|
||||
const elementCss = readFileSync(resolve('node_modules/element-plus/theme-chalk/el-button.css'), 'utf8')
|
||||
const appCss = readFileSync(resolve('src/style.css'), 'utf8')
|
||||
await page.setContent('<main style="background: white"></main>')
|
||||
for (const content of componentCssLast ? [appCss, elementCss] : [elementCss, appCss]) {
|
||||
await page.addStyleTag({ content })
|
||||
}
|
||||
const results = await page.evaluate(() => {
|
||||
const main = document.querySelector('main')!
|
||||
const luminance = (color: string) => {
|
||||
const channels = color.match(/[\d.]+/g)!.slice(0, 3).map(Number).map(value => {
|
||||
const channel = value / 255
|
||||
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4
|
||||
})
|
||||
return 0.2126 * channels[0]! + 0.7152 * channels[1]! + 0.0722 * channels[2]!
|
||||
}
|
||||
const failures: string[] = []
|
||||
for (const type of ['', 'primary', 'success', 'info', 'warning', 'danger']) {
|
||||
for (const variant of ['', 'is-plain', 'is-text', 'is-link', 'is-dashed']) {
|
||||
for (const disabled of [false, true]) {
|
||||
const button = document.createElement('button')
|
||||
button.className = ['el-button', type && `el-button--${type}`, variant, disabled && 'is-disabled'].filter(Boolean).join(' ')
|
||||
button.textContent = '操作 Action'
|
||||
main.appendChild(button)
|
||||
const style = getComputedStyle(button)
|
||||
const background = style.backgroundColor === 'rgba(0, 0, 0, 0)' ? 'rgb(255, 255, 255)' : style.backgroundColor
|
||||
const values = [luminance(style.color), luminance(background)].sort((a, b) => b - a)
|
||||
const ratio = (values[0]! + 0.05) / (values[1]! + 0.05)
|
||||
if (ratio < 4.5) failures.push(`${button.className}: ${style.color} on ${background} = ${ratio.toFixed(2)}`)
|
||||
button.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
return failures
|
||||
})
|
||||
expect(results).toEqual([])
|
||||
})
|
||||
}
|
||||
|
||||
test('selection cards retain readable secondary labels and statuses', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<div class="registry-switch"><button><span>类别</span></button></div>
|
||||
<div class="plan-list"><button><small>说明</small><i>草稿</i><i class="published">已发布</i><i class="archived">已归档</i></button></div>
|
||||
<div class="schedule-version-strip"><button><small>版本说明</small></button></div>
|
||||
<div class="selection-round-strip"><button><span>轮次说明</span><i>待开始</i><i class="open">开放中</i></button></div>
|
||||
<div class="grade-sheet-list"><button><i>草稿</i><i class="submitted">已提交</i><i class="published">已发布</i><i class="returned">已退回</i></button></div>
|
||||
`)
|
||||
await page.addStyleTag({ content: readFileSync(resolve('src/style.css'), 'utf8') })
|
||||
const failures = await page.evaluate(() => {
|
||||
const lightness = (color: string) => {
|
||||
const rgb = color.match(/[\d.]+/g)!.slice(0, 3).map(Number).map(x => {
|
||||
const value = x / 255
|
||||
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4
|
||||
})
|
||||
return 0.2126 * rgb[0]! + 0.7152 * rgb[1]! + 0.0722 * rgb[2]!
|
||||
}
|
||||
return [...document.querySelectorAll('button span, button small, button i')].flatMap(element => {
|
||||
const color = getComputedStyle(element).color
|
||||
let background = 'rgb(255, 255, 255)'
|
||||
for (let current: Element | null = element; current; current = current.parentElement) {
|
||||
const candidate = getComputedStyle(current).backgroundColor
|
||||
if (candidate !== 'rgba(0, 0, 0, 0)') { background = candidate; break }
|
||||
}
|
||||
const values = [lightness(color), lightness(background)].sort((a, b) => b - a)
|
||||
const contrast = (values[0]! + 0.05) / (values[1]! + 0.05)
|
||||
return contrast < 4.5 ? [`${element.parentElement?.parentElement?.className} ${element.className}: ${contrast.toFixed(2)}`] : []
|
||||
})
|
||||
})
|
||||
expect(failures).toEqual([])
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
const routes: Record<string, string[]> = {
|
||||
SuperAdmin: ['/teaching-monitoring', '/campus-registrations', '/plugins', '/official-documents'],
|
||||
Teacher: ['/dashboard', '/account', '/teaching-preferences', '/my-timetable', '/teacher-roster', '/teacher-attendance', '/classroom-reservations', '/experiments', '/experiment-grades', '/grades', '/grade-analytics', '/exams', '/makeup-exams', '/course-adjustments', '/notifications', '/academic-calendar', '/approvals', '/evaluations'],
|
||||
Student: ['/dashboard', '/account', '/my-profile', '/my-curriculum', '/academic-planning', '/my-timetable', '/my-attendance', '/free-classrooms', '/classroom-reservations', '/campus-registrations', '/tuition', '/dormitory-services', '/dormitory-hygiene', '/experiments', '/experiment-grades', '/course-selections', '/grades', '/academic-overview', '/other-exams', '/physical-fitness', '/comprehensive-assessments', '/exams', '/makeup-exams', '/notifications', '/academic-calendar', '/approvals', '/warnings', '/student-status-changes', '/official-documents', '/graduation-audits', '/degree-awards', '/graduation-clearance', '/evaluations'],
|
||||
}
|
||||
const plugins = ['statistics', 'experiments', 'campus-services', 'evaluations', 'examinations', 'physical-fitness', 'comprehensive-assessment', 'student-services', 'graduation']
|
||||
|
||||
for (const [role, paths] of Object.entries(routes)) {
|
||||
test(`${role} routes fit mobile and desktop with unavailable business data`, async ({ page }) => {
|
||||
test.setTimeout(240_000)
|
||||
const user = { id: 'layout-user', userName: 'layout-user', displayName: '测试用户', roles: [role], permissions: role === 'SuperAdmin' ? ['system.plugins.manage'] : [], effectiveDataScope: role === 'SuperAdmin' ? 'All' : 'Self' }
|
||||
await page.addInitScript(savedUser => {
|
||||
localStorage.setItem('jiaowu_token', 'layout-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/'), route => {
|
||||
const path = new URL(route.request().url()).pathname
|
||||
if (path === '/api/auth/me') return route.fulfill({ json: user })
|
||||
if (path === '/api/plugins/runtime') return route.fulfill({ json: plugins.map(id => ({ id: `mingxu.${id}`, isEnabled: true, navigationPaths: [], capabilities: [] })) })
|
||||
if (path === '/api/licenses/status') return route.fulfill({ json: { isLicensed: true } })
|
||||
if (path === '/api/dashboard') return route.fulfill({ json: { greeting: { title: '测试教师', subtitle: '测试学期', narrative: '页面布局检查', label: '概览', insights: [] } } })
|
||||
if (path === '/api/grades/sheets') return route.fulfill({ json: { items: [], total: 0 } })
|
||||
return route.fulfill({ status: 503, json: { message: 'Test data unavailable' } })
|
||||
})
|
||||
const failures: string[] = []
|
||||
for (const width of [390, 1024]) {
|
||||
await page.setViewportSize({ width, height: 844 })
|
||||
for (const path of paths) {
|
||||
await page.goto(path, { waitUntil: 'domcontentloaded' })
|
||||
try {
|
||||
await expect(page.locator('h1, h2').first()).toBeVisible({ timeout: 8000 })
|
||||
if (new URL(page.url()).pathname !== path) failures.push(`${width} ${path}: redirected to ${page.url()}`)
|
||||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth)
|
||||
if (overflow > 1) failures.push(`${width} ${path}: horizontal overflow ${overflow}px`)
|
||||
} catch {
|
||||
failures.push(`${width} ${path}: heading did not render (${page.url()})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(failures).toEqual([])
|
||||
})
|
||||
}
|
||||
Loaded 3 of 21 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user