MCPcopy
hub / github.com/dnote/dnote / TestListNotes

Function TestListNotes

pkg/cli/cmd/view/book_test.go:125–152  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

123}
124
125func TestListNotes(t *testing.T) {
126 // Setup
127 db := database.InitTestMemoryDB(t)
128 defer db.Close()
129
130 bookUUID := "js-book-uuid"
131 database.MustExec(t, "inserting book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", bookUUID, "javascript")
132 database.MustExec(t, "inserting note 1", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-1", bookUUID, "first note", 1515199943)
133 database.MustExec(t, "inserting note 2", db, "INSERT INTO notes (uuid, book_uuid, body, added_on) VALUES (?, ?, ?, ?)", "note-2", bookUUID, "multiline note\nwith second line", 1515199945)
134
135 ctx := context.DnoteCtx{DB: db}
136 var buf bytes.Buffer
137
138 // Execute
139 err := listNotes(ctx, &buf, "javascript")
140 if err != nil {
141 t.Fatal(err)
142 }
143
144 got := buf.String()
145
146 // Verify output
147 assert.Equal(t, strings.Contains(got, "on book javascript"), true, "should show book name")
148 assert.Equal(t, strings.Contains(got, "first note"), true, "should contain first note")
149 assert.Equal(t, strings.Contains(got, "multiline note"), true, "should show first line of multiline note")
150 assert.Equal(t, strings.Contains(got, "[---More---]"), true, "should show more indicator for multiline note")
151 assert.Equal(t, strings.Contains(got, "with second line"), false, "should not show second line of multiline note")
152}
153
154func TestListBooks(t *testing.T) {
155 // Setup

Callers

nothing calls this directly

Calls 5

InitTestMemoryDBFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
listNotesFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected