summaryrefslogtreecommitdiff
path: root/internal/store/labels_test.go
blob: 4e970845e21494b3d1c37ab9e373a02b9b66609f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package store

import (
	"errors"
	"testing"
)

func TestSetTaskLabels_UpdatesLabels(t *testing.T) {
	s := newNativeTasksTestStore(t)

	if err := s.SetTaskLabels("real-1", []string{"chore", "urgent"}); err != nil {
		t.Fatalf("SetTaskLabels: %v", err)
	}

	task, err := s.GetNativeTaskByID("real-1")
	if err != nil {
		t.Fatal(err)
	}
	if len(task.Labels) != 2 || task.Labels[0] != "chore" || task.Labels[1] != "urgent" {
		t.Errorf("Labels = %v, want [chore urgent]", task.Labels)
	}
}

func TestSetTaskLabels_EmptyList_ClearsLabels(t *testing.T) {
	s := newNativeTasksTestStore(t)
	if err := s.SetTaskLabels("real-1", []string{"chore"}); err != nil {
		t.Fatal(err)
	}

	if err := s.SetTaskLabels("real-1", []string{}); err != nil {
		t.Fatalf("SetTaskLabels (clear): %v", err)
	}

	task, err := s.GetNativeTaskByID("real-1")
	if err != nil {
		t.Fatal(err)
	}
	if len(task.Labels) != 0 {
		t.Errorf("Labels = %v, want empty", task.Labels)
	}
}

func TestSetTaskLabels_UnknownID_ReturnsErrNotFound(t *testing.T) {
	s := newNativeTasksTestStore(t)
	err := s.SetTaskLabels("does-not-exist", []string{"chore"})
	if !errors.Is(err, ErrNativeTaskNotFound) {
		t.Fatalf("expected ErrNativeTaskNotFound, got %v", err)
	}
}

func TestSetLabelColor_ThenGetLabelColors_ReturnsIt(t *testing.T) {
	s := newNativeTasksTestStore(t)

	if err := s.SetLabelColor("chore", "#F59E0B"); err != nil {
		t.Fatalf("SetLabelColor: %v", err)
	}

	colors, err := s.GetLabelColors()
	if err != nil {
		t.Fatalf("GetLabelColors: %v", err)
	}
	if len(colors) != 1 || colors[0].Name != "chore" || colors[0].Color != "#F59E0B" {
		t.Fatalf("colors = %+v, want [{chore #F59E0B}]", colors)
	}
}

func TestSetLabelColor_SameName_Overwrites(t *testing.T) {
	s := newNativeTasksTestStore(t)
	if err := s.SetLabelColor("chore", "#F59E0B"); err != nil {
		t.Fatal(err)
	}

	if err := s.SetLabelColor("chore", "#EF4444"); err != nil {
		t.Fatalf("SetLabelColor (overwrite): %v", err)
	}

	colors, err := s.GetLabelColors()
	if err != nil {
		t.Fatal(err)
	}
	if len(colors) != 1 || colors[0].Color != "#EF4444" {
		t.Fatalf("colors = %+v, want a single entry with the overwritten color", colors)
	}
}