dashboard_test.go (2787B)
1 package tui 2 3 import "testing" 4 5 func TestMoveDownIntoChildren(t *testing.T) { 6 m := NewDashboard("/tmp/local", "remote:/tmp") 7 m.events = []SyncEvent{ 8 {File: "src/", Status: "synced", Files: []string{"src/a.go", "src/b.go"}, FileCount: 2}, 9 {File: "docs/", Status: "synced", Files: []string{"docs/readme.md"}, FileCount: 1}, 10 } 11 m.expanded[0] = true 12 13 filtered := m.filteredEvents() 14 15 // Start at event 0, parent 16 m.cursor = 0 17 m.childCursor = -1 18 19 // j → first child 20 m.moveDown(filtered) 21 if m.cursor != 0 || m.childCursor != 0 { 22 t.Fatalf("expected cursor=0 child=0, got cursor=%d child=%d", m.cursor, m.childCursor) 23 } 24 25 // j → second child 26 m.moveDown(filtered) 27 if m.cursor != 0 || m.childCursor != 1 { 28 t.Fatalf("expected cursor=0 child=1, got cursor=%d child=%d", m.cursor, m.childCursor) 29 } 30 31 // j → next event 32 m.moveDown(filtered) 33 if m.cursor != 1 || m.childCursor != -1 { 34 t.Fatalf("expected cursor=1 child=-1, got cursor=%d child=%d", m.cursor, m.childCursor) 35 } 36 } 37 38 func TestMoveUpFromChildren(t *testing.T) { 39 m := NewDashboard("/tmp/local", "remote:/tmp") 40 m.events = []SyncEvent{ 41 {File: "src/", Status: "synced", Files: []string{"src/a.go", "src/b.go"}, FileCount: 2}, 42 {File: "docs/", Status: "synced", Files: []string{"docs/readme.md"}, FileCount: 1}, 43 } 44 m.expanded[0] = true 45 46 filtered := m.filteredEvents() 47 48 // Start at event 1 49 m.cursor = 1 50 m.childCursor = -1 51 52 // k → last child of event 0 53 m.moveUp(filtered) 54 if m.cursor != 0 || m.childCursor != 1 { 55 t.Fatalf("expected cursor=0 child=1, got cursor=%d child=%d", m.cursor, m.childCursor) 56 } 57 58 // k → first child 59 m.moveUp(filtered) 60 if m.cursor != 0 || m.childCursor != 0 { 61 t.Fatalf("expected cursor=0 child=0, got cursor=%d child=%d", m.cursor, m.childCursor) 62 } 63 64 // k → parent 65 m.moveUp(filtered) 66 if m.cursor != 0 || m.childCursor != -1 { 67 t.Fatalf("expected cursor=0 child=-1, got cursor=%d child=%d", m.cursor, m.childCursor) 68 } 69 } 70 71 func TestMoveDownSkipsCollapsed(t *testing.T) { 72 m := NewDashboard("/tmp/local", "remote:/tmp") 73 m.events = []SyncEvent{ 74 {File: "src/", Status: "synced", Files: []string{"src/a.go"}, FileCount: 1}, 75 {File: "docs/", Status: "synced"}, 76 } 77 // Not expanded — should skip children 78 79 filtered := m.filteredEvents() 80 m.cursor = 0 81 m.childCursor = -1 82 83 m.moveDown(filtered) 84 if m.cursor != 1 || m.childCursor != -1 { 85 t.Fatalf("expected cursor=1 child=-1, got cursor=%d child=%d", m.cursor, m.childCursor) 86 } 87 } 88 89 func TestMoveDownAtEnd(t *testing.T) { 90 m := NewDashboard("/tmp/local", "remote:/tmp") 91 m.events = []SyncEvent{ 92 {File: "a.go", Status: "synced"}, 93 } 94 filtered := m.filteredEvents() 95 m.cursor = 0 96 m.childCursor = -1 97 98 m.moveDown(filtered) 99 // Should stay at 0 100 if m.cursor != 0 { 101 t.Fatalf("expected cursor=0, got %d", m.cursor) 102 } 103 }