diff --git a/web-admin/src/utils/oa-receive-account-value.test.ts b/web-admin/src/utils/oa-receive-account-value.test.ts index e86ced27..b393281c 100644 --- a/web-admin/src/utils/oa-receive-account-value.test.ts +++ b/web-admin/src/utils/oa-receive-account-value.test.ts @@ -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') + }) }) diff --git a/web-admin/src/utils/oa-receive-account-value.ts b/web-admin/src/utils/oa-receive-account-value.ts index 09b7e723..de31fa60 100644 --- a/web-admin/src/utils/oa-receive-account-value.ts +++ b/web-admin/src/utils/oa-receive-account-value.ts @@ -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 {