Files
Docwell/Server/internal/directory/content_test.go
T
tajniak81andClaude Opus 5.5 abf55a426b Edit page content with the Docwell editor
PageView now mounts @docwell/editor and autosaves the document through
GET/PUT /api/v1/pages/{id}/content. The server stores Tiptap JSON in
pages.content_json and derives content_text and word_count itself.
Saves are last-write-wins until the collab relay replaces them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 11:24:36 +01:00

37 lines
1.1 KiB
Go

package directory
import (
"encoding/json"
"testing"
)
func TestPlainText(t *testing.T) {
raw := `{"type":"doc","content":[
{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Release notes"}]},
{"type":"paragraph","content":[{"type":"text","text":"Fixed "},{"type":"text","marks":[{"type":"bold"}],"text":"two"},{"type":"text","text":" bugs."}]},
{"type":"bulletList","content":[
{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"one"}]}]},
{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"line"},{"type":"hardBreak"},{"type":"text","text":"break"}]}]}
]},
{"type":"paragraph"}
]}`
var doc docNode
if err := json.Unmarshal([]byte(raw), &doc); err != nil {
t.Fatal(err)
}
got := doc.plainText()
want := "Release notes\nFixed two bugs.\none\nline\nbreak"
if got != want {
t.Fatalf("plainText = %q, want %q", got, want)
}
if n := wordCount(got); n != 8 {
t.Fatalf("wordCount = %d, want 8", n)
}
}
func TestPlainTextEmpty(t *testing.T) {
if got := (docNode{Type: "doc"}).plainText(); got != "" {
t.Fatalf("empty doc = %q", got)
}
}