package tui import ( "context" "strings" "testing" "git.a-wan.net/alan/pipelines/internal/protocol" "github.com/charmbracelet/x/ansi" ) func TestRunPanesExpandWithTabFocus(t *testing.T) { m := New(context.Background(), "") m.width, m.height = 120, 48 m.runOpen, m.keys.runs = true, true m.requestedRunID = 1 run := &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1}, Steps: []protocol.RunStep{{Stage: "one", Status: "completed"}}} updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run})) m = updated.(Model) graph, details := m.runPaneHeights(44) if !m.runGraphFocus || graph <= details || graph+details != 44 { t.Fatal("new run did not prioritize graph", graph, details) } graphPage := m.runPageSize() m = runKey(m, "tab") graph, details = m.runPaneHeights(44) stageWidth := m.runSidebarWidth() if m.runGraphFocus || m.runDetailFocus || details <= graph || stageWidth <= m.width/2 || m.runPageSize() <= graphPage { t.Fatal("stage focus did not expand", graph, details, stageWidth) } m = runKey(m, "tab") if !m.runDetailFocus || m.runSidebarWidth() >= stageWidth || m.width-m.runSidebarWidth() <= m.width/2 { t.Fatal("details focus did not expand detail pane") } updated, _ = m.Update(receivedMsg(protocol.Message{Type: protocol.Run, RunDetail: run})) m = updated.(Model) if !m.runDetailFocus || m.runGraphFocus { t.Fatal("polling reset chosen focus") } m = runKey(m, "tab") graph, details = m.runPaneHeights(44) if !m.runGraphFocus || graph <= details { t.Fatal("graph did not expand again") } for _, height := range []int{14, 18, 24, 44, 80} { for _, pane := range []int{0, 1, 2} { m.runDetailFocus, m.runGraphFocus = pane == 1, pane == 2 graph, details = m.runPaneHeights(height) if graph+details != height || graph < 6 || details < 8 { t.Fatal("pane sizes exceed available height", height, graph, details) } view := m.runsView(height) if len(strings.Split(view, "\n")) > height { t.Fatal("expanded pane exceeds height") } for _, line := range strings.Split(view, "\n") { if ansi.StringWidth(line) > m.width { t.Fatal("expanded pane exceeds width") } } } } }