74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"github.com/charmbracelet/x/ansi"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Opt-in rendered snapshots for human/independent UI review; no server mutations.
|
|
func TestUIUXReviewSnapshots(t *testing.T) {
|
|
directory := os.Getenv("PIPELINES_UX_SNAPSHOT_DIR")
|
|
if directory == "" {
|
|
t.Skip("set PIPELINES_UX_SNAPSHOT_DIR for rendered UI review")
|
|
}
|
|
if err := os.MkdirAll(directory, 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
source, err := os.ReadFile("../../examples/anime-today.md")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
graph, err := pipeline.Parse(string(source))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, width := range []int{80, 120, 160} {
|
|
m := New(context.Background(), "ws://127.0.0.1:8080/connect")
|
|
m.width = width
|
|
m.height = 36
|
|
m.loaded = true
|
|
m.status = "127.0.0.1:8080"
|
|
m.notificationEndpoints = []protocol.NotificationEndpoint{{Destination: "system", ServerURL: "http://100.85.25.33:8090", Topic: "pipelines"}}
|
|
m.pipelines = []protocol.PipelineSummary{{ID: 8, Name: "anime episodes today", Version: 1, Stages: 4, CreatedAt: "2026-10-08T20:00:00Z", UpdatedAt: "2026-10-08T20:00:00Z"}}
|
|
save := func(name string) {
|
|
t.Helper()
|
|
view := ansi.Strip(m.View())
|
|
for _, line := range strings.Split(view, "\n") {
|
|
if ansi.StringWidth(line) > width {
|
|
t.Fatalf("%s overflows", name)
|
|
}
|
|
}
|
|
if err := os.WriteFile(filepath.Join(directory, fmt.Sprintf("%s-%d.txt", name, width)), []byte(view), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
save("home")
|
|
m.keys.detail = true
|
|
m.detail = &protocol.PipelineDetail{PipelineSummary: m.pipelines[0], Source: string(source), Graph: graph, LatestVersion: 1, VersionCreatedAt: "2026-10-08T20:00:00Z"}
|
|
save("pipeline")
|
|
m = press(m, "n")
|
|
save("next-stage")
|
|
m = press(m, "tab")
|
|
save("focused-stage")
|
|
for i := 0; i < 24; i++ {
|
|
m = press(m, "j")
|
|
}
|
|
save("scrolled-stage")
|
|
m = press(m, "tab")
|
|
m = press(m, "4")
|
|
save("delivery-stage")
|
|
m.runOpen = true
|
|
m.keys.runs = true
|
|
m.runDetail = &protocol.RunDetail{RunSummary: protocol.RunSummary{ID: 1, Name: "anime episodes today", PipelineID: 8, Version: 1, Status: "succeeded", CreatedAt: "2026-10-08T20:00:00Z", FinishedAt: "2026-10-08T20:01:00Z"}, Steps: []protocol.RunStep{{Sequence: 1, Stage: "discover", Status: "completed", Outcome: "success", Target: "verify"}, {Sequence: 2, Stage: "verify", Status: "completed", Outcome: "success", Target: "report"}, {Sequence: 3, Stage: "report", Status: "completed", Outcome: "success", Target: "notify", Output: map[string]any{"markdown": "# Anime episodes today\n\n[Source](https://www.livechart.me/schedule)"}}, {Sequence: 4, Stage: "notify", Status: "completed", Outcome: "success", Target: protocol.SuccessEnd, Output: map[string]any{"delivery": map[string]any{"attachment_url": "http://100.85.25.33:8090/file/report.md"}}}}}
|
|
m.runStepIndex = 4
|
|
save("run")
|
|
}
|
|
}
|