| 299 | } |
| 300 | |
| 301 | func TestToJSON(t *testing.T) { |
| 302 | tasks := []*model.Task{ |
| 303 | { |
| 304 | ID: "T1", |
| 305 | Title: "Task 1", |
| 306 | Status: model.StatusCompleted, |
| 307 | Priority: model.PriorityHigh, |
| 308 | Dependencies: []string{}, |
| 309 | Created: model.NewFlexibleTime(time.Now()), |
| 310 | }, |
| 311 | { |
| 312 | ID: "T2", |
| 313 | Title: "Task 2", |
| 314 | Status: model.StatusPending, |
| 315 | Dependencies: []string{"T1"}, |
| 316 | Created: model.NewFlexibleTime(time.Now()), |
| 317 | }, |
| 318 | } |
| 319 | |
| 320 | g := NewGraph(tasks) |
| 321 | jsonOutput := g.ToJSON() |
| 322 | |
| 323 | nodes, ok := jsonOutput["nodes"].([]map[string]any) |
| 324 | if !ok { |
| 325 | t.Fatal("Expected nodes to be a slice of maps") |
| 326 | } |
| 327 | |
| 328 | if len(nodes) != 2 { |
| 329 | t.Errorf("Expected 2 nodes in JSON output, got %d", len(nodes)) |
| 330 | } |
| 331 | |
| 332 | edges, ok := jsonOutput["edges"].([]map[string]string) |
| 333 | if !ok { |
| 334 | t.Fatal("Expected edges to be a slice of maps") |
| 335 | } |
| 336 | |
| 337 | if len(edges) != 1 { |
| 338 | t.Errorf("Expected 1 edge in JSON output, got %d", len(edges)) |
| 339 | } |
| 340 | |
| 341 | // Check edge structure |
| 342 | if edges[0]["from"] != "T1" || edges[0]["to"] != "T2" { |
| 343 | t.Error("Expected edge from T1 to T2") |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | func TestToASCII_NilFormatter_PlainText(t *testing.T) { |
| 348 | tasks := createTestTasks() |