...

Source file src/code.rocketnine.space/tslocum/cview/progressbar_test.go

Documentation: code.rocketnine.space/tslocum/cview

     1  package cview
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestProgressBar(t *testing.T) {
     8  	t.Parallel()
     9  
    10  	// Initialize
    11  
    12  	p := NewProgressBar()
    13  	if p.GetProgress() != 0 {
    14  		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 0 progress, got %d", p.GetProgress())
    15  	} else if p.GetMax() != 100 {
    16  		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected 100 max, got %d", p.GetMax())
    17  	} else if p.Complete() {
    18  		t.Errorf("failed to initialize ProgressBar: incorrect initial state: expected incomplete, got complete")
    19  	}
    20  
    21  	// Add progress
    22  
    23  	p.AddProgress(25)
    24  	if p.GetProgress() != 25 {
    25  		t.Errorf("failed to update ProgressBar: incorrect state: expected 25 progress, got %d", p.GetProgress())
    26  	} else if p.Complete() {
    27  		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
    28  	}
    29  
    30  	p.AddProgress(25)
    31  	if p.GetProgress() != 50 {
    32  		t.Errorf("failed to update ProgressBar: incorrect state: expected 50 progress, got %d", p.GetProgress())
    33  	} else if p.Complete() {
    34  		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
    35  	}
    36  
    37  	p.AddProgress(25)
    38  	if p.GetProgress() != 75 {
    39  		t.Errorf("failed to update ProgressBar: incorrect state: expected 75 progress, got %d", p.GetProgress())
    40  	} else if p.Complete() {
    41  		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
    42  	}
    43  
    44  	p.AddProgress(25)
    45  	if p.GetProgress() != 100 {
    46  		t.Errorf("failed to update ProgressBar: incorrect state: expected 100 progress, got %d", p.GetProgress())
    47  	} else if !p.Complete() {
    48  		t.Errorf("failed to update ProgressBar: incorrect state: expected complete, got incomplete")
    49  	}
    50  
    51  	// Reset progress
    52  
    53  	p.SetProgress(0)
    54  	if p.GetProgress() != 0 {
    55  		t.Errorf("failed to update ProgressBar: incorrect state: expected 0 progress, got %d", p.GetProgress())
    56  	} else if p.Complete() {
    57  		t.Errorf("failed to update ProgressBar: incorrect state: expected incomplete, got complete")
    58  	}
    59  
    60  	// Draw
    61  
    62  	app, err := newTestApp(p)
    63  	if err != nil {
    64  		t.Errorf("failed to initialize Application: %s", err)
    65  	}
    66  
    67  	p.Draw(app.screen)
    68  }
    69  

View as plain text