34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { describe, it } from "node:test"
|
|
import { ensureMinimalTipTapDoc, isEmptyTipTapDoc } from "./richtext-content.ts"
|
|
|
|
describe("richtext-content", () => {
|
|
it("detects empty TipTap documents", () => {
|
|
assert.equal(isEmptyTipTapDoc(undefined), true)
|
|
assert.equal(
|
|
isEmptyTipTapDoc({ type: "doc", content: [{ type: "paragraph" }] }),
|
|
true
|
|
)
|
|
assert.equal(
|
|
isEmptyTipTapDoc({
|
|
type: "doc",
|
|
content: [{ type: "paragraph", content: [{ type: "text", text: "Hello" }] }],
|
|
}),
|
|
false
|
|
)
|
|
})
|
|
|
|
it("ensureMinimalTipTapDoc fills missing blocks", () => {
|
|
assert.deepEqual(ensureMinimalTipTapDoc(undefined), {
|
|
type: "doc",
|
|
content: [{ type: "paragraph" }],
|
|
})
|
|
assert.deepEqual(ensureMinimalTipTapDoc({ type: "doc", content: [] }), {
|
|
type: "doc",
|
|
content: [{ type: "paragraph" }],
|
|
})
|
|
const existing = { type: "doc", content: [{ type: "paragraph" }] }
|
|
assert.equal(ensureMinimalTipTapDoc(existing), existing)
|
|
})
|
|
})
|