fix(web-admin): 运输归档合计行与可见表头列对齐。
planNo 可隐藏后不再硬编码插入,避免统计行按索引错位。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
82c21262ed
commit
04450fff88
2 files changed
+76
-17
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* #41 回归:运输归档绿色合计行须与表头列一一对应。
|
||||
* planNo 可隐藏后,不得再无条件硬编码插入 planNo,否则按索引错位。
|
||||
*/
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { buildStatsRowColumns } from '../src/utils/list-column-stats.ts'
|
||||
|
||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||
|
||||
const ARCHIVE_DEFS = [
|
||||
{ prop: 'planNo' },
|
||||
{ prop: 'planDate' },
|
||||
{ prop: 'planQty' },
|
||||
{ prop: 'actualQty' },
|
||||
{ prop: 'amount' }
|
||||
]
|
||||
|
||||
test('buildStatsRowColumns: hidden planNo must not leave a phantom stats cell', () => {
|
||||
const visible = new Set(['planDate', 'planQty', 'actualQty', 'amount'])
|
||||
const cols = buildStatsRowColumns({
|
||||
leadingSpacers: 2,
|
||||
optionalDefs: ARCHIVE_DEFS,
|
||||
isColumnVisible: (prop) => visible.has(prop),
|
||||
moneyProps: ['amount']
|
||||
})
|
||||
const props = cols.map((c) => c.prop || c.key)
|
||||
assert.deepEqual(props, [
|
||||
'__spacer_0',
|
||||
'__spacer_1',
|
||||
'planDate',
|
||||
'planQty',
|
||||
'actualQty',
|
||||
'amount'
|
||||
])
|
||||
assert.equal(cols.filter((c) => c.prop === 'planNo').length, 0)
|
||||
})
|
||||
|
||||
test('buildStatsRowColumns: visible planNo appears once after spacers', () => {
|
||||
const visible = new Set(['planNo', 'planDate', 'planQty'])
|
||||
const cols = buildStatsRowColumns({
|
||||
leadingSpacers: 2,
|
||||
optionalDefs: ARCHIVE_DEFS,
|
||||
isColumnVisible: (prop) => visible.has(prop)
|
||||
})
|
||||
const props = cols.map((c) => c.prop || c.key)
|
||||
assert.deepEqual(props, ['__spacer_0', '__spacer_1', 'planNo', 'planDate', 'planQty'])
|
||||
assert.equal(cols.filter((c) => c.prop === 'planNo').length, 1)
|
||||
})
|
||||
|
||||
test('plan-archive: stats row builds from visible columns without always-on planNo', () => {
|
||||
const src = readFileSync(join(root, 'src/views/pl/plan-archive/index.vue'), 'utf8')
|
||||
assert.match(
|
||||
src,
|
||||
/archiveStatsRowColumns[\s\S]*?buildStatsRowColumns\s*\(/,
|
||||
'archive stats columns should use buildStatsRowColumns so visibility stays in sync'
|
||||
)
|
||||
assert.doesNotMatch(
|
||||
src,
|
||||
/archiveStatsRowColumns[\s\S]*?key:\s*'__index'[\s\S]*?key:\s*'planNo'[\s\S]*?for\s*\(\s*const\s+def\s+of\s+listColumnDefs/,
|
||||
'must not hardcode planNo before looping listColumnDefs (causes off-by-one when hidden)'
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user