(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func TestGroupSnapshots(t *testing.T) { |
| 164 | snapshots := []TaskSnapshot{ |
| 165 | {ID: "001", Status: "completed", Priority: "high", Effort: "small", Group: "backend"}, |
| 166 | {ID: "002", Status: "pending", Priority: "medium", Effort: "medium"}, |
| 167 | {ID: "003", Status: "pending", Priority: "low", Effort: "large", Group: "frontend"}, |
| 168 | } |
| 169 | |
| 170 | tests := []struct { |
| 171 | name string |
| 172 | groupBy string |
| 173 | wantKey string |
| 174 | }{ |
| 175 | {"by status", "status", "pending"}, |
| 176 | {"by priority", "priority", "high"}, |
| 177 | {"by effort", "effort", "small"}, |
| 178 | {"by group", "group", "backend"}, |
| 179 | {"unknown field", "unknown", "ungrouped"}, |
| 180 | } |
| 181 | |
| 182 | for _, tt := range tests { |
| 183 | t.Run(tt.name, func(t *testing.T) { |
| 184 | groups := groupSnapshots(snapshots, tt.groupBy) |
| 185 | if _, ok := groups[tt.wantKey]; !ok { |
| 186 | t.Errorf("expected key %q in groups, got keys: %v", tt.wantKey, groupKeys(groups)) |
| 187 | } |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | // Empty field → "none" |
| 192 | t.Run("empty field becomes none", func(t *testing.T) { |
| 193 | groups := groupSnapshots(snapshots, "group") |
| 194 | if _, ok := groups["none"]; !ok { |
| 195 | t.Errorf("expected 'none' key for empty group field, got keys: %v", groupKeys(groups)) |
| 196 | } |
| 197 | }) |
| 198 | } |
| 199 | |
| 200 | func groupKeys(m map[string][]TaskSnapshot) []string { |
| 201 | keys := make([]string, 0, len(m)) |
nothing calls this directly
no test coverage detected