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.
49 lines
1.3 KiB
49 lines
1.3 KiB
import { describe, expect, test } from 'bun:test'
|
|
import { handlePostBodyMarkdownEditorViewportSwitch } from './post-body-markdown-editor-vditor-viewport'
|
|
|
|
describe('PostBodyMarkdownEditor viewport switch', () => {
|
|
test('断点未变化时不重建且返回 false', () => {
|
|
let remountCalls = 0
|
|
const changed = handlePostBodyMarkdownEditorViewportSwitch({
|
|
currentIsMobile: false,
|
|
nextIsMobile: false,
|
|
hasMountedEditor: true,
|
|
remountEditor: () => {
|
|
remountCalls += 1
|
|
},
|
|
})
|
|
|
|
expect(changed).toBe(false)
|
|
expect(remountCalls).toBe(0)
|
|
})
|
|
|
|
test('断点变化且已挂载时会重建编辑器', () => {
|
|
let remountCalls = 0
|
|
const changed = handlePostBodyMarkdownEditorViewportSwitch({
|
|
currentIsMobile: false,
|
|
nextIsMobile: true,
|
|
hasMountedEditor: true,
|
|
remountEditor: () => {
|
|
remountCalls += 1
|
|
},
|
|
})
|
|
|
|
expect(changed).toBe(true)
|
|
expect(remountCalls).toBe(1)
|
|
})
|
|
|
|
test('断点变化但未挂载时仅更新状态不重建', () => {
|
|
let remountCalls = 0
|
|
const changed = handlePostBodyMarkdownEditorViewportSwitch({
|
|
currentIsMobile: true,
|
|
nextIsMobile: false,
|
|
hasMountedEditor: false,
|
|
remountEditor: () => {
|
|
remountCalls += 1
|
|
},
|
|
})
|
|
|
|
expect(changed).toBe(true)
|
|
expect(remountCalls).toBe(0)
|
|
})
|
|
})
|
|
|