xonecas.io
60255
Zn

Zoea-Nova / files

Zoea-Nova / internal / tui / testhelpers_test.go

1.7 KB
1package tui
2
3import (
4	"fmt"
5	"regexp"
6	"testing"
7	"time"
8
9	"github.com/charmbracelet/bubbles/viewport"
10	"github.com/charmbracelet/lipgloss"
11	"github.com/muesli/termenv"
12)
13
14// Test constants for consistent terminal dimensions
15const (
16	TestTerminalWidth  = 120
17	TestTerminalHeight = 40
18)
19
20// setupGoldenTest forces TrueColor output for consistent golden file generation.
21// Returns a cleanup function that should be deferred.
22func setupGoldenTest(t *testing.T) func() {
23	t.Helper()
24	lipgloss.SetColorProfile(termenv.TrueColor)
25	return func() {
26		lipgloss.SetColorProfile(termenv.Ascii)
27	}
28}
29
30// ansiRegex matches ANSI escape codes (duplicated from tui_test.go for golden tests)
31var ansiStripRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
32
33// stripANSIForGolden removes all ANSI escape codes from a string for stripped golden files.
34func stripANSIForGolden(s string) string {
35	return ansiStripRegex.ReplaceAllString(s, "")
36}
37
38// newTestViewport creates a viewport for testing.
39func newTestViewport(width, height int) viewport.Model {
40	vp := viewport.New(width, height)
41	vp.Style = logStyle
42	return vp
43}
44
45// testMysisID returns a consistent test mysis ID.
46func testMysisID(id int) string {
47	return fmt.Sprintf("mysis-test-%d", id)
48}
49
50// testMysisName returns a consistent test mysis name.
51func testMysisName(id int) string {
52	return fmt.Sprintf("test-mysis-%d", id)
53}
54
55// testTime returns a consistent test timestamp for today at a fixed time.
56// This prevents golden file mismatches from timestamps changing.
57// Returns time for today at 12:00:00 in local timezone.
58func testTime() time.Time {
59	now := time.Now()
60	return time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, time.Local)
61}