-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimer_test.go
84 lines (81 loc) · 2.21 KB
/
timer_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package i3status_test
import (
"github.com/ghedamat/go-i3status/i3status"
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func TestTimerWidgetConstructor(t *testing.T) {
Convey("Given two channels", t, func() {
c := make(chan i3status.Message)
i := make(chan i3status.Entry)
Convey("When timer is created", func() {
w := i3status.NewTimerWidget()
w.SetChannels(c, i)
Convey("output channel is available", func() {
So(w.Output, ShouldEqual, c)
})
})
})
}
func TestTimerWidgetStartEvent(t *testing.T) {
Convey("Given A timer widget", t, func() {
c := make(chan i3status.Message)
i := make(chan i3status.Entry)
w := i3status.NewTimerWidget()
w.SetChannels(c, i)
w.Start()
Convey("When a left click event is received", func() {
msg := <-c
i <- i3status.Entry{"Timer", "0", 1, 0, 0}
time.Sleep(1)
Convey("timer status is started", func() {
So(w.Status, ShouldContainSubstring, "started")
msg = <-c
So(msg.FullText, ShouldContainSubstring, "started")
})
})
})
}
func TestTimerWidgetPauseEvent(t *testing.T) {
Convey("Given A timer widget", t, func() {
c := make(chan i3status.Message)
i := make(chan i3status.Entry)
w := i3status.NewTimerWidget()
w.SetChannels(c, i)
w.Start()
Convey("When a second left click event is received", func() {
msg := <-c
i <- i3status.Entry{"Timer", "0", 1, 0, 0}
msg = <-c
i <- i3status.Entry{"Timer", "0", 1, 0, 0}
time.Sleep(1)
Convey("timer status is paused", func() {
msg = <-c
So(w.Status, ShouldContainSubstring, "paused")
So(msg.FullText, ShouldContainSubstring, "paused")
})
})
})
}
func TestTimerWidgetStopEvent(t *testing.T) {
Convey("Given A timer widget", t, func() {
c := make(chan i3status.Message)
i := make(chan i3status.Entry)
w := i3status.NewTimerWidget()
w.SetChannels(c, i)
w.Start()
Convey("When a right click event is received", func() {
msg := <-c
i <- i3status.Entry{"Timer", "0", 1, 0, 0}
msg = <-c
i <- i3status.Entry{"Timer", "0", 3, 0, 0}
time.Sleep(1)
Convey("timer status is stopped", func() {
msg = <-c
So(w.Status, ShouldContainSubstring, "stopped")
So(msg.FullText, ShouldContainSubstring, "stopped")
})
})
})
}