2014-09-04 21:11:05 -07:00
|
|
|
// Copyright 2014 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
|
2017-08-31 23:26:22 -07:00
|
|
|
package web
|
2014-09-04 21:11:05 -07:00
|
|
|
|
|
|
|
|
import (
|
2021-05-16 11:00:29 -07:00
|
|
|
"github.com/Team254/cheesy-arena-lite/model"
|
|
|
|
|
"github.com/Team254/cheesy-arena-lite/websocket"
|
2018-08-31 22:40:08 -07:00
|
|
|
gorillawebsocket "github.com/gorilla/websocket"
|
2014-09-04 21:11:05 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"testing"
|
2015-08-22 18:27:31 -07:00
|
|
|
"time"
|
2014-09-04 21:11:05 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSetupLowerThirds(t *testing.T) {
|
2017-08-28 20:14:32 -07:00
|
|
|
web := setupTestWeb(t)
|
2014-09-04 21:11:05 -07:00
|
|
|
|
2019-08-09 23:13:45 -07:00
|
|
|
web.arena.Database.CreateLowerThird(&model.LowerThird{0, "Top Text 1", "Bottom Text 1", 0, 0})
|
|
|
|
|
web.arena.Database.CreateLowerThird(&model.LowerThird{0, "Top Text 2", "Bottom Text 2", 1, 0})
|
|
|
|
|
web.arena.Database.CreateLowerThird(&model.LowerThird{0, "Top Text 3", "Bottom Text 3", 2, 0})
|
2014-09-04 21:11:05 -07:00
|
|
|
|
2017-08-28 20:14:32 -07:00
|
|
|
recorder := web.getHttpResponse("/setup/lower_thirds")
|
2014-09-04 21:11:05 -07:00
|
|
|
assert.Equal(t, 200, recorder.Code)
|
|
|
|
|
assert.Contains(t, recorder.Body.String(), "Top Text 1")
|
|
|
|
|
assert.Contains(t, recorder.Body.String(), "Bottom Text 2")
|
|
|
|
|
|
2017-08-28 20:14:32 -07:00
|
|
|
server, wsUrl := web.startTestServer()
|
2015-08-22 18:27:31 -07:00
|
|
|
defer server.Close()
|
2018-08-31 22:40:08 -07:00
|
|
|
conn, _, err := gorillawebsocket.DefaultDialer.Dial(wsUrl+"/setup/lower_thirds/websocket", nil)
|
2015-08-22 18:27:31 -07:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
defer conn.Close()
|
2018-08-31 22:40:08 -07:00
|
|
|
ws := websocket.NewTestWebsocket(conn)
|
2014-09-04 21:11:05 -07:00
|
|
|
|
2019-08-09 23:13:45 -07:00
|
|
|
ws.Write("saveLowerThird", model.LowerThird{1, "Top Text 4", "Bottom Text 1", 0, 0})
|
2015-08-22 18:27:31 -07:00
|
|
|
time.Sleep(time.Millisecond * 10) // Allow some time for the command to be processed.
|
2017-08-28 20:14:32 -07:00
|
|
|
lowerThird, _ := web.arena.Database.GetLowerThirdById(1)
|
2015-08-22 18:27:31 -07:00
|
|
|
assert.Equal(t, "Top Text 4", lowerThird.TopText)
|
2014-09-04 21:11:05 -07:00
|
|
|
|
2019-08-09 23:13:45 -07:00
|
|
|
ws.Write("deleteLowerThird", model.LowerThird{1, "Top Text 4", "Bottom Text 1", 0, 0})
|
2015-08-22 18:27:31 -07:00
|
|
|
time.Sleep(time.Millisecond * 10)
|
2017-08-28 20:14:32 -07:00
|
|
|
lowerThird, _ = web.arena.Database.GetLowerThirdById(1)
|
2015-08-22 18:27:31 -07:00
|
|
|
assert.Nil(t, lowerThird)
|
|
|
|
|
|
2018-08-31 22:40:08 -07:00
|
|
|
assert.Equal(t, "blank", web.arena.AudienceDisplayMode)
|
2019-08-09 23:13:45 -07:00
|
|
|
ws.Write("showLowerThird", model.LowerThird{2, "Top Text 5", "Bottom Text 1", 0, 0})
|
2015-08-22 18:27:31 -07:00
|
|
|
time.Sleep(time.Millisecond * 10)
|
2017-08-28 20:14:32 -07:00
|
|
|
lowerThird, _ = web.arena.Database.GetLowerThirdById(2)
|
2015-08-22 18:27:31 -07:00
|
|
|
assert.Equal(t, "Top Text 5", lowerThird.TopText)
|
2020-03-28 14:37:26 -07:00
|
|
|
assert.Equal(t, true, web.arena.ShowLowerThird)
|
2015-08-22 18:27:31 -07:00
|
|
|
|
2019-08-09 23:13:45 -07:00
|
|
|
ws.Write("hideLowerThird", model.LowerThird{2, "Top Text 6", "Bottom Text 1", 0, 0})
|
2015-08-22 18:27:31 -07:00
|
|
|
time.Sleep(time.Millisecond * 10)
|
2017-08-28 20:14:32 -07:00
|
|
|
lowerThird, _ = web.arena.Database.GetLowerThirdById(2)
|
2015-08-22 18:27:31 -07:00
|
|
|
assert.Equal(t, "Top Text 6", lowerThird.TopText)
|
2020-03-28 14:37:26 -07:00
|
|
|
assert.Equal(t, false, web.arena.ShowLowerThird)
|
2014-09-04 21:11:05 -07:00
|
|
|
|
2015-08-22 18:27:31 -07:00
|
|
|
ws.Write("reorderLowerThird", map[string]interface{}{"Id": 2, "moveUp": false})
|
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
2017-08-28 20:14:32 -07:00
|
|
|
lowerThirds, _ := web.arena.Database.GetAllLowerThirds()
|
2021-05-12 17:49:05 -07:00
|
|
|
assert.Equal(t, 3, lowerThirds[0].Id)
|
|
|
|
|
assert.Equal(t, 2, lowerThirds[1].Id)
|
2014-09-04 21:11:05 -07:00
|
|
|
}
|