gunk-dev/the-valley

plan_test.go

sourced5c3f09f23b9main's published tip history
2.6 KiB
1package main
2
3import (
4 "slices"
5 "testing"
6 "time"
7
8 "the-valley/knot"
9)
10
11// A root's progress counts every descendant, at any depth. An abandoned
12// knot counts for nothing, and the knots under it count as any other. A
13// level lists its knots in the order they were created, then by title,
14// then by ID, so knots of one date and one title keep one order. valley-plan
15// holds the rest of the view to a golden file.
16func TestPlanCountsEveryDescendantAndOrdersByCreatedTitleID(t *testing.T) {
17 g := &knot.Graph{Knots: map[string]*knot.Knot{}, Comments: map[string][]knot.Noted{}}
18 add := func(typ, id, status, title, created, parent string) {
19 g.Knots[id] = &knot.Knot{Type: typ, ID: id, Status: status, Title: title, Created: created,
20 Parent: parent, Slug: "s"}
21 }
22 add("outcome", "oc-0000001", "open", "Milestone", "2026-10-02", "")
23 add("outcome", "oc-0000009", "open", "Zz root", "2026-10-01", "")
24 add("outcome", "oc-0000002", "done", "Zeta", "2026-10-01", "oc-0000001")
25 add("bug", "bd-0000005", "closed", "Beta", "2026-10-02", "oc-0000002")
26 add("outcome", "oc-0000003", "abandoned", "Alpha", "2026-10-02", "oc-0000001")
27 add("bug", "bd-0000004", "open", "Left under an abandoned outcome", "2026-10-02", "oc-0000003")
28 add("outcome", "oc-0000008", "open", "Beta", "2026-10-02", "oc-0000001")
29 add("outcome", "oc-0000006", "open", "Beta", "2026-10-02", "oc-0000001")
30 add("idea", "ida-0000007", "raw", "Beta", "2026-10-02", "oc-0000001")
31
32 v := newPlanView(remote{}, knotState{graph: g}, time.Date(2026, 10, 15, 0, 0, 0, 0, time.UTC), nil)
33
34 if want := []string{"oc-0000009", "oc-0000001"}; !slices.Equal(v.roots, want) {
35 t.Errorf("roots are %v, want %v", v.roots, want)
36 }
37 want := []string{"oc-0000002", "oc-0000003", "ida-0000007", "oc-0000006", "oc-0000008"}
38 if got := v.children["oc-0000001"]; !slices.Equal(got, want) {
39 t.Errorf("the milestone's children are %v, want %v", got, want)
40 }
41 want = []string{"oc-0000009", "oc-0000001", "oc-0000002", "bd-0000005", "oc-0000003", "bd-0000004",
42 "ida-0000007", "oc-0000006", "oc-0000008"}
43 if !slices.Equal(v.order, want) {
44 t.Errorf("the tree lists %v, want %v", v.order, want)
45 }
46 for id, want := range map[string]knot.Progress{
47 "oc-0000001": {Done: 2, Of: 6}, // oc-2 and bd-5 done; bd-4, ida-7, oc-6, oc-8 not; oc-3 abandoned
48 "oc-0000002": {Done: 1, Of: 1},
49 "oc-0000003": {Done: 0, Of: 1},
50 } {
51 if got := v.knots[id].Progress; got == nil || *got != want {
52 t.Errorf("%s's progress is %v, want %v", id, got, want)
53 }
54 }
55 if p := v.knots["oc-0000009"].Progress; p != nil {
56 t.Errorf("a root with no descendants has the progress %v, want none", *p)
57 }
58}