Files
Docwell/Server/internal/directory/notify_test.go
T
tajniak81andClaude Opus 5.5 53dd43cc2e Add synced pages, editor settings and split view
Phase B items 7-9 of docs/AFFINE.md.

Synced pages: "![[" or /Synced page shows another page inside this one,
read-only and live. The copy follows the page over a read-only collab
connection (CollabProvider readOnly: no edits, no presence) in a nested
read-only editor; it folds to its title and opens the page. The node
keeps the page's title, so exports (Markdown, HTML, PDF, Word) and
readers without a host show it as a link to the page.

Settings: Account -> Editor sets, per device, the text size, full width
or a date title for new pages, showing properties and backlinks, and
code line numbers. The inbox settings choose which notification types
the email digest includes (users.notify_email_off, new migration).

Split view: Alt+click a page link, or Open beside in the page menu,
shows that page in a side pane on wide screens; it survives navigation
and reloads of the tab. The page menu opens pages in a new tab on the
web, and Ctrl+[ / Ctrl+] go back and forward.

Strings are translated into all five languages, the user guide covers
the new features, and the mobile editor bundle is rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 19:23:30 +01:00

81 lines
2.6 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package directory
import (
"strings"
"testing"
)
func TestMentionIDs(t *testing.T) {
doc := `{"type":"doc","content":[
{"type":"paragraph","content":[
{"type":"text","text":"hi "},
{"type":"mention","attrs":{"id":"bbbbbbbbbbbbbbb","label":"Bob"}},
{"type":"mention","attrs":{"id":"aaaaaaaaaaaaaaa","label":"Ann"}}]},
{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[
{"type":"mention","attrs":{"id":"bbbbbbbbbbbbbbb"}},
{"type":"mention","attrs":{"id":"bad id!"}}]}]}]}]}`
got := strings.Join(mentionIDs([]byte(doc)), ",")
if got != "aaaaaaaaaaaaaaa,bbbbbbbbbbbbbbb" {
t.Fatalf("mentionIDs = %q", got)
}
if mentionIDs([]byte("null")) != nil || mentionIDs([]byte("{")) != nil {
t.Fatal("empty documents should have no mentions")
}
}
func TestValidEmoji(t *testing.T) {
for _, e := range []string{"👍", "❤️", "🎉", "👩‍💻"} {
if !validEmoji(e) {
t.Errorf("%q should be accepted", e)
}
}
for _, e := range []string{"", "ok", "a b", "1", "👍👍👍👍👍👍👍👍👍", "\n"} {
if validEmoji(e) {
t.Errorf("%q should be refused", e)
}
}
}
func TestExcerpt(t *testing.T) {
if got := excerpt(" a\n\n b "); got != "a b" {
t.Fatalf("excerpt = %q", got)
}
if got := []rune(excerpt(strings.Repeat("x", 300))); len(got) != 200 || got[199] != '…' {
t.Fatalf("long excerpt has %d runes", len(got))
}
}
func TestLinkIDs(t *testing.T) {
link := func(href string) string {
return `{"type":"text","text":"x","marks":[{"type":"bold"},{"type":"link","attrs":{"href":"` + href + `"}}]}`
}
doc := `{"type":"doc","content":[{"type":"paragraph","content":[` + strings.Join([]string{
link("/p/bbbbbbbbbbbbbbb"),
link("https://docs.example.com/p/aaaaaaaaaaaaaaa?comment=x"),
link("/p/selfselfselfse"),
link("/p/bbbbbbbbbbbbbbb"),
link("https://example.com/other"),
link("/p/bad id"),
}, ",") + `]}]}`
got := strings.Join(linkIDs([]byte(doc), "selfselfselfse"), ",")
if got != "aaaaaaaaaaaaaaa,bbbbbbbbbbbbbbb" {
t.Fatalf("linkIDs = %q", got)
}
if ids := linkIDs([]byte("null"), "x"); ids == nil || len(ids) != 0 {
t.Fatalf("empty document should give an empty list, got %v", ids)
}
}
func TestEmailTypesLeaveOutTheOnesTurnedOff(t *testing.T) {
got := emailTypes([]string{"comment", "share"})
want := []string{"mention", "reply", "resolved", "reminder"}
if strings.Join(got, ",") != strings.Join(want, ",") {
t.Errorf("emailTypes = %v, want %v", got, want)
}
if len(emailTypes(nil)) != len(notificationTypes) {
t.Error("nothing turned off should email every type")
}
}