39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { serializeEditorDocumentToMarkdown, syncActiveTabIntoRawBuffer } from './editorRawModeSync'
|
|
|
|
function imageEditor(markdown: string) {
|
|
return {
|
|
document: [{ id: 'image-1', type: 'image', props: {}, children: [] }],
|
|
blocksToMarkdownLossy: vi.fn(() => markdown),
|
|
}
|
|
}
|
|
|
|
describe('editorRawModeSync image paths', () => {
|
|
it('serializes vault-local image assets relative to the active note directory', () => {
|
|
const editor = imageEditor('\n')
|
|
|
|
expect(serializeEditorDocumentToMarkdown(
|
|
editor as never,
|
|
'---\ntitle: Project Plan\n---\n',
|
|
'/vault',
|
|
'/vault/projects/notes/plan.md',
|
|
)).toBe('---\ntitle: Project Plan\n---\n\n')
|
|
})
|
|
|
|
it('uses activeTabPath when syncing rich editor images into raw mode', () => {
|
|
const rawLatestContentRef = { current: null as string | null }
|
|
const editor = imageEditor('\n')
|
|
|
|
const synced = syncActiveTabIntoRawBuffer({
|
|
editor: editor as never,
|
|
activeTabPath: '/vault/projects/notes/plan.md',
|
|
activeTabContent: '---\ntitle: Project Plan\n---\n\n\n',
|
|
rawLatestContentRef,
|
|
vaultPath: '/vault',
|
|
})
|
|
|
|
expect(synced).toBe('---\ntitle: Project Plan\n---\n\n')
|
|
expect(rawLatestContentRef.current).toBe(synced)
|
|
})
|
|
})
|