支持移动端样本编码远程关键字检索、分期起始日刷新与鸿蒙微信附件选取,并同步收款账户选择、角色页与相关设计文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
143 lines
5.1 KiB
JavaScript
143 lines
5.1 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFile } from 'node:fs/promises'
|
|
import test from 'node:test'
|
|
|
|
import {
|
|
HARMONY_FILE_SOURCES,
|
|
attachmentRejectionMessage,
|
|
collectAcceptedAttachments,
|
|
harmonyFileInputAttrs,
|
|
isHarmonyWechat
|
|
} from './harmony-file-picker.js'
|
|
|
|
const HARMONY_WECHAT_UA =
|
|
'Mozilla/5.0 (Phone; OpenHarmony 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile MicroMessenger/8.0.12'
|
|
const HUAWEI_ANDROID_WECHAT_UA =
|
|
'Mozilla/5.0 (Linux; Android 12; HarmonyOS; NOH-AN00) AppleWebKit/537.36 Chrome/99.0.4844.88 Mobile Safari/537.36 MicroMessenger/8.0.30'
|
|
const IPHONE_WECHAT_UA =
|
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.42'
|
|
|
|
test('detects HarmonyOS WeChat by ArkWeb or OpenHarmony plus MicroMessenger', () => {
|
|
assert.equal(isHarmonyWechat(HARMONY_WECHAT_UA), true)
|
|
assert.equal(
|
|
isHarmonyWechat(
|
|
'Mozilla/5.0 (Phone; OpenHarmony 5.0) AppleWebKit/537.36 Mobile MicroMessenger/8.0.5'
|
|
),
|
|
true
|
|
)
|
|
assert.equal(isHarmonyWechat(HUAWEI_ANDROID_WECHAT_UA), false)
|
|
assert.equal(isHarmonyWechat(IPHONE_WECHAT_UA), false)
|
|
assert.equal(
|
|
isHarmonyWechat(
|
|
'Mozilla/5.0 (Phone; OpenHarmony 6.0) AppleWebKit/537.36 ArkWeb/4.1.6.1 Mobile'
|
|
),
|
|
false
|
|
)
|
|
assert.equal(isHarmonyWechat(''), false)
|
|
})
|
|
|
|
test('offers camera, album, and system file sources', () => {
|
|
assert.deepEqual(
|
|
HARMONY_FILE_SOURCES.map((item) => item.name),
|
|
['拍照', '从相册选择', '从文件选择']
|
|
)
|
|
assert.deepEqual(
|
|
HARMONY_FILE_SOURCES.map((item) => item.value),
|
|
['camera', 'album', 'file']
|
|
)
|
|
})
|
|
|
|
test('maps each source to the file input that Harmony WeChat can open', () => {
|
|
assert.deepEqual(harmonyFileInputAttrs('camera'), {
|
|
accept: 'image/*',
|
|
capture: 'environment',
|
|
multiple: false
|
|
})
|
|
assert.deepEqual(harmonyFileInputAttrs('album'), {
|
|
accept: 'image/*',
|
|
capture: undefined,
|
|
multiple: true
|
|
})
|
|
assert.deepEqual(harmonyFileInputAttrs('file'), {
|
|
accept: '',
|
|
capture: undefined,
|
|
multiple: true
|
|
})
|
|
assert.equal(harmonyFileInputAttrs('other'), null)
|
|
})
|
|
|
|
test('keeps files whose extension or image mime is on the original accept list', () => {
|
|
const accept = '.jpg,.jpeg,.png,.pdf,.doc,.docx'
|
|
assert.equal(attachmentRejectionMessage(file('a.PDF', 'application/pdf'), { accept }), '')
|
|
assert.equal(attachmentRejectionMessage(file('a.jpg', ''), { accept }), '')
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('camera', 'image/jpeg'), { accept }),
|
|
''
|
|
)
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('clip.gif', 'image/gif'), { accept }),
|
|
'不支持该附件类型'
|
|
)
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('note.txt', 'text/plain'), { accept }),
|
|
'不支持该附件类型'
|
|
)
|
|
})
|
|
|
|
test('treats image and video wildcards as their mime families', () => {
|
|
const accept = 'image/*,video/*,.pdf'
|
|
assert.equal(attachmentRejectionMessage(file('a.png', 'image/png'), { accept }), '')
|
|
assert.equal(attachmentRejectionMessage(file('a.mov', 'video/quicktime'), { accept }), '')
|
|
assert.equal(attachmentRejectionMessage(file('a.pdf', ''), { accept }), '')
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('a.zip', 'application/zip'), { accept }),
|
|
'不支持该附件类型'
|
|
)
|
|
})
|
|
|
|
test('rejects oversized files before type and reports one message for a mixed batch', () => {
|
|
const accept = '.jpg,.pdf'
|
|
const maxBytes = 10 * 1024 * 1024
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('a.pdf', 'application/pdf', maxBytes), { accept, maxBytes }),
|
|
''
|
|
)
|
|
assert.equal(
|
|
attachmentRejectionMessage(file('a.pdf', 'application/pdf', maxBytes + 1), { accept, maxBytes }),
|
|
'单个附件不能超过10MB'
|
|
)
|
|
const result = collectAcceptedAttachments(
|
|
[
|
|
file('bad.txt', 'text/plain', 1),
|
|
file('ok.pdf', 'application/pdf', 4),
|
|
file('big.pdf', 'application/pdf', maxBytes + 1)
|
|
],
|
|
{ accept, maxBytes }
|
|
)
|
|
assert.deepEqual(result.accepted.map((item) => item.name), ['ok.pdf'])
|
|
assert.equal(result.message, '不支持该附件类型')
|
|
})
|
|
|
|
function file(name, type, size = 1) {
|
|
return { name, type, size }
|
|
}
|
|
|
|
test('market and oa attachment entries share the harmony source sheet', async () => {
|
|
const [cards, upload, comment, source] = await Promise.all([
|
|
readFile(new URL('../market/components/MarketAttachmentCards.vue', import.meta.url), 'utf8'),
|
|
readFile(new URL('../oa/components/OaUploadField.vue', import.meta.url), 'utf8'),
|
|
readFile(new URL('../oa/components/OaCommentComposer.vue', import.meta.url), 'utf8'),
|
|
readFile(new URL('../components/HarmonyFileSource.vue', import.meta.url), 'utf8')
|
|
])
|
|
for (const content of [cards, upload, comment]) {
|
|
assert.match(content, /HarmonyFileSource/)
|
|
assert.match(content, /isHarmonyWechat/)
|
|
}
|
|
assert.match(cards, /<van-uploader/)
|
|
assert.match(cards, /v-if="editable && !useHarmonyPicker"/)
|
|
assert.match(upload, /pointer-events:\s*none/)
|
|
assert.match(source, /input\.click\(\)/)
|
|
assert.match(source, /collectAcceptedAttachments/)
|
|
assert.match(source, /harmonyFileInputAttrs/)
|
|
})
|