feat(miniprogram): add invoice thumb helper utilities.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ea4d990abb
commit
4201d656b1
2 files changed
+147
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
isImageFileType,
|
||||
fileExtLabel,
|
||||
formatInvoiceDateYmd,
|
||||
buildAttachItemsFromInvoiceRows,
|
||||
mergeInvoicePicksByDraftKeys
|
||||
} from '../utils/bxInvoiceThumb.js'
|
||||
|
||||
assert.equal(isImageFileType('image/jpeg'), true)
|
||||
assert.equal(isImageFileType('application/pdf'), false)
|
||||
assert.equal(fileExtLabel('a.PDF'), 'PDF')
|
||||
assert.equal(formatInvoiceDateYmd('2026-09-16T12:00:00'), '2026-09-16')
|
||||
assert.equal(formatInvoiceDateYmd(''), '—')
|
||||
|
||||
const rows = [
|
||||
{
|
||||
id: 'inv1',
|
||||
amount: 100,
|
||||
createTime: '2026-09-01T10:00:00',
|
||||
attachments: [
|
||||
{ id: 'a1', fileName: 'x.jpg', fileType: 'image/jpeg' },
|
||||
{ id: 'a2', fileName: 'y.pdf', fileType: 'application/pdf' }
|
||||
]
|
||||
}
|
||||
]
|
||||
const items = buildAttachItemsFromInvoiceRows(rows)
|
||||
assert.equal(items.length, 2)
|
||||
assert.equal(items[0].key, 'inv1:a1')
|
||||
assert.equal(items[1].fileName, 'y.pdf')
|
||||
|
||||
const prev = [
|
||||
{
|
||||
key: 'inv9:a9',
|
||||
invoiceId: 'inv9',
|
||||
attachmentId: 'a9',
|
||||
amount: 9,
|
||||
createTime: '2026-08-01',
|
||||
fileName: 'old.jpg',
|
||||
fileType: 'image/jpeg',
|
||||
previewUrl: 'http://old'
|
||||
}
|
||||
]
|
||||
const merged = mergeInvoicePicksByDraftKeys(
|
||||
['inv9:a9', 'inv1:a1'],
|
||||
items,
|
||||
prev
|
||||
)
|
||||
assert.equal(merged.length, 2)
|
||||
assert.ok(merged.some((p) => p.key === 'inv9:a9' && p.previewUrl === 'http://old'))
|
||||
assert.ok(merged.some((p) => p.key === 'inv1:a1'))
|
||||
|
||||
console.log('bxInvoiceThumb ok')
|
||||
Reference in new issue
Block a user