Files
Docwell/Server/internal/convert/database_test.go
T
tajniak81andClaude Opus 5.5 406779b353 Open record links on public pages and find records in search
- Public pages follow "#b-…" and "#r-…" links like the page view does,
  and their block and record links copy the public address. The retry
  logic is shared as followLink (Packages/editor/src/hashlinks.ts).
- Search indexes each database record as its own document (from the
  page's content_json), returned with a "record" field and opened beside
  its page. Filter-only listings stay pages only; removed records and
  trashed pages drop out. The index mapping version is bumped, so it
  rebuilds once.
- Phone app: search lists records and opens them through a new
  "follow" bridge message.
- Guide updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:50:51 +01:00

76 lines
2.4 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package convert
import (
"strings"
"testing"
)
func TestDatabaseExportsAsTable(t *testing.T) {
doc, err := Parse([]byte(`{"type":"doc","content":[{"type":"callout","content":[{"type":"database","attrs":{"id":"d","data":{
"title":"Tasks",
"columns":[
{"id":"t","name":"Name","type":"title"},
{"id":"s","name":"Status","type":"select","options":[{"id":"o","name":"Doing","color":"blue"}]},
{"id":"m","name":"Tags","type":"multiSelect","options":[{"id":"a","name":"red"},{"id":"b","name":"blue"}]},
{"id":"c","name":"Done","type":"checkbox"},
{"id":"h","name":"Secret","type":"text"}
],
"rows":[
{"id":"r1","createdAt":1,"cells":{"t":"Write","s":"o","m":["a","b"],"c":true,"h":"x"}},
{"id":"r2","createdAt":2,"cells":{"t":"Ship"}}
],
"views":[{"id":"v","type":"table","hidden":["h"]}]
}}}]}]}`))
if err != nil {
t.Fatal(err)
}
md := Markdown(doc, Options{})
for _, want := range []string{"**Tasks**", "| Name | Status | Tags | Done |", "| Write | Doing | red, blue | ✓ |", "| Ship |"} {
if !strings.Contains(md, want) {
t.Errorf("markdown lacks %q:\n%s", want, md)
}
}
if strings.Contains(md, "Secret") {
t.Errorf("hidden column exported:\n%s", md)
}
h := HTML(doc, Options{})
if !strings.Contains(h, "<th>") || !strings.Contains(h, "Doing") {
t.Errorf("html lacks the table:\n%s", h)
}
if _, err := DOCX("T", doc, DOCXOptions{}); err != nil {
t.Fatal(err)
}
if _, err := PDF("T", doc, PDFOptions{}); err != nil {
t.Fatal(err)
}
}
func TestRecordsForSearch(t *testing.T) {
recs, err := Records([]byte(`{"type":"doc","content":[{"type":"callout","content":[{"type":"database","attrs":{"id":"d","data":{
"columns":[
{"id":"t","name":"Name","type":"title"},
{"id":"s","name":"Status","type":"select","options":[{"id":"o","name":"Doing"}]},
{"id":"c","name":"Done","type":"checkbox"}
],
"rows":[
{"id":"r1","cells":{"t":"Write","s":"o","c":true},"body":[{"type":"paragraph","content":[{"type":"text","text":"draft first"}]}]},
{"id":"r2","cells":{}},
{"cells":{"t":"no id"}}
]
}}}]}]}`))
if err != nil {
t.Fatal(err)
}
want := []Record{{Database: "d", Row: "r1", Title: "Write", Text: "Doing draft first"}, {Database: "d", Row: "r2"}}
if len(recs) != len(want) {
t.Fatalf("records = %+v", recs)
}
for i := range want {
if recs[i] != want[i] {
t.Errorf("record %d = %+v, want %+v", i, recs[i], want[i])
}
}
}