48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
func TestShowcaseGraphsRender(t *testing.T) {
|
|
for _, name := range []string{"bug-fix", "new-feature", "dashboard-screenshots", "dependency-upgrade", "incident-diagnosis"} {
|
|
t.Run(name, func(t *testing.T) {
|
|
source, err := os.ReadFile(filepath.Join("..", "..", "examples", name+".md"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
graph, err := pipeline.Parse(string(source))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
layout := layoutGraph(graph)
|
|
for _, selected := range graph.Stages {
|
|
rows := renderGraph(graph, selected.Key)
|
|
if len(rows) != layout.height {
|
|
t.Fatal("render height differs from layout")
|
|
}
|
|
for _, row := range rows {
|
|
if lipgloss.Width(row) > layout.width {
|
|
t.Fatal("render exceeds graph width")
|
|
}
|
|
}
|
|
view := strings.Join(rows, "\n")
|
|
for _, stage := range graph.Stages {
|
|
if !strings.Contains(view, stage.Key) {
|
|
t.Fatalf("missing stage %s", stage.Key)
|
|
}
|
|
}
|
|
if !strings.Contains(view, "SUCCESS") || !strings.Contains(view, "FAILURE") {
|
|
t.Fatal("missing terminal nodes")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|