cview/progressbar_test.go

69 lines
2.1 KiB
Go
Raw Normal View History

2020-04-27 05:19:54 +00:00
package cview
import (
"testing"
)
func TestProgressBar(t *testing.T) {
t.Parallel()
2020-04-28 21:58:37 +00:00
// Initialize
2020-04-28 14:57:37 +00:00
p := NewProgressBar()
2020-04-27 05:19:54 +00:00
if p.GetProgress() != 0 {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 0 progress, got %d", p.GetProgress())
2020-04-27 05:19:54 +00:00
} else if p.GetMax() != 100 {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 100 max, got %d", p.GetMax())
2020-04-27 05:19:54 +00:00
} else if p.Complete() {
2020-04-28 14:57:37 +00:00
t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected incomplete, got complete")
2020-04-27 05:19:54 +00:00
}
2020-04-28 21:58:37 +00:00
// Add progress
2020-04-27 05:19:54 +00:00
p.AddProgress(25)
if p.GetProgress() != 25 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 25 progress, got %d", p.GetProgress())
} else if p.Complete() {
t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
}
p.AddProgress(25)
if p.GetProgress() != 50 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 50 progress, got %d", p.GetProgress())
} else if p.Complete() {
t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
}
p.AddProgress(25)
if p.GetProgress() != 75 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 75 progress, got %d", p.GetProgress())
} else if p.Complete() {
t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
}
p.AddProgress(25)
if p.GetProgress() != 100 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 100 progress, got %d", p.GetProgress())
} else if !p.Complete() {
t.Errorf("failed to update ProgressBar: incorrect state: expected complete, got incomplete")
}
2020-04-28 21:58:37 +00:00
// Reset progress
2020-04-27 05:19:54 +00:00
p.SetProgress(0)
if p.GetProgress() != 0 {
t.Errorf("failed to update ProgressBar: incorrect state: expected 0 progress, got %d", p.GetProgress())
} else if p.Complete() {
t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
}
2020-04-28 21:58:37 +00:00
// Draw
2020-04-28 14:57:37 +00:00
app, err := newTestApp(p)
if err != nil {
t.Errorf("failed to initialize Application: %s", err)
}
2020-04-27 05:19:54 +00:00
2020-04-28 14:57:37 +00:00
p.Draw(app.screen)
2020-04-27 05:19:54 +00:00
}