Files
zkxw/mobile-oa-h5/src/utils/host-file-preview-nav.test.js
T
zlwuandCursor e488b86c35
continuous-integration/drone/tag Build is passing
fix(mobile): 小程序 WebView 附件下载改走宿主原生预览页
鸿蒙微信 ArkWeb 下 H5 window.open 常静默失败,仅出现「开始下载…」。
OA/市场附件在小程序 WebView 内改为跳转 pages/oa/file-preview,
用 uni.downloadFile + openDocument 打开,浏览器环境仍用预签名直链。

Refs: #74
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-09 15:04:14 +08:00

37 lines
1.3 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
asciiHostFileName,
buildHostFilePreviewPath,
openDocumentFileType
} from './host-file-preview-nav.js'
test('ascii host file name keeps extension only', () => {
assert.equal(asciiHostFileName('26-10生产任务.xlsx'), 'file.xlsx')
assert.equal(asciiHostFileName('report.PDF'), 'file.pdf')
assert.equal(asciiHostFileName('plain'), 'file.bin')
})
test('openDocument file types cover office docs', () => {
assert.equal(openDocumentFileType('a.xlsx'), 'xlsx')
assert.equal(openDocumentFileType('a.XLS'), 'xls')
assert.equal(openDocumentFileType('a.docx'), 'docx')
assert.equal(openDocumentFileType('a.zip'), '')
})
test('host file preview path is short and points at file-preview page', () => {
const built = buildHostFilePreviewPath({
fileUrl: 'oa-approval/202610/abc.xlsx',
fileName: '26-10生产任务.xlsx'
})
assert.ok(built.path.startsWith('/pages/oa/file-preview/index?'))
assert.ok(built.path.includes('fileUrl='))
assert.ok(built.path.includes('&f='))
assert.ok(built.path.includes('&n=file.xlsx'))
assert.equal(built.fileType, 'xlsx')
assert.ok(!built.path.includes('%E7%94%9F'))
assert.ok(built.queryLen < 400)
assert.ok(built.path.length < 500)
})