diff --git a/Makefile b/Makefile index 1aba8f6..59a87e0 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,7 @@ update: lint: @golangci-lint run + + +test: + @go test -v ./... diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..bf907de --- /dev/null +++ b/config_test.go @@ -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) + } +} diff --git a/models_test.go b/models_test.go new file mode 100644 index 0000000..3881c27 --- /dev/null +++ b/models_test.go @@ -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()) + } +} diff --git a/mvc_test.go b/mvc_test.go new file mode 100644 index 0000000..19dc164 --- /dev/null +++ b/mvc_test.go @@ -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") + } +} diff --git a/readme.md b/readme.md index 890a51c..29e94cb 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,6 @@ # Taskin +Easy and logical-to-implement task lists that feel alive and interactive. +
diff --git a/taskin_test.go b/taskin_test.go new file mode 100644 index 0000000..fb80f02 --- /dev/null +++ b/taskin_test.go @@ -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)) + } +}