You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
1.9 KiB

import { describe, expect, test } from 'bun:test'
import {
buildPostBodyMarkdownEditorVditorOptions,
postBodyMarkdownEditorToolbarPresets,
} from './post-body-markdown-editor-vditor-config'
describe('PostBodyMarkdownEditor Vditor config', () => {
test('桌面端使用完整工具栏与可预览模式', () => {
const options = buildPostBodyMarkdownEditorVditorOptions({
value: 'hello',
isMobile: false,
onInput: () => undefined,
uploadHandler: async () => '',
})
expect(options.mode).toBe('sv')
expect(options.toolbar).toEqual(postBodyMarkdownEditorToolbarPresets.desktop)
expect(postBodyMarkdownEditorToolbarPresets.desktop.includes('preview')).toBe(false)
expect(postBodyMarkdownEditorToolbarPresets.desktop.length).toBeGreaterThan(postBodyMarkdownEditorToolbarPresets.mobile.length)
})
test('移动端使用精简工具栏并将预览作为次级入口', () => {
const options = buildPostBodyMarkdownEditorVditorOptions({
value: 'hello',
isMobile: true,
onInput: () => undefined,
uploadHandler: async () => '',
})
expect(options.mode).toBe('ir')
expect(options.toolbar).toEqual(postBodyMarkdownEditorToolbarPresets.mobile)
expect(postBodyMarkdownEditorToolbarPresets.mobile).toEqual([
'bold',
'italic',
'headings',
'|',
'list',
'ordered-list',
'|',
'link',
'upload',
'code',
'|',
'preview',
])
})
test('上传处理器透传到 upload.handler', async () => {
const uploadHandler = async () => 'ok'
const options = buildPostBodyMarkdownEditorVditorOptions({
value: '',
isMobile: false,
onInput: () => undefined,
uploadHandler,
}) as { upload?: { handler?: (files: File[]) => Promise<string> } }
expect(options.upload?.handler).toBeDefined()
const result = await options.upload?.handler?.([] as File[])
expect(result).toBe('ok')
})
})