A relation column can now mirror a relation of the related database (relation.back). The mirror stores no links: it lists the records whose relation links to each row, so both sides always agree. - "Show on … too" in a relation's Related database menu adds the mirror to a database on the same page in one step. - Pointing a relation at a database whose relation already links back offers to mirror it, across pages too. - Editing a mirror cell changes the stored side when it is on the same page; a mirror of another page's relation is read-only and says where to change the links. - Filters, sorts and rollups read mirrors like other relations; paste and delete skip them. - docwell-server's exports work out same-page mirrors. Strings are translated into all five languages, the user guide covers the feature, and the mobile editor bundle is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
4.9 KiB
Go
123 lines
4.9 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])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRelationsAndRollupsExport(t *testing.T) {
|
|
doc, err := Parse([]byte(`{"type":"doc","content":[
|
|
{"type":"database","attrs":{"id":"p","data":{"title":"Projects",
|
|
"columns":[{"id":"t","name":"Name","type":"title"},
|
|
{"id":"rel","name":"Tasks","type":"relation","relation":{"page":"","database":"k"}},
|
|
{"id":"n","name":"Hours","type":"rollup","rollup":{"relation":"rel","property":"h","fn":"sum"}},
|
|
{"id":"d","name":"Done","type":"rollup","rollup":{"relation":"rel","property":"c","fn":"percentChecked"}},
|
|
{"id":"far","name":"Elsewhere","type":"relation","relation":{"page":"other","database":"x"}}],
|
|
"rows":[{"id":"p1","cells":{"t":"Launch","rel":["k1","k2","gone"],"far":["a","b"]}}],
|
|
"views":[{"id":"v","type":"table"}]}}},
|
|
{"type":"database","attrs":{"id":"k","data":{"title":"Tasks",
|
|
"columns":[{"id":"t","name":"Name","type":"title"},{"id":"h","name":"Hours","type":"number"},{"id":"c","name":"Done","type":"checkbox"}],
|
|
"rows":[{"id":"k1","cells":{"t":"Write","h":2.5,"c":true}},{"id":"k2","cells":{"t":"Ship","h":4}}],
|
|
"views":[{"id":"v","type":"table"}]}}}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
md := Markdown(doc, Options{})
|
|
if want := "| Launch | Write, Ship | 6.5 | 50% | 2 linked |"; !strings.Contains(md, want) {
|
|
t.Errorf("markdown lacks %q:\n%s", want, md)
|
|
}
|
|
}
|
|
|
|
func TestTwoWayRelationExport(t *testing.T) {
|
|
doc, err := Parse([]byte(`{"type":"doc","content":[
|
|
{"type":"database","attrs":{"id":"p","data":{"title":"Projects",
|
|
"columns":[{"id":"t","name":"Name","type":"title"},
|
|
{"id":"rel","name":"Tasks","type":"relation","relation":{"page":"","database":"k"}}],
|
|
"rows":[{"id":"p1","cells":{"t":"Launch","rel":["k1","k2"]}},{"id":"p2","cells":{"t":"Docs","rel":["k2"]}}],
|
|
"views":[{"id":"v","type":"table"}]}}},
|
|
{"type":"database","attrs":{"id":"k","data":{"title":"Tasks",
|
|
"columns":[{"id":"t","name":"Name","type":"title"},
|
|
{"id":"back","name":"Projects","type":"relation","relation":{"page":"","database":"p","back":"rel"}},
|
|
{"id":"n","name":"Count","type":"rollup","rollup":{"relation":"back","property":"","fn":"count"}}],
|
|
"rows":[{"id":"k1","cells":{"t":"Write","back":["stale"]}},{"id":"k2","cells":{"t":"Ship"}},{"id":"k3","cells":{"t":"Idle"}}],
|
|
"views":[{"id":"v","type":"table"}]}}}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
md := Markdown(doc, Options{})
|
|
for _, want := range []string{"| Write | Launch | 1 |", "| Ship | Launch, Docs | 2 |", "| Idle | | 0 |"} {
|
|
if !strings.Contains(md, want) {
|
|
t.Errorf("markdown lacks %q:\n%s", want, md)
|
|
}
|
|
}
|
|
}
|