feat: 完善知识库预览功能与配置管理优化
This commit is contained in:
25
web/tests/knowledge-preview-layout.test.mjs
Normal file
25
web/tests/knowledge-preview-layout.test.mjs
Normal file
@@ -0,0 +1,25 @@
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { resolveKnowledgePreviewLayoutState } from '../src/views/scripts/knowledgePreviewLayout.js'
|
||||
|
||||
function testUsesLibraryOnlyLayoutWithoutSelection() {
|
||||
assert.deepEqual(resolveKnowledgePreviewLayoutState(null), {
|
||||
isPreviewModalOpen: false,
|
||||
usesSplitLayout: false
|
||||
})
|
||||
}
|
||||
|
||||
function testUsesModalPreviewLayoutWhenDocumentIsSelected() {
|
||||
assert.deepEqual(resolveKnowledgePreviewLayoutState({ id: 'doc-1' }), {
|
||||
isPreviewModalOpen: true,
|
||||
usesSplitLayout: false
|
||||
})
|
||||
}
|
||||
|
||||
function run() {
|
||||
testUsesLibraryOnlyLayoutWithoutSelection()
|
||||
testUsesModalPreviewLayoutWhenDocumentIsSelected()
|
||||
console.log('knowledge preview layout tests passed')
|
||||
}
|
||||
|
||||
run()
|
||||
@@ -1,6 +1,10 @@
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { resolveKnowledgePreviewMode } from '../src/views/scripts/knowledgePreviewMode.js'
|
||||
import {
|
||||
resolveKnowledgePreviewMode,
|
||||
shouldRenderOnlyOfficeHost,
|
||||
shouldRenderOnlyOfficePreview
|
||||
} from '../src/views/scripts/knowledgePreviewMode.js'
|
||||
|
||||
function testPrefersOnlyOfficeForSupportedOfficeFileWhenAvailable() {
|
||||
const document = {
|
||||
@@ -29,10 +33,108 @@ function testUsesPreviewKindForNonOnlyOfficeFile() {
|
||||
assert.equal(resolveKnowledgePreviewMode(document, { onlyOfficeAvailable: false }), 'pdf')
|
||||
}
|
||||
|
||||
function testRendersOnlyOfficeContainerWhileOfficePreviewIsLoading() {
|
||||
const document = {
|
||||
extension: 'docx',
|
||||
previewKind: 'text'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficePreview(document, {
|
||||
onlyOfficeLoading: true,
|
||||
onlyOfficeAvailable: false
|
||||
}),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
function testKeepsOnlyOfficeContainerVisibleWhenOfficePreviewHasError() {
|
||||
const document = {
|
||||
extension: 'docx',
|
||||
previewKind: 'text'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficePreview(document, {
|
||||
onlyOfficeLoading: false,
|
||||
onlyOfficeAvailable: false,
|
||||
onlyOfficeError: 'timeout'
|
||||
}),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
function testDoesNotRenderOnlyOfficeContainerAfterFailedMount() {
|
||||
const document = {
|
||||
extension: 'xlsx',
|
||||
previewKind: 'table'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficePreview(document, {
|
||||
onlyOfficeLoading: false,
|
||||
onlyOfficeAvailable: false
|
||||
}),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
function testRendersOnlyOfficeHostWhileOfficePreviewIsLoading() {
|
||||
const document = {
|
||||
extension: 'pptx',
|
||||
previewKind: 'slides'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficeHost(document, {
|
||||
onlyOfficeLoading: true,
|
||||
onlyOfficeAvailable: false
|
||||
}),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
function testKeepsOnlyOfficeHostVisibleWhenOfficePreviewHasError() {
|
||||
const document = {
|
||||
extension: 'xlsx',
|
||||
previewKind: 'table'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficeHost(document, {
|
||||
onlyOfficeLoading: false,
|
||||
onlyOfficeAvailable: false,
|
||||
onlyOfficeError: 'timeout'
|
||||
}),
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
function testDoesNotRenderOnlyOfficeHostForNonOfficeDocuments() {
|
||||
const document = {
|
||||
extension: 'pdf',
|
||||
previewKind: 'pdf'
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
shouldRenderOnlyOfficeHost(document, {
|
||||
onlyOfficeLoading: true,
|
||||
onlyOfficeAvailable: false
|
||||
}),
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
function run() {
|
||||
testPrefersOnlyOfficeForSupportedOfficeFileWhenAvailable()
|
||||
testFallsBackToStructuredPreviewForOfficeFileWhenOnlyOfficeUnavailable()
|
||||
testUsesPreviewKindForNonOnlyOfficeFile()
|
||||
testRendersOnlyOfficeContainerWhileOfficePreviewIsLoading()
|
||||
testKeepsOnlyOfficeContainerVisibleWhenOfficePreviewHasError()
|
||||
testDoesNotRenderOnlyOfficeContainerAfterFailedMount()
|
||||
testRendersOnlyOfficeHostWhileOfficePreviewIsLoading()
|
||||
testKeepsOnlyOfficeHostVisibleWhenOfficePreviewHasError()
|
||||
testDoesNotRenderOnlyOfficeHostForNonOfficeDocuments()
|
||||
console.log('knowledge preview mode tests passed')
|
||||
}
|
||||
|
||||
|
||||
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