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

60 lines
2.4 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/RecordsHistoryPage.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 保持自身实现不动。
const dup = readSource('src/pages/tasks/DuplicateCheckPage.vue')
assert.match(dup, /el-table-column/, 'DuplicateCheckPage 表格仍在且未被修改')
})
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 自身宽度保留')
})