cview/checkbox_test.go

49 lines
1.2 KiB
Go
Raw Normal View History

2020-04-26 23:46:43 +00:00
package cview
import (
"testing"
)
const (
2020-04-26 23:55:45 +00:00
testCheckBoxLabelA = "Hello, world!"
testCheckBoxLabelB = "Goodnight, moon!"
2020-04-26 23:46:43 +00:00
)
2020-04-26 23:55:45 +00:00
func TestCheckBox(t *testing.T) {
2020-04-26 23:46:43 +00:00
t.Parallel()
2020-04-28 14:57:37 +00:00
c := NewCheckBox()
2020-04-26 23:46:43 +00:00
if c.IsChecked() {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize CheckBox: incorrect initial state: expected unchecked, got checked")
} else if c.GetLabel() != "" {
t.Errorf("failed to initialize CheckBox: incorrect label: expected '', got %s", c.GetLabel())
}
c.SetLabel(testCheckBoxLabelA)
if c.GetLabel() != testCheckBoxLabelA {
t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelA, c.GetLabel())
2020-04-26 23:46:43 +00:00
}
2020-04-26 23:55:45 +00:00
c.SetLabel(testCheckBoxLabelB)
if c.GetLabel() != testCheckBoxLabelB {
t.Errorf("failed to set CheckBox label: incorrect label: expected %s, got %s", testCheckBoxLabelB, c.GetLabel())
2020-04-26 23:46:43 +00:00
}
c.SetChecked(true)
if !c.IsChecked() {
2020-04-26 23:55:45 +00:00
t.Errorf("failed to update CheckBox state: incorrect state: expected checked, got unchecked")
2020-04-26 23:46:43 +00:00
}
c.SetChecked(false)
if c.IsChecked() {
2020-04-26 23:55:45 +00:00
t.Errorf("failed to update CheckBox state: incorrect state: expected unchecked, got checked")
2020-04-26 23:46:43 +00:00
}
2020-04-28 14:57:37 +00:00
app, err := newTestApp(c)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)
}
2020-04-26 23:46:43 +00:00
2020-04-28 14:57:37 +00:00
c.Draw(app.screen)
2020-04-26 23:46:43 +00:00
}