feat(web-admin): add freight config sample partition helper
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
55e321f266
commit
ce9d836194
2 files changed
+81
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, it } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
partitionFreightConfigSamples,
|
||||
freightConfigSkipMessage,
|
||||
freightConfigAllConfiguredMessage
|
||||
} from './sample-freight-config-guard'
|
||||
|
||||
function row(partial: Record<string, unknown>) {
|
||||
return partial
|
||||
}
|
||||
|
||||
describe('partitionFreightConfigSamples', () => {
|
||||
it('splits configured vs unconfigured (id / draft / freightId)', () => {
|
||||
const selected = [
|
||||
row({ id: 'a', freight: { id: 'f1' } }),
|
||||
row({ id: 'b', freightDraft: { clientKey: 'k1' } }),
|
||||
row({ id: 'c', freightId: 'f2' }),
|
||||
row({ id: 'd' }),
|
||||
row({ id: 'e', freight: null, freightId: '' })
|
||||
]
|
||||
const { configurable, skipped } = partitionFreightConfigSamples(selected)
|
||||
assert.deepEqual(
|
||||
configurable.map((r) => r.id),
|
||||
['d', 'e']
|
||||
)
|
||||
assert.deepEqual(
|
||||
skipped.map((r) => r.id),
|
||||
['a', 'b', 'c']
|
||||
)
|
||||
})
|
||||
|
||||
it('treats empty selection as no configurable', () => {
|
||||
const { configurable, skipped } = partitionFreightConfigSamples([])
|
||||
assert.equal(configurable.length, 0)
|
||||
assert.equal(skipped.length, 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('freight config messages', () => {
|
||||
it('builds skip and all-configured copy', () => {
|
||||
assert.equal(
|
||||
freightConfigSkipMessage(2),
|
||||
'已跳过 2 个已配置运费的样本,将仅为其余样本配置运费'
|
||||
)
|
||||
assert.equal(
|
||||
freightConfigAllConfiguredMessage(),
|
||||
'所选样本均已配置运费,请先取消运费后再配置'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user