2014-09-06 17:06:06 -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-06 17:06:06 -07:00
|
|
|
|
|
|
|
|
import (
|
2018-04-11 23:26:36 -07:00
|
|
|
"github.com/Team254/cheesy-arena/game"
|
2018-08-31 22:40:08 -07:00
|
|
|
"github.com/Team254/cheesy-arena/websocket"
|
|
|
|
|
gorillawebsocket "github.com/gorilla/websocket"
|
2014-09-06 17:06:06 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAllianceStationDisplay(t *testing.T) {
|
2017-08-28 20:14:32 -07:00
|
|
|
web := setupTestWeb(t)
|
2014-09-06 17:06:06 -07:00
|
|
|
|
2017-08-28 20:14:32 -07:00
|
|
|
recorder := web.getHttpResponse("/displays/alliance_station")
|
2018-09-09 22:42:38 -07:00
|
|
|
assert.Equal(t, 302, recorder.Code)
|
2019-09-14 17:31:36 -07:00
|
|
|
assert.Contains(t, recorder.Header().Get("Location"), "displayId=100")
|
2018-09-09 22:42:38 -07:00
|
|
|
assert.Contains(t, recorder.Header().Get("Location"), "station=R1")
|
|
|
|
|
|
|
|
|
|
recorder = web.getHttpResponse("/displays/alliance_station?displayId=1&station=B1")
|
2014-09-06 17:06:06 -07:00
|
|
|
assert.Equal(t, 200, recorder.Code)
|
|
|
|
|
assert.Contains(t, recorder.Body.String(), "Alliance Station Display - Untitled Event - Cheesy Arena")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAllianceStationDisplayWebsocket(t *testing.T) {
|
2017-08-28 20:14:32 -07:00
|
|
|
web := setupTestWeb(t)
|
2014-09-06 17:06:06 -07:00
|
|
|
|
2017-08-28 20:14:32 -07:00
|
|
|
server, wsUrl := web.startTestServer()
|
2014-09-06 17:06:06 -07:00
|
|
|
defer server.Close()
|
2018-08-31 22:40:08 -07:00
|
|
|
conn, _, err := gorillawebsocket.DefaultDialer.Dial(wsUrl+"/displays/alliance_station/websocket?displayId=1", nil)
|
2014-09-06 17:06:06 -07:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
defer conn.Close()
|
2018-08-31 22:40:08 -07:00
|
|
|
ws := websocket.NewTestWebsocket(conn)
|
2014-09-06 17:06:06 -07:00
|
|
|
|
|
|
|
|
// Should get a few status updates right after connection.
|
2020-03-29 16:55:53 -07:00
|
|
|
readWebsocketType(t, ws, "displayConfiguration")
|
2014-09-06 17:06:06 -07:00
|
|
|
readWebsocketType(t, ws, "matchTiming")
|
2018-08-31 22:40:08 -07:00
|
|
|
readWebsocketType(t, ws, "allianceStationDisplayMode")
|
|
|
|
|
readWebsocketType(t, ws, "arenaStatus")
|
|
|
|
|
readWebsocketType(t, ws, "matchLoad")
|
2014-09-06 17:06:06 -07:00
|
|
|
readWebsocketType(t, ws, "matchTime")
|
|
|
|
|
readWebsocketType(t, ws, "realtimeScore")
|
|
|
|
|
|
|
|
|
|
// Change to a different screen.
|
2018-08-31 22:40:08 -07:00
|
|
|
web.arena.AllianceStationDisplayMode = "logo"
|
|
|
|
|
web.arena.AllianceStationDisplayModeNotifier.Notify()
|
|
|
|
|
readWebsocketType(t, ws, "allianceStationDisplayMode")
|
2014-09-06 17:06:06 -07:00
|
|
|
|
|
|
|
|
// Run through a match cycle.
|
2018-08-31 22:40:08 -07:00
|
|
|
web.arena.MatchLoadNotifier.Notify()
|
|
|
|
|
readWebsocketType(t, ws, "matchLoad")
|
2017-08-28 20:14:32 -07:00
|
|
|
web.arena.AllianceStations["R1"].Bypass = true
|
|
|
|
|
web.arena.AllianceStations["R2"].Bypass = true
|
|
|
|
|
web.arena.AllianceStations["R3"].Bypass = true
|
|
|
|
|
web.arena.AllianceStations["B1"].Bypass = true
|
|
|
|
|
web.arena.AllianceStations["B2"].Bypass = true
|
|
|
|
|
web.arena.AllianceStations["B3"].Bypass = true
|
|
|
|
|
web.arena.StartMatch()
|
|
|
|
|
web.arena.Update()
|
2019-04-12 17:32:40 -07:00
|
|
|
messages := readWebsocketMultiple(t, ws, 3)
|
2018-08-31 22:40:08 -07:00
|
|
|
_, ok := messages["matchTime"]
|
|
|
|
|
assert.True(t, ok)
|
2018-04-11 23:26:36 -07:00
|
|
|
web.arena.MatchStartTime = time.Now().Add(-time.Duration(game.MatchTiming.WarmupDurationSec) * time.Second)
|
|
|
|
|
web.arena.Update()
|
2018-08-31 22:40:08 -07:00
|
|
|
messages = readWebsocketMultiple(t, ws, 2)
|
|
|
|
|
_, ok = messages["arenaStatus"]
|
2014-09-06 17:06:06 -07:00
|
|
|
assert.True(t, ok)
|
|
|
|
|
_, ok = messages["matchTime"]
|
|
|
|
|
assert.True(t, ok)
|
2018-08-31 22:40:08 -07:00
|
|
|
web.arena.RealtimeScoreNotifier.Notify()
|
2014-09-06 17:06:06 -07:00
|
|
|
readWebsocketType(t, ws, "realtimeScore")
|
|
|
|
|
}
|