Files
X-Financial/web/tests/employee-management-history.test.mjs

63 lines
2.5 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
const employeeViewScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/EmployeeManagementView.js', import.meta.url)),
'utf8'
)
const employeeViewTemplate = readFileSync(
fileURLToPath(new URL('../src/views/EmployeeManagementView.vue', import.meta.url)),
'utf8'
)
const employeeViewStyles = readFileSync(
fileURLToPath(
new URL('../src/assets/styles/views/employee-management-view.css', import.meta.url)
),
'utf8'
)
function extractFormatEmployeeHistoryTime() {
const padMatched = employeeViewScript.match(
/function padDatePart\(value\) \{[\s\S]*?\n\}\n\n(?:export\s+)?function formatEmployeeHistoryTime/
)
assert.ok(padMatched, 'padDatePart should be present before history time formatter')
const matched = employeeViewScript.match(
/(?:export\s+)?function formatEmployeeHistoryTime\(value\) \{[\s\S]*?\n\}\n\nfunction resolveOrganizationUnitCode/
)
assert.ok(matched, 'formatEmployeeHistoryTime should be present before organization helpers')
const padSource = padMatched[0].replace(
/\n\n(?:export\s+)?function formatEmployeeHistoryTime[\s\S]*$/u,
''
)
const source = matched[0].replace(/\n\nfunction resolveOrganizationUnitCode[\s\S]*$/u, '')
return new Function(
'normalizeText',
`${padSource}; ${source}; return formatEmployeeHistoryTime;`
)((value) => String(value || '').trim())
}
test('employee history time uses fixed-width date and minute format', () => {
const formatEmployeeHistoryTime = extractFormatEmployeeHistoryTime()
assert.equal(formatEmployeeHistoryTime('2026年5月6日10时4分'), '2026-05-06 10:04')
assert.equal(formatEmployeeHistoryTime('2026-05-06T10:04:33+08:00'), '2026-05-06 10:04')
assert.equal(formatEmployeeHistoryTime('2026-05-06 10:04'), '2026-05-06 10:04')
})
test('employee history row keeps owner and time in aligned grid columns', () => {
assert.match(employeeViewTemplate, /class="history-row-owner"/)
assert.match(employeeViewTemplate, /class="history-row-time"/)
assert.doesNotMatch(employeeViewTemplate, /class="history-row-meta"/)
assert.match(employeeViewStyles, /\.history-row\s*\{[^}]*display:\s*grid/s)
assert.match(
employeeViewStyles,
/\.history-row\s*\{[^}]*grid-template-columns:\s*minmax\(0,\s*1fr\)\s*128px\s*112px/s
)
assert.match(employeeViewStyles, /\.history-row-time\s*\{[^}]*font-variant-numeric:\s*tabular-nums/s)
})