Skip to content

Commit

Permalink
✅ proper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed May 5, 2024
1 parent 47a42c5 commit 95324f6
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ update:

lint:
@golangci-lint run


test:
@go test -v ./...
42 changes: 42 additions & 0 deletions config_test.go
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)
}
}
44 changes: 44 additions & 0 deletions models_test.go
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())
}
}
46 changes: 46 additions & 0 deletions mvc_test.go
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")
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Taskin
Easy and logical-to-implement task lists that feel alive and interactive.


<p align="center">
<img src="https://raw.githubusercontent.com/fumeapp/taskin/857a1b8cbeda577a751b5c7f38885995a894169f/taskin.png" width="300" />
Expand Down
64 changes: 64 additions & 0 deletions taskin_test.go
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))
}
}

0 comments on commit 95324f6

Please sign in to comment.