diff --git a/displays_test.go b/displays_test.go index 793f676..80c7efc 100644 --- a/displays_test.go +++ b/displays_test.go @@ -77,6 +77,12 @@ func TestAudienceDisplayWebsocket(t *testing.T) { readWebsocketType(t, ws, "realtimeScore") mainArena.scorePostedNotifier.Notify(nil) readWebsocketType(t, ws, "setFinalScore") + + // Test other overlays. + mainArena.allianceSelectionNotifier.Notify(nil) + readWebsocketType(t, ws, "allianceSelection") + mainArena.lowerThirdNotifier.Notify(nil) + readWebsocketType(t, ws, "lowerThird") } func TestPitDisplay(t *testing.T) { diff --git a/lower_third_test.go b/lower_third_test.go new file mode 100644 index 0000000..c28250a --- /dev/null +++ b/lower_third_test.go @@ -0,0 +1,61 @@ +// Copyright 2014 Team 254. All Rights Reserved. +// Author: pat@patfairbank.com (Patrick Fairbank) + +package main + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestGetNonexistentLowerThird(t *testing.T) { + clearDb() + defer clearDb() + db, err := OpenDatabase(testDbPath) + assert.Nil(t, err) + defer db.Close() + + lowerThird, err := db.GetLowerThirdById(1114) + assert.Nil(t, err) + assert.Nil(t, lowerThird) +} + +func TestLowerThirdCrud(t *testing.T) { + clearDb() + defer clearDb() + db, err := OpenDatabase(testDbPath) + assert.Nil(t, err) + defer db.Close() + + lowerThird := LowerThird{0, "Top Text", "Bottom Text"} + db.CreateLowerThird(&lowerThird) + lowerThird2, err := db.GetLowerThirdById(1) + assert.Nil(t, err) + assert.Equal(t, lowerThird, *lowerThird2) + + lowerThird.BottomText = "Blorpy" + db.SaveLowerThird(&lowerThird) + lowerThird2, err = db.GetLowerThirdById(1) + assert.Nil(t, err) + assert.Equal(t, lowerThird.BottomText, lowerThird2.BottomText) + + db.DeleteLowerThird(&lowerThird) + lowerThird2, err = db.GetLowerThirdById(1) + assert.Nil(t, err) + assert.Nil(t, lowerThird2) +} + +func TestTruncateLowerThirds(t *testing.T) { + clearDb() + defer clearDb() + db, err := OpenDatabase(testDbPath) + assert.Nil(t, err) + defer db.Close() + + lowerThird := LowerThird{0, "Top Text", "Bottom Text"} + db.CreateLowerThird(&lowerThird) + db.TruncateLowerThirds() + lowerThird2, err := db.GetLowerThirdById(1) + assert.Nil(t, err) + assert.Nil(t, lowerThird2) +} diff --git a/setup_lower_thirds_test.go b/setup_lower_thirds_test.go new file mode 100644 index 0000000..0140ff6 --- /dev/null +++ b/setup_lower_thirds_test.go @@ -0,0 +1,55 @@ +// Copyright 2014 Team 254. All Rights Reserved. +// Author: pat@patfairbank.com (Patrick Fairbank) + +package main + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +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"}) + db.CreateLowerThird(&LowerThird{0, "Top Text 2", "Bottom Text 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") + + recorder = postHttpResponse("/setup/lower_thirds", "action=delete&id=1") + assert.Equal(t, 302, recorder.Code) + recorder = getHttpResponse("/setup/lower_thirds") + assert.Equal(t, 200, recorder.Code) + assert.NotContains(t, recorder.Body.String(), "Top Text 1") + assert.Contains(t, recorder.Body.String(), "Bottom Text 2") + + recorder = postHttpResponse("/setup/lower_thirds", "action=save&topText=Text 3&bottomText=") + assert.Equal(t, 302, recorder.Code) + recorder = getHttpResponse("/setup/lower_thirds") + assert.Equal(t, 200, recorder.Code) + assert.Contains(t, recorder.Body.String(), "Text 3") + lowerThird, _ := db.GetLowerThirdById(3) + assert.NotNil(t, lowerThird) + + recorder = postHttpResponse("/setup/lower_thirds", "action=show&topText=Text 4&bottomText=&id=3") + assert.Equal(t, 302, recorder.Code) + recorder = getHttpResponse("/setup/lower_thirds") + assert.Equal(t, 200, recorder.Code) + assert.Contains(t, recorder.Body.String(), "Text 4") + lowerThird, _ = db.GetLowerThirdById(3) + assert.Equal(t, "Text 4", lowerThird.TopText) + assert.Equal(t, "", lowerThird.BottomText) + + recorder = postHttpResponse("/setup/lower_thirds", "action=hide&id=3") + assert.Equal(t, 302, recorder.Code) +}