Skip to content

Commit

Permalink
Make attributes display properly in dashboard and add additional unit…
Browse files Browse the repository at this point in the history
… tests

Attributes should be displayed in dashboad JSON format data, and, because we fixed the JSON display for when attributes are added, we should write additional unit tests for them.
  • Loading branch information
YoonKiJin committed Jun 30, 2023
1 parent abf17ac commit a2998fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/document/crdt/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,14 @@ func marshal(builder *strings.Builder, node *TreeNode) {
}
marshal(builder, child.Value)
}
builder.WriteString(`]}`)
builder.WriteString(`]`)

if node.Attrs != nil && node.Attrs.Len() > 0 {
builder.WriteString(fmt.Sprintf(`,"attributes":`))
builder.WriteString(node.Attrs.Marshal())
}

builder.WriteString(`}`)
}

// DeepCopy copies itself deeply.
Expand Down
3 changes: 3 additions & 0 deletions test/integration/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ func TestTree(t *testing.T) {

assert.Equal(t, `<root><p bold="true">ab</p><p italic="true">cd</p></root>`, d1.Root().GetTree("t").ToXML())
assert.Equal(t, `<root><p bold="true">ab</p><p italic="true">cd</p></root>`, d2.Root().GetTree("t").ToXML())

assert.Equal(t, `{"type":"root","children":[{"type":"p","children":[{"type":"text","value":"ab"}],"attributes":{"bold":"true"}},{"type":"p","children":[{"type":"text","value":"cd"}],"attributes":{"italic":"true"}}]}`, d1.Root().GetTree("t").Marshal())
assert.Equal(t, `{"type":"root","children":[{"type":"p","children":[{"type":"text","value":"ab"}],"attributes":{"bold":"true"}},{"type":"p","children":[{"type":"text","value":"cd"}],"attributes":{"italic":"true"}}]}`, d2.Root().GetTree("t").Marshal())
})

t.Run("insert inline content to the same position(left) concurrently test", func(t *testing.T) {
Expand Down

0 comments on commit a2998fa

Please sign in to comment.