fix(web-admin): harden receive account display helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-07-30 13:49:02 +08:00
1 parent d946b91dd1
commit 4e805f9625
2 files changed
+83 -10

No files matched your search

@@ -6,6 +6,8 @@ import {
formatReceiveAccountLine,
isReceiveAccountSnapshot,
normalizeReceiveAccountModelValue,
optionLabelFromRow,
snapshotFromRow,
type ReceiveAccountSnapshot
} from './oa-receive-account-value'
@@ -65,4 +67,70 @@ describe('oa-receive-account-value', () => {
const text = formatReceiveAccountDisplay([alipay, personal])
assert.ok(text.includes('\n'))
})
it('format line personal province only', () => {
const line = formatReceiveAccountLine({
...personal,
bankCity: ''
})
assert.ok(line.includes('安徽省'))
assert.ok(!line.includes(' / '))
})
it('format line personal city only', () => {
const line = formatReceiveAccountLine({
...personal,
bankProvince: ''
})
assert.ok(line.includes('合肥市'))
assert.ok(!line.includes(' / '))
})
it('optionLabelFromRow minimal row', () => {
assert.equal(
optionLabelFromRow({
accountType: 'alipay',
accountName: '张三',
accountNo: '13800138000'
}),
'支付宝 · 张三 · 13800138000'
)
})
it('optionLabelFromRow unknown type falls back to raw type', () => {
assert.equal(
optionLabelFromRow({
accountType: 'other',
accountName: '王五',
accountNo: '9999'
}),
'other · 王五 · 9999'
)
})
it('snapshotFromRow maps and trims fields', () => {
assert.deepEqual(
snapshotFromRow({
id: ' 10 ',
accountType: 'corporate',
accountName: ' 公司 ',
accountNo: ' 123 ',
bankName: '建行',
bankProvince: '北京',
bankCity: '北京',
bankBranch: '分行',
remark: '备注'
}),
{
id: '10',
accountType: 'corporate',
accountName: '公司',
accountNo: '123',
bankName: '建行',
bankProvince: '北京',
bankCity: '北京',
bankBranch: '分行',
remark: '备注'
}
)
})
it('snapshotFromRow defaults invalid type to personal', () => {
const snap = snapshotFromRow({ id: '1', accountType: 'invalid' })
assert.equal(snap.accountType, 'personal')
})
})
+15 -10
View File
@@ -78,8 +78,11 @@ export function formatReceiveAccountLine(item: ReceiveAccountSnapshot): string {
]
if (item.accountType === 'personal' || item.accountType === 'corporate') {
if (item.bankName) parts.push(item.bankName)
if (item.bankProvince || item.bankCity) {
parts.push(`${item.bankProvince} / ${item.bankCity}`)
const { bankProvince, bankCity } = item
if (bankProvince && bankCity) {
parts.push(`${bankProvince} / ${bankCity}`)
} else if (bankProvince || bankCity) {
parts.push(bankProvince || bankCity)
}
if (item.bankBranch) parts.push(item.bankBranch)
}
@@ -93,14 +96,16 @@ export function formatReceiveAccountDisplay(raw: unknown): string {
.join('\n')
}
export function optionLabelFromRow(row: ReceiveAccountSnapshot): string {
return [
ACCOUNT_TYPE_LABEL[row.accountType],
row.accountName,
row.accountNo
]
.filter(Boolean)
.join(' · ')
export function optionLabelFromRow(row: {
accountType: ReceiveAccountType | string
accountName: string
accountNo: string
}): string {
const typeLabel =
(isReceiveAccountType(row.accountType)
? ACCOUNT_TYPE_LABEL[row.accountType]
: undefined) || row.accountType
return [typeLabel, row.accountName, row.accountNo].filter(Boolean).join(' · ')
}
export function snapshotFromRow(row: any): ReceiveAccountSnapshot {