Files
shanxia2.0/web-admin/scripts/cert-list-face.test.ts
T
wuzilongandCursor 522b4be705 feat(pl): 装送货段增加同市标记,并同步额度证件与计划表单。
同市易制毒段只校验购买证;同步 Web/H5 表单、额度统计展示与相关回归测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 16:34:58 +08:00

71 lines
2.7 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
buyPartyName,
certFaceFields,
certKindLabel,
certKindTagType,
compareCertUploadTime,
expiryWarning,
salePartyName
} from '../src/views/pl/quota-cert/cert-list-face'
const today = new Date(2026, 10, 4)
test('purchase and transport certificates use their own party names', () => {
assert.equal(salePartyName({ certType: 'purchase', sellerName: '销售方', shipperName: '货主' }), '销售方')
assert.equal(buyPartyName({ certType: 'purchase', buyerName: '购买方', consigneeName: '收货方' }), '购买方')
assert.equal(salePartyName({ certType: 'transport', sellerName: '销售方', shipperName: '货主' }), '货主')
assert.equal(buyPartyName({ certType: 'transport', buyerName: '购买方', consigneeName: '收货方' }), '收货方')
assert.equal(salePartyName({ certType: 'transport', salePartyName: '已汇总货主', shipperName: '货主' }), '已汇总货主')
})
test('contract certificate face fields stay beside the shared quantity labels', () => {
assert.deepEqual(
certFaceFields({
certType: 'transport',
shipperName: '货主',
consigneeName: '收货方',
validUseText: '一次有效',
validTo: '2026-11-04'
}).map((item) => item.label),
['销售单位', '购买单位', '有效次数', '是否预警']
)
const [seller, buyer, times, alert] = certFaceFields({
certType: 'transport',
shipperName: '货主',
consigneeName: '收货方',
validUseText: '一次有效',
validTo: '2026-11-04'
})
assert.equal(seller.value, '货主')
assert.equal(buyer.value, '收货方')
assert.equal(times.value, '一次有效')
assert.equal(alert.value, '今天到期')
assert.equal(alert.alert, true)
})
test('only certificates expiring within seven days show a red warning label', () => {
assert.equal(expiryWarning('2026-11-04', today)?.label, '今天到期')
assert.equal(expiryWarning('2026-11-11', today)?.label, '7天后到期')
assert.equal(expiryWarning('2026-11-03', today), null)
assert.equal(expiryWarning('2026-11-12', today), null)
assert.equal(expiryWarning('', today), null)
})
test('merged certificate lists follow upload time, then id, descending', () => {
assert.equal(certKindLabel('transport'), '运输证')
assert.equal(certKindLabel('purchase'), '购买证')
assert.equal(certKindTagType('transport'), 'warning')
assert.equal(certKindTagType('purchase'), 'success')
const rows = [
{ id: 'b', createTime: '2026-11-01 10:00:00' },
{ id: 'a', createTime: '2026-11-05 10:00:00' },
{ id: 'c', createTime: '2026-11-05 10:00:00' }
].sort(compareCertUploadTime)
assert.deepEqual(
rows.map((row) => row.id),
['c', 'a', 'b']
)
})