github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/model/note/note_test.go (about) 1 package note 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/cozy/prosemirror-go/model" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestMarkdown(t *testing.T) { 13 initial := `# My title 14 15 foobar **bold** 16 17 :info: this is a panel 18 19 ✍ this is a decision 20 ✍ and another decision 21 22 - [ ] a todo task 23 24 - [X] a done task` 25 26 schemaSpecs := DefaultSchemaSpecs() 27 specs := model.SchemaSpecFromJSON(schemaSpecs) 28 schema, err := model.NewSchema(&specs) 29 require.NoError(t, err) 30 31 node, err := parseFile(strings.NewReader(initial), schema) 32 require.NoError(t, err) 33 34 md := markdownSerializer(nil).Serialize(node) 35 assert.Equal(t, initial, md) 36 } 37 38 func TestText(t *testing.T) { 39 initial := `# My title 40 41 hello **world** 42 43 - foo 44 - bar 45 - baz 46 47 ✍ This is a decision 48 ✍ and another decision 49 50 - [ ] A todo task 51 - [X] a done task` 52 53 expected := `My title 54 55 hello world 56 57 - foo 58 59 - bar 60 61 - baz 62 63 This is a decision 64 65 and another decision 66 67 - A todo task 68 69 - a done task` 70 71 schemaSpecs := DefaultSchemaSpecs() 72 specs := model.SchemaSpecFromJSON(schemaSpecs) 73 schema, err := model.NewSchema(&specs) 74 require.NoError(t, err) 75 76 node, err := parseFile(strings.NewReader(initial), schema) 77 require.NoError(t, err) 78 79 md := textSerializer().Serialize(node) 80 assert.Equal(t, expected, md) 81 }