1package ui
2
3import (
4 "testing"
5
6 "github.com/bnema/vev/internal/domain"
7 "github.com/stretchr/testify/require"
8)
9
10func TestResolvePresentation(t *testing.T) {
11 tests := []struct {
12 name string
13 base domain.Size
14 bounds, inner domain.Rect
15 want Presentation
16 }{
17 {
18 name: "79 columns becomes full-width drawer",
19 base: domain.Size{Cols: 79, Rows: 24},
20 bounds: domain.Rect{X: 8, Y: 6, Width: 63, Height: 11},
21 inner: domain.Rect{X: 9, Y: 7, Width: 61, Height: 9},
22 want: Presentation{
23 Mode: PresentationDrawer,
24 Bounds: domain.Rect{X: 0, Y: 12, Width: 79, Height: 11},
25 Inner: domain.Rect{X: 0, Y: 13, Width: 79, Height: 10},
26 Borders: BorderTop,
27 },
28 },
29 {
30 name: "80 columns preserves preferred geometry",
31 base: domain.Size{Cols: 80, Rows: 24},
32 bounds: domain.Rect{X: 8, Y: 3, Width: 64, Height: 18},
33 inner: domain.Rect{X: 9, Y: 4, Width: 62, Height: 16},
34 want: Presentation{
35 Mode: PresentationFloating,
36 Bounds: domain.Rect{X: 8, Y: 3, Width: 64, Height: 18},
37 Inner: domain.Rect{X: 9, Y: 4, Width: 62, Height: 16},
38 Borders: BorderAll,
39 },
40 },
41 {
42 name: "100 percent height preserves three rows and bottom bar",
43 base: domain.Size{Cols: 79, Rows: 24},
44 bounds: domain.Rect{Width: 79, Height: 24},
45 inner: domain.Rect{X: 1, Y: 1, Width: 77, Height: 22},
46 want: Presentation{
47 Mode: PresentationDrawer,
48 Bounds: domain.Rect{X: 0, Y: 3, Width: 79, Height: 20},
49 Inner: domain.Rect{X: 0, Y: 4, Width: 79, Height: 19},
50 Borders: BorderTop,
51 },
52 },
53 {
54 name: "preferred height larger than available is capped",
55 base: domain.Size{Cols: 79, Rows: 10},
56 bounds: domain.Rect{X: -100, Y: -100, Width: 1000, Height: 1000},
57 inner: domain.Rect{X: -99, Y: -99, Width: 998, Height: 998},
58 want: Presentation{
59 Mode: PresentationDrawer,
60 Bounds: domain.Rect{X: 0, Y: 3, Width: 79, Height: 6},
61 Inner: domain.Rect{X: 0, Y: 4, Width: 79, Height: 5},
62 Borders: BorderTop,
63 },
64 },
65 {
66 name: "negative preferred height becomes empty drawer",
67 base: domain.Size{Cols: 79, Rows: 24},
68 bounds: domain.Rect{Height: -1},
69 inner: domain.Rect{Height: -3},
70 want: Presentation{
71 Mode: PresentationDrawer,
72 Bounds: domain.Rect{X: 0, Y: 23, Width: 79, Height: 0},
73 Inner: domain.Rect{X: 0, Y: 23, Width: 79, Height: 0},
74 Borders: BorderTop,
75 },
76 },
77 {
78 name: "four-row terminal reserves all protected rows",
79 base: domain.Size{Cols: 79, Rows: 4},
80 bounds: domain.Rect{Width: 79, Height: 4},
81 inner: domain.Rect{X: 1, Y: 1, Width: 77, Height: 2},
82 want: Presentation{
83 Mode: PresentationDrawer,
84 Bounds: domain.Rect{X: 0, Y: 3, Width: 79},
85 Inner: domain.Rect{X: 0, Y: 3, Width: 79},
86 Borders: BorderTop,
87 },
88 },
89 {
90 name: "one-row terminal is panic-free and empty",
91 base: domain.Size{Cols: 1, Rows: 1},
92 bounds: domain.Rect{Width: 1, Height: 1},
93 inner: domain.Rect{X: 1, Y: 1},
94 want: Presentation{
95 Mode: PresentationDrawer,
96 Bounds: domain.Rect{X: 0, Y: 0, Width: 1},
97 Inner: domain.Rect{X: 0, Y: 0, Width: 1},
98 Borders: BorderTop,
99 },
100 },
101 {name: "zero frame is empty", base: domain.Size{}, want: Presentation{}},
102 {name: "negative columns are empty", base: domain.Size{Cols: -1, Rows: 24}, want: Presentation{}},
103 {name: "negative rows are empty", base: domain.Size{Cols: 79, Rows: -1}, want: Presentation{}},
104 }
105
106 for _, tt := range tests {
107 t.Run(tt.name, func(t *testing.T) {
108 require.Equal(t, tt.want, ResolvePresentation(tt.base, tt.bounds, tt.inner))
109 })
110 }
111}