| 1 | package cmd |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "the-valley/flow/internal/config" |
| 8 | gh "the-valley/flow/internal/github" |
| 9 | "the-valley/flow/internal/run" |
| 10 | ) |
| 11 | |
| 12 | // TestDashboardNotesFailedValleyCheck feeds the update loop a failed valley |
| 13 | // check and then a good one: the note shows while the latest check failed |
| 14 | // and clears on the next success. |
| 15 | func TestDashboardNotesFailedValleyCheck(t *testing.T) { |
| 16 | m := newDashboardModel(run.NewGitDirStore(t.TempDir()), config.Config{}, gh.NewGHCLIClient("")) |
| 17 | m.width, m.height = 120, 30 |
| 18 | m.states = []*run.State{} |
| 19 | update := func(msg integrationMsg) { |
| 20 | next, _ := m.Update(msg) |
| 21 | m = next.(dashboardModel) |
| 22 | } |
| 23 | const note = "valley unreachable: timed out after 3m0s; showing git's view" |
| 24 | |
| 25 | update(integrationMsg{valleyErr: "timed out after 3m0s"}) |
| 26 | if v := m.View(); !strings.Contains(v, note) { |
| 27 | t.Errorf("view lacks %q after a failed check:\n%s", note, v) |
| 28 | } |
| 29 | update(integrationMsg{valleyErr: "timed out after 3m0s"}) |
| 30 | if v := m.View(); strings.Count(v, "valley unreachable") != 1 { |
| 31 | t.Errorf("a second failure should keep one note:\n%s", v) |
| 32 | } |
| 33 | update(integrationMsg{}) |
| 34 | if v := m.View(); strings.Contains(v, "valley unreachable") { |
| 35 | t.Errorf("the note should clear after a successful check:\n%s", v) |
| 36 | } |
| 37 | } |