Files
upstream-tiptap/packages/markdown/tests/integration/empty-content.test.ts
upstream-mirror 083a46e93b
Some checks failed
Verify / Install node dependencies (push) Failing after 2s
Verify / Build packages (push) Has been skipped
Verify / Check linting & formatting (push) Has been skipped
Verify / Run unit tests (push) Has been skipped
Verify / Run e2e tests (shard 1/4) (push) Has been skipped
Verify / Run e2e tests (shard 2/4) (push) Has been skipped
Verify / Run e2e tests (shard 3/4) (push) Has been skipped
Verify / Run e2e tests (shard 4/4) (push) Has been skipped
Publish / Resolve publish config (push) Failing after 2s
Publish / Send notification to Slack (push) Has been skipped
Publish / Send failure notification to Slack (push) Failing after 8s
Verify / Merge e2e reports (push) Has been skipped
Publish / Build (push) Has been skipped
Publish / Bump Versions OR Release to Registry (push) Has been skipped
snapshot of https://github.com/ueberdosis/tiptap.git (main, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:11:02 +05:00

89 lines
2.8 KiB
TypeScript

import { Editor } from '@tiptap/core'
import { Bold } from '@tiptap/extension-bold'
import { Document } from '@tiptap/extension-document'
import { Paragraph } from '@tiptap/extension-paragraph'
import { Text } from '@tiptap/extension-text'
import { Markdown } from '@tiptap/markdown'
import { afterEach, describe, expect, it } from 'vite-plus/test'
describe('empty markdown content', () => {
let editor: Editor
afterEach(() => {
editor?.destroy()
})
it('should create a valid document when initial content is an empty string', () => {
editor = new Editor({
extensions: [Document, Paragraph, Text, Markdown],
content: '',
contentType: 'markdown',
})
const json = editor.getJSON()
expect(json.type).toBe('doc')
expect(json.content).toBeDefined()
expect(json.content).toHaveLength(1)
expect(json.content![0].type).toBe('paragraph')
})
it('should allow inserting text after initialization with empty markdown content', () => {
editor = new Editor({
extensions: [Document, Paragraph, Text, Markdown],
content: '',
contentType: 'markdown',
})
editor.commands.insertContent('Hello')
const json = editor.getJSON()
expect((json.content![0].content![0] as any).text).toBe('Hello')
})
it('should allow inserting text with a paragraph command after initialization with empty markdown content', () => {
editor = new Editor({
extensions: [Document, Paragraph, Text, Markdown],
content: '',
contentType: 'markdown',
})
editor.commands.insertContentAt(0, { type: 'text', text: 'Hello' })
const json = editor.getJSON()
expect((json.content![0].content![0] as any).text).toBe('Hello')
})
it('should allow inserting markdown-formatted content after initialization with empty markdown content', () => {
editor = new Editor({
extensions: [Document, Paragraph, Text, Bold, Markdown],
content: '',
contentType: 'markdown',
})
editor.commands.insertContent('**bold**', { contentType: 'markdown' })
const json = editor.getJSON()
const textNode = json.content![0].content![0] as any
expect(textNode.type).toBe('text')
expect(textNode.text).toBe('bold')
expect(textNode.marks?.[0]?.type).toBe('bold')
})
it('should allow inserting markdown-formatted content at a specific position after empty initialization', () => {
editor = new Editor({
extensions: [Document, Paragraph, Text, Bold, Markdown],
content: '',
contentType: 'markdown',
})
editor.commands.insertContentAt(0, '**bold**', { contentType: 'markdown' })
const json = editor.getJSON()
const textNode = json.content![0].content![0] as any
expect(textNode.type).toBe('text')
expect(textNode.text).toBe('bold')
expect(textNode.marks?.[0]?.type).toBe('bold')
})
})