feat: 完善知识库预览功能与配置管理优化
This commit is contained in:
54
web/tests/onlyoffice-preview-config.test.mjs
Normal file
54
web/tests/onlyoffice-preview-config.test.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { buildOnlyOfficePreviewConfig } from '../src/views/scripts/onlyOfficePreviewConfig.js'
|
||||
|
||||
function testUsesExplicitPixelHeightFromViewport() {
|
||||
const config = buildOnlyOfficePreviewConfig({ width: '50%', height: '100%' }, { viewportHeight: 900 })
|
||||
|
||||
assert.equal(config.width, '100%')
|
||||
assert.equal(config.height, '680px')
|
||||
}
|
||||
|
||||
function testFallsBackToSafeDefaultHeight() {
|
||||
const config = buildOnlyOfficePreviewConfig({}, {})
|
||||
|
||||
assert.equal(config.height, '720px')
|
||||
}
|
||||
|
||||
function testClampsSmallViewportHeight() {
|
||||
const config = buildOnlyOfficePreviewConfig({}, { viewportHeight: 600 })
|
||||
|
||||
assert.equal(config.height, '520px')
|
||||
}
|
||||
|
||||
function testUsesEmbeddedPreviewModeWithMinimalToolbar() {
|
||||
const config = buildOnlyOfficePreviewConfig(
|
||||
{
|
||||
editorConfig: {
|
||||
customization: {
|
||||
compactHeader: true
|
||||
}
|
||||
}
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
assert.equal(config.type, 'embedded')
|
||||
assert.deepEqual(config.editorConfig.embedded, {
|
||||
embedUrl: '',
|
||||
fullscreenUrl: '',
|
||||
saveUrl: '',
|
||||
shareUrl: '',
|
||||
toolbarDocked: 'top'
|
||||
})
|
||||
}
|
||||
|
||||
function run() {
|
||||
testUsesExplicitPixelHeightFromViewport()
|
||||
testFallsBackToSafeDefaultHeight()
|
||||
testClampsSmallViewportHeight()
|
||||
testUsesEmbeddedPreviewModeWithMinimalToolbar()
|
||||
console.log('onlyoffice preview config tests passed')
|
||||
}
|
||||
|
||||
run()
|
||||
Reference in New Issue
Block a user