-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_test.go
More file actions
62 lines (51 loc) · 2.04 KB
/
layout_test.go
File metadata and controls
62 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package devtui
import (
"fmt"
"testing"
"github.com/charmbracelet/lipgloss"
)
// TestLayoutAlignment verifies that the Header title block and the Footer left block
// (Pagination + Spacer + Label) have exactly the same visual width.
// This ensures vertical alignment of the left column across the UI.
func TestLayoutAlignment(t *testing.T) {
// Setup styles manually to mirror what's being used
palette := DefaultPalette()
style := newTuiStyle(palette)
// --- HEADER CALCULATION ---
// Emulate headerView logic
// The header uses UIColumnWidth to truncate and render
headerText := "TINYWASM/BUILD"
truncatedHeader := fmt.Sprintf("%-*s", UIColumnWidth, headerText)
if len(truncatedHeader) > UIColumnWidth {
truncatedHeader = truncatedHeader[:UIColumnWidth]
}
// Apply style (Padding(0, 1))
headerRendered := style.headerTitleStyle.Render(truncatedHeader)
headerWidth := lipgloss.Width(headerRendered)
// --- FOOTER CALCULATION ---
// Emulate Pagination
// Pagination uses PaginationColumnWidth (10)
paginationText := " 2/ 3" // PaginationColumnWidth = 5
if len(paginationText) != PaginationColumnWidth {
// Ensure test data matches constant if possible, or just force it for the test
paginationText = fmt.Sprintf("%-*s", PaginationColumnWidth, " 1/ 1")
}
paginationRendered := style.paginationStyle.Render(paginationText)
paginationWidth := lipgloss.Width(paginationRendered)
// Spacer
spacerWidth := FooterSpacerWidth
// Label
// Label uses FooterLabelWidth
labelText := "Compiler Mode"
labelTruncated := fmt.Sprintf("%-*s", FooterLabelWidth, labelText)
if len(labelTruncated) > FooterLabelWidth {
labelTruncated = labelTruncated[:FooterLabelWidth]
}
// Footer Label uses headerTitleStyle (same as header)
labelRendered := style.headerTitleStyle.Render(labelTruncated)
labelWidth := lipgloss.Width(labelRendered)
totalFooterLeftWidth := paginationWidth + spacerWidth + labelWidth
if headerWidth != totalFooterLeftWidth {
t.Errorf("MISALIGNMENT: Header width (%d) != Footer width (%d)", headerWidth, totalFooterLeftWidth)
}
}