refactor: enforce 800 line source limits
This commit is contained in:
@@ -3,10 +3,8 @@ 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'
|
||||
)
|
||||
import { formatEmployeeHistoryTime } from '../src/views/scripts/employeeManagementModel.js'
|
||||
|
||||
const employeeViewTemplate = readFileSync(
|
||||
fileURLToPath(new URL('../src/views/EmployeeManagementView.vue', import.meta.url)),
|
||||
'utf8'
|
||||
@@ -18,31 +16,7 @@ const employeeViewStyles = readFileSync(
|
||||
'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')
|
||||
|
||||
Reference in New Issue
Block a user