40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"github.com/charmbracelet/x/ansi"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHomeNotificationSetup(t *testing.T) {
|
|
m := New(context.Background(), "ws://localhost/connect")
|
|
m.width = 120
|
|
m.height = 40
|
|
updated, _ := m.Update(receivedMsg(protocol.Message{Type: protocol.PipelineList, NotificationEndpoints: []protocol.NotificationEndpoint{{Destination: "system", ServerURL: "http://10.0.0.249:8090", Topic: "pipelines"}}}))
|
|
m = updated.(Model)
|
|
view := ansi.Strip(m.View())
|
|
header := strings.Split(view, "\n")[0]
|
|
for _, text := range []string{"ntfy", "http://10.0.0.249:8090", "topic pipelines"} {
|
|
if !strings.Contains(header, text) {
|
|
t.Fatal("missing phone setup", text, view)
|
|
}
|
|
}
|
|
if strings.Contains(strings.Join(m.homeLines(), "\n"), "Phone notifications") {
|
|
t.Fatal("notification setup still occupies home panel")
|
|
}
|
|
m.runOpen = true
|
|
if !strings.Contains(strings.Split(ansi.Strip(m.View()), "\n")[0], "topic pipelines") {
|
|
t.Fatal("ntfy setup missing from run page header")
|
|
}
|
|
for _, width := range []int{1, 12, 40, 80, 120} {
|
|
m.width = width
|
|
for _, line := range strings.Split(m.View(), "\n") {
|
|
if ansi.StringWidth(line) > width {
|
|
t.Fatalf("header/layout overflows at width %d", width)
|
|
}
|
|
}
|
|
}
|
|
}
|