提交 40d98862 authored 作者: 王鹏飞's avatar 王鹏飞

test(admin): characterize editor node serialization

上级 cd66c024
import { describe, expect, it } from 'vitest'
import { editorFeatureRegistry } from '@/common/wangeditor-customer/features'
const galleryList = encodeURI(JSON.stringify([{ url: 'https://example.test/image.png', title: 'Image' }]))
const fixtures = {
chapterImage: { type: 'chapterImage', title: 'Image title', imgUrl: 'https://example.test/image.png', imgDescript: 'Image description', children: [{ text: '' }] },
chapterVideo: { type: 'chapterVideo', title: 'Video title', videoUrl: 'https://example.test/video.mp4', children: [{ text: '' }] },
chapterAudio: { type: 'chapterAudio', title: 'Audio title', audioUrl: 'https://example.test/audio.mp3', children: [{ text: '' }] },
chapterGallery: { type: 'chapterGallery', title: 'Gallery title', galleryList, random: 'gallery-1', flex: 1, theme: '#123456', children: [{ text: '' }] },
chapterGalleryInline: { type: 'chapterGalleryInline', title: 'Inline gallery', galleryList, random: 'gallery-2', flex: 1, theme: '#123456', fontsize: 18, children: [{ text: '' }] },
chapterFormula: { type: 'chapterFormula', formulaHtml: '<svg><text>x</text></svg>', children: [{ text: '' }] },
}
const expectedFields = {
chapterImage: ['title', 'imgUrl', 'imgDescript'],
chapterVideo: ['title', 'videoUrl'],
chapterAudio: ['title', 'audioUrl'],
chapterGallery: ['title', 'galleryList', 'random', 'flex'],
chapterGalleryInline: ['title', 'galleryList', 'random', 'flex', 'theme', 'fontsize'],
chapterFormula: ['formulaHtml'],
}
const configFor = type => {
const entry = editorFeatureRegistry.nodeModules.find(item => item.types.includes(type))
return {
toHtml: entry.module.elemsToHtml.find(item => item.type === type).elemToHtml,
parse: entry.module.parseElemsHtml.find(item => item.selector.includes(type)).parseElemHtml,
}
}
describe('custom node serialization', () => {
it.each(Object.keys(fixtures))('%s preserves its identifying fields', type => {
const fixture = fixtures[type]
const { toHtml, parse } = configFor(type)
const container = document.createElement('div')
container.innerHTML = toHtml(fixture, '')
const parsed = parse(container.firstElementChild, [], {})
expectedFields[type].forEach(field => expect(String(parsed[field])).toBe(String(fixture[field])))
})
})
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论