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
|
package tui
import "testing"
func TestWithOverlay_SetsField(t *testing.T) {
e := New(WithOverlay(true))
if !e.IsOverlay() {
t.Error("expected overlay to be true")
}
e2 := New(WithOverlay(false))
if e2.IsOverlay() {
t.Error("expected overlay to be false")
}
}
func TestLayoutChildren_ExcludesOverlay(t *testing.T) {
parent := New()
normal := New(WithText("visible"))
overlay := New(WithOverlay(true), WithText("overlay"))
parent.AddChild(normal)
parent.AddChild(overlay)
children := parent.LayoutChildren()
if len(children) != 1 {
t.Fatalf("expected 1 layout child, got %d", len(children))
}
}
func TestRenderElement_SkipsOverlayChildren(t *testing.T) {
parent := New(WithWidth(20), WithHeight(3))
normal := New(WithText("visible"))
overlay := New(WithOverlay(true), WithText("hidden"))
parent.AddChild(normal)
parent.AddChild(overlay)
buf := NewBuffer(20, 3)
parent.Render(buf, 20, 3)
content := buf.String()
if !containsSubstring(content, "visible") {
t.Error("expected normal child to be rendered")
}
if containsSubstring(content, "hidden") {
t.Error("expected overlay child to NOT be rendered")
}
}
func TestApply_SetsOptions(t *testing.T) {
e := New()
e.Apply(WithOverlay(true), WithHidden(true))
if !e.IsOverlay() {
t.Error("expected overlay after Apply")
}
if !e.Hidden() {
t.Error("expected hidden after Apply")
}
}
|