fix(admin): 统一后台筛选控件高度与对齐

This commit is contained in:
2026-11-20 14:19:06 +08:00
parent 51c41b238a
commit 5bdc125b18
12 changed files with 274 additions and 28 deletions
@@ -0,0 +1,58 @@
import { expect, test } from '@playwright/test'
const brandPath = '/admin-vue/asin-center/invalid'
test('品牌数据库:单行筛选控件等高、底边对齐,窄屏可以换行', async ({ page }) => {
await page.goto(brandPath)
const filters = page.locator('.invalid-filter-row')
await expect(filters.getByRole('button', { name: '查询' })).toBeVisible()
const controls = [
filters.getByPlaceholder('输入 ASIN'),
filters.getByPlaceholder('输入品牌'),
filters.locator('.el-select__wrapper'),
filters.getByRole('button', { name: '查询' }),
]
const boxes = await Promise.all(controls.map((control) => control.evaluate((el) => {
const { height, bottom } = el.getBoundingClientRect()
return { height, bottom }
})))
expect(boxes.map((box) => box.height)).toEqual([34, 34, 34, 34])
expect(Math.max(...boxes.map((box) => box.bottom)) - Math.min(...boxes.map((box) => box.bottom))).toBeLessThan(1)
const batchDelete = page.getByRole('button', { name: '批量删除(0)' })
await expect(batchDelete).toBeDisabled()
const batchBox = await batchDelete.boundingBox()
const tableBox = await page.locator('.invalid-asin-table-scroll').boundingBox()
expect(batchBox?.height).toBe(34)
expect(tableBox!.y - batchBox!.y - batchBox!.height).toBeGreaterThanOrEqual(8)
await page.setViewportSize({ width: 680, height: 900 })
await expect.poll(async () => filters.evaluate((row) => {
const first = row.firstElementChild!.getBoundingClientRect()
const last = row.lastElementChild!.getBoundingClientRect()
return last.top >= first.bottom && last.right <= row.getBoundingClientRect().right + 1
})).toBe(true)
})
test('品牌数据库:键盘搜索分组、查询和新增仍可用', async ({ page }) => {
await page.goto(brandPath)
const filters = page.locator('.invalid-filter-row')
await filters.getByPlaceholder('输入品牌').press('Tab')
const group = filters.getByRole('combobox')
await expect(group).toBeFocused()
await group.fill('测试')
await expect(page.getByRole('option', { name: '测试分组' })).toBeVisible()
await expect(page.getByRole('option', { name: '其他分组' })).not.toBeVisible()
await page.getByRole('option', { name: '测试分组' }).click()
await filters.getByPlaceholder('输入 ASIN').fill('B0INVALID1')
const queried = page.waitForRequest((req) => new URL(req.url()).pathname === '/api/admin/invalid-asin-data' && req.url().includes('group_id=1'))
await filters.getByRole('button', { name: '查询' }).click()
const params = new URL((await queried).url()).searchParams
expect(params.get('data_value')).toBe('B0INVALID1')
expect(params.get('page')).toBe('1')
await page.getByRole('button', { name: '新增', exact: true }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByRole('button', { name: '保存' })).toBeVisible()
await dialog.getByRole('button', { name: '取消' }).click()
await expect(dialog).not.toBeVisible()
})
@@ -0,0 +1,159 @@
import { expect, test, type Locator } from '@playwright/test'
// 独立的可见菜单清单;不从运行时路由反推夹具,以免漏注册时测试仍然全绿。
const shared = [
['admin_users', '用户管理', 'account/users', '.form-row'],
['admin_columns', '菜单管理', 'account/menus', '.form-row'],
['admin_group_manage', '数据权限分组', 'account/groups', '.form-row'],
['admin_companies', '公司管理', 'account/companies', '.form-row'],
] as const
const amazon = [
...shared,
['admin_user_secrets', '密钥管理', 'account/user-secrets', '.form-row'],
['admin_user_secret_usage', '密钥用量统计', 'account/user-secret-usage', '.form-row'],
['admin_shop_data_duplicate_check', '店铺撞款监控', 'shop-center/duplicate-check', '.filter-row'],
['admin_brand_gating', '品牌Gating库', 'shop-center/brand-gating', '.g-filters'],
['admin_keyword_usage', '关键词使用记录', 'shop-center/keyword-usage', '.kw-filters'],
['admin_shop_keys', '店铺密钥管理', 'shop-center/keys', '.form-row'],
['admin_shop_manage', '店铺管理', 'shop-center/shops', '.form-row'],
['admin_history', '生成记录', 'records/history', '.form-row'],
['admin_version', '软件版本管理', 'records/software-version', '.admin-header-controls'],
['admin_tutorial', '教程管理', 'records/tutorial', '.admin-header-controls'],
['admin_workbench_client_package', '数富AI工作台客户端包管理', 'records/workbench-client-package', '.admin-header-controls'],
['admin_device_logs', '日志管理', 'records/device-logs', '.form-row'],
['admin_task_center', '客户端任务管理', 'task-center/board', '.form-row'],
['digital_human_version', '数字人版本管理', 'records/digital-human-version', '.admin-header-controls'],
['admin_image_video_tasks', '视频任务记录', 'records/image-video-tasks', '.form-row'],
['admin_shop_data_crawl_tasks', '店铺数据记录', 'shop-center/data-tasks', '.form-row'],
['admin_dedupe_total_data', '数据去重总数据', 'asin-center/registry', '.dedupe-filter-row'],
['admin_invalid_asin_data', '品牌数据库', 'asin-center/invalid', '.form-row'],
['admin_query_asin', '查询ASIN', 'asin-center/query', '.form-row'],
['admin_product_categories', '商品类目', 'asin-center/categories', '.admin-header-controls'],
['admin_skip_price_asin', '最低价ASIN', 'asin-center/skip-price', '.form-row'],
['admin_appearance_patent_clean_items', '外观专利数据库', 'patent-center/clean-items', '.clean-filter-row'],
] as const
const jdDatabase = ['admin_jd_database', '京东数据库', 'jd-center/database', '.jd-filter-row'] as const
const jd = [...shared, jdDatabase]
const allMenus = [...amazon, jdDatabase].map(([key, name, path]) => ({ key, name, route: `/${path}` }))
const emptyPage = { items: [], total: 0 }
const fixtures: Record<string, unknown> = {
'/api/admin/appearance-patent-clean-items': emptyPage,
'/api/admin/brand-gating': emptyPage,
'/api/admin/brand-gating/stats': { total: 0 },
'/api/admin/companies': { items: [{ id: 1, name: '测试公司' }], total: 1 },
'/api/admin/device-logs/files': emptyPage,
'/api/admin/history': emptyPage,
'/api/admin/image-video-tasks': emptyPage,
'/api/admin/jd-product-groups': { items: [{ id: 1, name: '测试分类' }] },
'/api/admin/jd-product-groups/scope': {
platformSuperAdmin: true, defaultGroupId: 1,
groups: [{ id: 1, name: '测试分组', label: '测试分组', editable: true }, { id: 2, name: '其他分组', label: '其他分组', editable: true }],
},
'/api/admin/jd-products': emptyPage,
'/api/admin/jd-products/categories': [],
'/api/admin/keyword-usage': emptyPage,
'/api/admin/keyword-usage/deletes': emptyPage,
'/api/admin/keyword-usage/overview': {},
'/api/admin/shop-data-crawl-tasks': emptyPage,
'/api/admin/shop-keys': emptyPage,
'/api/admin/shop-manages': emptyPage,
'/api/admin/shop-manages/groups': [{ id: 1, group_name: '测试分组' }],
'/api/admin/task-center/overview': { runningTasks: 0, todayFinishedTasks: 0, stuckTasks: 0 },
'/api/admin/task-center/shop-options': { items: ['测试店铺'] },
'/api/admin/task-center/tasks': emptyPage,
'/api/admin/task-center/variant-tasks': emptyPage,
'/api/admin/user-secret-usage': emptyPage,
'/api/admin/versions': emptyPage,
'/api/admin/workbench-client/packages': emptyPage,
'/api/digital-human/versions': emptyPage,
}
// 这些接口在 mock-admin-server 里已经有专门的响应,不吃通用兜底。
const serverFixtures = new Set([
'/api/admin/current-user', '/api/admin/notifications/summary', '/api/admin/users',
'/api/admin/permission-menus', '/api/admin/user-secrets', '/api/admin/user-secrets/balances',
'/api/admin/shop-data-crawl/duplicate-check-console', '/api/admin/shop-data-crawl/duplicate-check-ledger',
'/api/admin/tutorials', '/api/admin/invalid-asin-data', '/api/admin/invalid-asin-data/groups',
'/api/admin/dedupe-total-data', '/api/admin/query-asins', '/api/admin/product-categories/children',
'/api/admin/skip-price-asins',
])
async function controlDeviations(row: Locator) {
await expect(row).toBeVisible()
return row.evaluate((el) => {
const selector = 'input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"], select, .el-select__wrapper:not(.is-multiple), button:not(.btn-sm), .admin-header-controls > .btn'
const controls = Array.from(el.querySelectorAll<HTMLElement>(selector)).flatMap((control) => {
if (control.matches('.el-select__input, .el-input__inner') || control.closest('[role="listbox"], .cat-panel')) return []
const box = control.getBoundingClientRect()
if (!box.width || !box.height) return []
const name = control.getAttribute('placeholder') || control.textContent?.trim() || control.className
return [{ name, box }]
})
if (!controls.length) return ['没有测到可见控件']
const failures = controls.filter(({ box }) => Math.abs(box.height - 34) >= 1)
.map(({ name, box }) => `${name}: ${box.height}px`)
for (const [index, { name, box }] of controls.entries()) {
for (const other of controls.slice(index + 1)) {
const overlapY = Math.min(box.bottom, other.box.bottom) - Math.max(box.top, other.box.top)
if (overlapY < 17) continue
if (Math.abs(box.bottom - other.box.bottom) >= 1) failures.push(`${name} / ${other.name} 底边未对齐`)
}
}
return failures
})
}
for (const [platform, menus] of [['亚马逊', amazon], ['京东', jd]] as const) {
test(`${platform}:逐个点击侧栏菜单,检查筛选区外框`, async ({ page, baseURL }) => {
test.setTimeout(120_000)
const pageErrors: string[] = []
const missingFixtures = new Set<string>()
page.on('pageerror', (error) => pageErrors.push(error.message))
await page.route('**/*', async (route) => {
const url = new URL(route.request().url())
if (url.origin !== baseURL) return route.abort()
if (url.pathname === '/api/admin/current-user/menus') {
return route.fulfill({ json: { success: true, data: { items: allMenus } } })
}
if (Object.hasOwn(fixtures, url.pathname)) {
return route.fulfill({ json: { success: true, data: fixtures[url.pathname] } })
}
if (url.pathname.startsWith('/api/') && !serverFixtures.has(url.pathname)) {
missingFixtures.add(url.pathname)
return route.abort()
}
return route.continue()
})
await page.goto('/admin-vue/')
await page.getByRole('tab', { name: platform }).click()
const sidebar = page.locator('.admin-menu')
await expect(sidebar.getByRole('menuitem')).toHaveCount(menus.length)
const deviations: string[] = []
for (const [, name, path, selector] of menus) {
await test.step(name, async () => {
await sidebar.getByRole('menuitem', { name, exact: true }).click()
await expect(page).toHaveURL(new RegExp(`/admin-vue/${path}$`))
await expect(page.locator('.admin-topbar h1')).toHaveText(name)
const content = page.locator('#admin-content')
await expect(content.locator('.load-failure-bar:visible, .page-error:visible')).toHaveCount(0)
const record = async (label: string, row: Locator) => {
const mismatches = await controlDeviations(row)
if (mismatches.length) deviations.push(`${name}${label}:${mismatches.join('、')}`)
}
await record('', content.locator(`${selector}:visible`).first())
if (path === 'asin-center/registry') {
await record('日期导出', content.locator('.dedupe-filter-date-row'))
}
if (path === 'task-center/board') {
await content.getByRole('button', { name: /^变体采集/ }).click()
await expect(content.getByRole('heading', { name: '变体采集(麦象批量任务)' })).toBeVisible()
await record('变体采集', content.locator('.form-row:visible'))
}
})
}
expect.soft(pageErrors).toEqual([])
expect.soft([...missingFixtures], '逐菜单验收不能使用未登记的空响应').toEqual([])
expect(deviations).toEqual([])
})
}