Add document tests

This commit is contained in:
mcrakhman authored and Mikhail Iudin committed 2022-07-12 23:07:05 +02:00
1 parent acc2699b0e
commit c5fbe7e56b
4 files changed
+73 -66

No files matched your search

+4 -1
View File
@@ -23,7 +23,10 @@ type plainTextDocument struct {
}
func (p *plainTextDocument) Text() string {
return p.state.Text
if p.state != nil {
return p.state.Text
}
return ""
}
func (p *plainTextDocument) AddText(text string) error {
+46 -51
View File
@@ -1,53 +1,48 @@
package plaintextdocument
//
//import (
// "github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
// "github.com/stretchr/testify/assert"
// "testing"
//)
//
//func TestDocument_Build(t *testing.T) {
// thread, err := threadbuilder.NewThreadBuilderWithTestName("threadbuilder/userjoinexample.yml")
// if err != nil {
// t.Fatal(err)
// }
// keychain := thread.GetKeychain()
// accountData := &AccountData{
// Identity: keychain.GetIdentity("A"),
// EncKey: keychain.EncryptionKeys["A"],
// }
// doc := NewDocument(thread, NewPlainTextDocumentStateProvider(), accountData)
// res, err := doc.Build()
// if err != nil {
// t.Fatal(err)
// }
//
// st := res.(*DocumentState)
// assert.Equal(t, st.Text, "some text|first")
//}
//
//func TestDocument_Update(t *testing.T) {
// thread, err := threadbuilder.NewThreadBuilderWithTestName("threadbuilder/userjoinexample.yml")
// if err != nil {
// t.Fatal(err)
// }
// keychain := thread.GetKeychain()
// accountData := &AccountData{
// Identity: keychain.GetIdentity("A"),
// EncKey: keychain.EncryptionKeys["A"],
// }
// doc := NewDocument(thread, NewPlainTextDocumentStateProvider(), accountData)
// res, err := doc.Build()
// if err != nil {
// t.Fatal(err)
// }
//
// st := res.(*DocumentState)
// assert.Equal(t, st.Text, "some text|first")
//
// rawChs := thread.GetUpdatedChanges()
// res, updateResult, err := doc.Update(rawChs...)
// assert.Equal(t, updateResult, UpdateResultAppend)
// assert.Equal(t, res.(*DocumentState).Text, "some text|first|second")
//}
import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/account"
"github.com/anytypeio/go-anytype-infrastructure-experiments/testutils/threadbuilder"
"github.com/anytypeio/go-anytype-infrastructure-experiments/thread"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDocument_NewPlainTextDocument(t *testing.T) {
keychain := threadbuilder.NewKeychain()
keychain.AddSigningKey("A")
keychain.AddEncryptionKey("A")
data := &account.AccountData{
Identity: keychain.GetIdentity("A"),
SignKey: keychain.SigningKeys["A"],
EncKey: keychain.EncryptionKeys["A"],
}
doc, err := NewPlainTextDocument(data, thread.NewInMemoryThread, "Some text")
if err != nil {
t.Fatalf("should not create document with error: %v", err)
}
assert.Equal(t, doc.Text(), "Some text")
}
func TestDocument_PlainTextDocument_AddText(t *testing.T) {
keychain := threadbuilder.NewKeychain()
keychain.AddSigningKey("A")
keychain.AddEncryptionKey("A")
data := &account.AccountData{
Identity: keychain.GetIdentity("A"),
SignKey: keychain.SigningKeys["A"],
EncKey: keychain.EncryptionKeys["A"],
}
doc, err := NewPlainTextDocument(data, thread.NewInMemoryThread, "Some text")
if err != nil {
t.Fatalf("should not create document with error: %v", err)
}
err = doc.AddText("Next")
if err != nil {
t.Fatalf("should be able to add document: %v", err)
}
assert.Equal(t, doc.Text(), "Some text|Next")
}