Files
pipelines/internal/tui/graph_compact_test.go
T

42 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package tui
import (
"fmt"
"strings"
"testing"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/x/ansi"
)
func TestCompactGraphDimensions(t *testing.T) {
linear, err := pipeline.Parse(pipeline.Template([]string{"plan", "implement_with_a_long_stage_name", "review", "publish"}, true))
if err != nil {
t.Fatal(err)
}
for name, graph := range map[string]protocol.Graph{"linear": linear, "nested": nestedForkGraph(t)} {
layout := layoutGraph(graph)
t.Logf("%s: %d columns × %d rows", name, layout.width, layout.height)
// Measured before compaction: linear 175×15; nested forks 147×48.
if name == "linear" && (layout.width > 100 || layout.height > 15) {
t.Fatal("linear graph grew", layout.width, layout.height)
}
if name == "nested" && (layout.width > 118 || layout.height > 41) {
t.Fatal("fork graph grew", layout.width, layout.height)
}
assertForkRouteClearance(t, layout)
view := ansi.Strip(strings.Join(renderGraph(graph), "\n"))
for _, stage := range graph.Stages {
if !strings.Contains(view, stage.Key) {
t.Fatal("compaction lost stage", stage.Key)
}
}
for _, edge := range layout.edges {
if !strings.Contains(view, fmt.Sprintf("%s [%d]", edge.label, edge.id)) {
t.Fatal("compaction lost outcome", edge)
}
}
}
}