|
|
@@ -0,0 +1,63 @@
|
|
|
+import assert from 'node:assert/strict'
|
|
|
+import { describe, it } from 'node:test'
|
|
|
+import {
|
|
|
+ sanitizeRemarkBaseName,
|
|
|
+ buildApplyAttachmentDisplayName,
|
|
|
+ mapApplyAttachmentDisplayNames
|
|
|
+} from './attachment-display-name'
|
|
|
+
|
|
|
+describe('sanitizeRemarkBaseName', () => {
|
|
|
+ it('trims and replaces illegal chars and spaces', () => {
|
|
|
+ assert.equal(sanitizeRemarkBaseName(' 差旅/说明 A '), '差旅_说明_A')
|
|
|
+ })
|
|
|
+
|
|
|
+ it('truncates to 40 chars', () => {
|
|
|
+ const long = '啊'.repeat(50)
|
|
|
+ assert.equal(sanitizeRemarkBaseName(long).length, 40)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('returns empty for blank', () => {
|
|
|
+ assert.equal(sanitizeRemarkBaseName(' '), '')
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('buildApplyAttachmentDisplayName', () => {
|
|
|
+ it('falls back to original when remark empty', () => {
|
|
|
+ assert.equal(
|
|
|
+ buildApplyAttachmentDisplayName({ remark: '', originalFileName: 'a.pdf', index1: 1 }),
|
|
|
+ 'a.pdf'
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('uses remark_index + ext', () => {
|
|
|
+ assert.equal(
|
|
|
+ buildApplyAttachmentDisplayName({
|
|
|
+ remark: '差旅说明',
|
|
|
+ originalFileName: 'photo.JPG',
|
|
|
+ index1: 2
|
|
|
+ }),
|
|
|
+ '差旅说明_2.JPG'
|
|
|
+ )
|
|
|
+ })
|
|
|
+
|
|
|
+ it('handles missing extension', () => {
|
|
|
+ assert.equal(
|
|
|
+ buildApplyAttachmentDisplayName({
|
|
|
+ remark: '说明',
|
|
|
+ originalFileName: 'readme',
|
|
|
+ index1: 1
|
|
|
+ }),
|
|
|
+ '说明_1'
|
|
|
+ )
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('mapApplyAttachmentDisplayNames', () => {
|
|
|
+ it('maps list with 1-based indices', () => {
|
|
|
+ const out = mapApplyAttachmentDisplayNames('备注', [
|
|
|
+ { fileName: 'a.pdf' },
|
|
|
+ { fileName: 'b.jpg' }
|
|
|
+ ])
|
|
|
+ assert.deepEqual(out, ['备注_1.pdf', '备注_2.jpg'])
|
|
|
+ })
|
|
|
+})
|