-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnote_test.go
68 lines (54 loc) · 1.43 KB
/
note_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"testing"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/test"
"github.com/stretchr/testify/assert"
)
func testlist() *notelist {
a := test.NewApp()
n := ¬elist{pref: a.Preferences()}
return n
}
func TestNoteTitle(t *testing.T) {
str := "Some content"
n := ¬e{binding.BindString(&str), binding.NewBool()}
title, _ := n.title().Get()
assert.Equal(t, str, title)
n.content.Set("line1\nline2")
title, _ = n.title().Get()
assert.Equal(t, "line1", title)
n.content.Set("")
title, _ = n.title().Get()
assert.Equal(t, "Untitled", title)
}
func TestNoteListAdd(t *testing.T) {
notes := testlist()
notes.add()
assert.Equal(t, 1, len(notes.all))
}
func TestNoteListRemove(t *testing.T) {
str1 := "remove me"
str2 := "remove me2"
first := ¬e{content: binding.BindString(&str1), deleted: binding.NewBool()}
second := ¬e{content: binding.BindString(&str2), deleted: binding.NewBool()}
notes := testlist()
notes.all = []*note{first, second}
assert.Equal(t, 2, len(notes.notes()))
notes.delete(first)
assert.Equal(t, 1, len(notes.notes()))
notes.delete(second)
assert.Equal(t, 0, len(notes.notes()))
}
func TestNoteListLoad(t *testing.T) {
l := testlist()
n := l.add()
defer l.delete(n)
n.content.Set("Test")
l.save()
// get a new one
l.load() // load fresh from preferences
assert.Equal(t, 1, len(l.all))
str, _ := l.all[0].content.Get()
assert.Equal(t, "Test", str) // same content
}