-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ update: | |
|
||
lint: | ||
@golangci-lint run | ||
|
||
|
||
test: | ||
@go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package taskin | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/progress" | ||
"github.com/charmbracelet/bubbles/spinner" | ||
"github.com/charmbracelet/lipgloss" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
config := Config{ | ||
Spinner: spinner.Dot, | ||
ProgressOption: progress.WithDefaultGradient(), | ||
Colors: ConfigColors{ | ||
Spinner: lipgloss.Color("214"), | ||
Pending: lipgloss.Color("21"), | ||
Success: lipgloss.Color("46"), | ||
Failure: lipgloss.Color("196"), | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(config.Spinner.Frames, spinner.Dot.Frames) { | ||
t.Errorf("Expected spinner frames to be equal to 'Dot' frames") | ||
} | ||
|
||
if config.Colors.Spinner != lipgloss.Color("214") { | ||
t.Errorf("Expected spinner color to be '214', got '%s'", config.Colors.Spinner) | ||
} | ||
|
||
if config.Colors.Pending != lipgloss.Color("21") { | ||
t.Errorf("Expected pending color to be '21', got '%s'", config.Colors.Pending) | ||
} | ||
|
||
if config.Colors.Success != lipgloss.Color("46") { | ||
t.Errorf("Expected success color to be '46', got '%s'", config.Colors.Success) | ||
} | ||
|
||
if config.Colors.Failure != lipgloss.Color("196") { | ||
t.Errorf("Expected failure color to be '196', got '%s'", config.Colors.Failure) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package taskin | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestTask(t *testing.T) { | ||
task := Task{ | ||
Title: "Test Task", | ||
Task: func(t *Task) error { return nil }, | ||
} | ||
|
||
if task.Title != "Test Task" { | ||
t.Errorf("Expected task title to be 'Test Task', got '%s'", task.Title) | ||
} | ||
|
||
err := task.Task(&task) | ||
if err != nil { | ||
t.Errorf("Expected task function to return nil, got '%s'", err.Error()) | ||
} | ||
} | ||
|
||
func TestRunner(t *testing.T) { | ||
runner := Runner{ | ||
Task: Task{ | ||
Title: "Test Task", | ||
Task: func(t *Task) error { return nil }, | ||
}, | ||
State: NotStarted, | ||
} | ||
|
||
if runner.State != NotStarted { | ||
t.Errorf("Expected runner state to be 'NotStarted', got '%d'", runner.State) | ||
} | ||
|
||
if runner.Task.Title != "Test Task" { | ||
t.Errorf("Expected task title to be 'Test Task', got '%s'", runner.Task.Title) | ||
} | ||
|
||
err := runner.Task.Task(&runner.Task) | ||
if err != nil { | ||
t.Errorf("Expected task function to return nil, got '%s'", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package taskin | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/spinner" | ||
"testing" | ||
) | ||
|
||
func TestRunners_Init(t *testing.T) { | ||
runners := &Runners{ | ||
NewRunner(Task{Title: "Test Task", Task: func(t *Task) error { return nil }}, Config{}), | ||
} | ||
|
||
cmd := runners.Init() | ||
|
||
if cmd == nil { | ||
t.Errorf("Expected Init to return a non-nil Cmd") | ||
} | ||
} | ||
|
||
func TestRunners_Update(t *testing.T) { | ||
runners := &Runners{ | ||
// Initialize with some test data | ||
} | ||
|
||
model, cmd := runners.Update(spinner.TickMsg{}) | ||
|
||
if model == nil { | ||
t.Errorf("Expected Update to return a non-nil Model") | ||
} | ||
|
||
if cmd == nil { | ||
t.Errorf("Expected Update to return a non-nil Cmd") | ||
} | ||
} | ||
|
||
func TestRunners_View(t *testing.T) { | ||
runners := &Runners{ | ||
NewRunner(Task{Title: "Test Task", Task: func(t *Task) error { return nil }}, Config{}), | ||
} | ||
|
||
view := runners.View() | ||
|
||
if view == "" { | ||
t.Errorf("Expected View to return a non-empty string") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package taskin | ||
|
||
import ( | ||
"github.com/charmbracelet/bubbles/spinner" | ||
"testing" | ||
) | ||
|
||
func TestNewRunner(t *testing.T) { | ||
task := Task{ | ||
Title: "Test Task", | ||
Task: func(t *Task) error { return nil }, | ||
} | ||
cfg := Config{ | ||
Spinner: spinner.Dot, | ||
} | ||
|
||
runner := NewRunner(task, cfg) | ||
|
||
if runner.State != NotStarted { | ||
t.Errorf("Expected runner state to be 'NotStarted', got '%d'", runner.State) | ||
} | ||
|
||
if runner.Task.Title != "Test Task" { | ||
t.Errorf("Expected task title to be 'Test Task', got '%s'", runner.Task.Title) | ||
} | ||
} | ||
|
||
func TestRunnersRun(t *testing.T) { | ||
tasks := Tasks{ | ||
Task{ | ||
Title: "Test Task", | ||
Task: func(t *Task) error { return nil }, | ||
}, | ||
} | ||
cfg := Config{ | ||
Spinner: spinner.Dot, | ||
} | ||
|
||
runners := New(tasks, cfg) | ||
|
||
err := runners.Run() | ||
|
||
if err != nil { | ||
t.Errorf("Expected Run to return nil, got '%s'", err.Error()) | ||
} | ||
} | ||
|
||
func TestNew(t *testing.T) { | ||
tasks := Tasks{ | ||
Task{ | ||
Title: "Test Task", | ||
Task: func(t *Task) error { return nil }, | ||
}, | ||
} | ||
cfg := Config{ | ||
Spinner: spinner.Dot, | ||
} | ||
|
||
runners := New(tasks, cfg) | ||
|
||
if len(runners) != 1 { | ||
t.Errorf("Expected New to return 1 runner, got '%d'", len(runners)) | ||
} | ||
} |