forked from Team254/cheesy-arena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_lower_thirds_test.go
68 lines (57 loc) · 2.31 KB
/
setup_lower_thirds_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
// Copyright 2014 Team 254. All Rights Reserved.
// Author: [email protected] (Patrick Fairbank)
package main
import (
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"sync"
"testing"
"time"
)
func TestSetupLowerThirds(t *testing.T) {
clearDb()
defer clearDb()
var err error
db, err = OpenDatabase(testDbPath)
assert.Nil(t, err)
defer db.Close()
eventSettings, _ = db.GetEventSettings()
mainArena.Setup()
db.CreateLowerThird(&LowerThird{0, "Top Text 1", "Bottom Text 1", 0})
db.CreateLowerThird(&LowerThird{0, "Top Text 2", "Bottom Text 2", 1})
db.CreateLowerThird(&LowerThird{0, "Top Text 3", "Bottom Text 3", 2})
recorder := getHttpResponse("/setup/lower_thirds")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "Top Text 1")
assert.Contains(t, recorder.Body.String(), "Bottom Text 2")
server, wsUrl := startTestServer()
defer server.Close()
conn, _, err := websocket.DefaultDialer.Dial(wsUrl+"/setup/lower_thirds/websocket", nil)
assert.Nil(t, err)
defer conn.Close()
ws := &Websocket{conn, new(sync.Mutex)}
ws.Write("saveLowerThird", LowerThird{1, "Top Text 4", "Bottom Text 1", 0})
time.Sleep(time.Millisecond * 10) // Allow some time for the command to be processed.
lowerThird, _ := db.GetLowerThirdById(1)
assert.Equal(t, "Top Text 4", lowerThird.TopText)
ws.Write("deleteLowerThird", LowerThird{1, "Top Text 4", "Bottom Text 1", 0})
time.Sleep(time.Millisecond * 10)
lowerThird, _ = db.GetLowerThirdById(1)
assert.Nil(t, lowerThird)
assert.Equal(t, "blank", mainArena.audienceDisplayScreen)
ws.Write("showLowerThird", LowerThird{2, "Top Text 5", "Bottom Text 1", 0})
time.Sleep(time.Millisecond * 10)
lowerThird, _ = db.GetLowerThirdById(2)
assert.Equal(t, "Top Text 5", lowerThird.TopText)
assert.Equal(t, "lowerThird", mainArena.audienceDisplayScreen)
ws.Write("hideLowerThird", LowerThird{2, "Top Text 6", "Bottom Text 1", 0})
time.Sleep(time.Millisecond * 10)
lowerThird, _ = db.GetLowerThirdById(2)
assert.Equal(t, "Top Text 6", lowerThird.TopText)
assert.Equal(t, "blank", mainArena.audienceDisplayScreen)
ws.Write("reorderLowerThird", map[string]interface{}{"Id": 2, "moveUp": false})
time.Sleep(time.Millisecond * 100)
lowerThirds, _ := db.GetAllLowerThirds()
assert.Equal(t, 3, lowerThirds[0].Id)
assert.Equal(t, 2, lowerThirds[1].Id)
}