Files
crawler-plugin/admin-frontend-vue/tests/align-column-width.test.ts
T

64 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
// 验收反馈:所有列表的宽度列自适应。
// 不变式:列表页 el-table-column 一律用 min-width(弹性分配,随容器自适应),不得残留固定 width。
// 例外:DuplicateCheckPage 不动;dialog/表单的 width 不属于表格列。
const PAGES = [
'src/pages/account/GroupsPage.vue',
'src/pages/account/MenusPage.vue',
'src/pages/account/UsersPage.vue',
'src/pages/asin/AsinInvalidPage.vue',
'src/pages/asin/DedupeRegistryPage.vue',
'src/pages/asin/ProductCategoryPage.vue',
'src/pages/asin/QueryAsinPage.vue',
'src/pages/asin/SkipPricePage.vue',
'src/pages/records/RecordsDigitalHumanVersionPage.vue',
'src/pages/records/RecordsSoftwareVersionPage.vue',
'src/pages/shop/ShopKeysPage.vue',
'src/pages/shop/ShopManagePage.vue',
'src/pages/tasks/ImageVideoTasksPage.vue',
'src/pages/tasks/ShopDataTasksPage.vue',
]
function columnWidthLines(src: string): string[] {
// 只检查 el-table-column 标签行内出现的固定 width="数字"。
return src
.split('\n')
.filter((line) => /<el-table-column[^>]*\swidth="\d+"/.test(line))
}
test('align_column_width_normal_primary_path', () => {
for (const page of PAGES) {
const bad = columnWidthLines(readSource(page))
assert.equal(bad.length, 0, `${page} 表格列不得残留固定 width(应改 min-width: ${bad.join(' | ')}`)
}
})
test('align_column_width_normal_variant_input', () => {
// 自适应不意味着无下限:至少保留一处 min-width 以保证内容可读。
for (const page of PAGES) {
const src = readSource(page)
assert.match(src, /el-table-column[^>]*min-width|el-table-column/, `${page} 应有表格列定义`)
}
})
test('align_column_width_boundary_empty_input', () => {
// 例外页 DuplicateCheckPage 已整页复刻 reference 撞款控制台(原生 ledger 表格),不参与 el-table 列宽约定。
const dup = readSource('src/pages/tasks/DuplicateCheckPage.vue')
assert.equal(/el-table-column/.test(dup), false, '撞款台账已用 reference 原生表格,不再有 el-table-column')
assert.match(dup, /class="ledger"/, '撞款台账仍为表格实现')
const hist = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.equal(/el-table-column/.test(hist), false, '生成记录已像素复刻 admin panel-history 原生表格,不再有 el-table-column')
assert.match(hist, /class="table-scroll history-table-scroll"/, '生成记录用原生 .table-scroll 表格')
assert.match(hist, /<th[^>]*>结果预览<\/th>/, '原生表含结果预览列')
})
test('align_column_width_dependency_failure_returns_actionable_message', () => {
// dialog 宽度(如 width="620px")与表单宽度不受影响——只约束 el-table-column 行。
const shop = readSource('src/pages/tasks/ShopDataTasksPage.vue')
assert.match(shop, /el-dialog[^>]*width="\d+px"/, 'el-dialog 自身宽度保留')
})