-
Notifications
You must be signed in to change notification settings - Fork 1
/
had_overflow_test.go
123 lines (102 loc) · 3.29 KB
/
had_overflow_test.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package flex
import (
"testing"
"github.com/stretchr/testify/assert"
)
func newHadOverflowTests() (*Config, *Node) {
config := NewConfig()
root := NewNodeWithConfig(config)
root.StyleSetWidth(200)
root.StyleSetHeight(100)
root.StyleSetFlexDirection(FlexDirectionColumn)
root.StyleSetFlexWrap(WrapNoWrap)
return config, root
}
func TestChildren_overflow_no_wrap_and_no_flex_children(t *testing.T) {
config, root := newHadOverflowTests()
child0 := NewNodeWithConfig(config)
child0.StyleSetWidth(80)
child0.StyleSetHeight(40)
child0.StyleSetMargin(EdgeTop, 10)
child0.StyleSetMargin(EdgeBottom, 15)
root.InsertChild(child0, 0)
child1 := NewNodeWithConfig(config)
child1.StyleSetWidth(80)
child1.StyleSetHeight(40)
child1.StyleSetMargin(EdgeBottom, 5)
root.InsertChild(child1, 1)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.True(t, root.Layout.HadOverflow)
}
func TestSpacing_overflow_no_wrap_and_no_flex_children(t *testing.T) {
config, root := newHadOverflowTests()
child0 := NewNodeWithConfig(config)
child0.StyleSetWidth(80)
child0.StyleSetHeight(40)
child0.StyleSetMargin(EdgeTop, 10)
child0.StyleSetMargin(EdgeBottom, 10)
root.InsertChild(child0, 0)
child1 := NewNodeWithConfig(config)
child1.StyleSetWidth(80)
child1.StyleSetHeight(40)
child1.StyleSetMargin(EdgeBottom, 5)
root.InsertChild(child1, 1)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.True(t, root.Layout.HadOverflow)
}
func TestNo_overflow_no_wrap_and_flex_children(t *testing.T) {
config, root := newHadOverflowTests()
child0 := NewNodeWithConfig(config)
child0.StyleSetWidth(80)
child0.StyleSetHeight(40)
child0.StyleSetMargin(EdgeTop, 10)
child0.StyleSetMargin(EdgeBottom, 10)
root.InsertChild(child0, 0)
child1 := NewNodeWithConfig(config)
child1.StyleSetWidth(80)
child1.StyleSetHeight(40)
child1.StyleSetMargin(EdgeBottom, 5)
child1.StyleSetFlexShrink(1)
root.InsertChild(child1, 1)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.False(t, root.Layout.HadOverflow)
}
func TestHadOverflow_gets_reset_if_not_logger_valid(t *testing.T) {
config, root := newHadOverflowTests()
child0 := NewNodeWithConfig(config)
child0.StyleSetWidth(80)
child0.StyleSetHeight(40)
child0.StyleSetMargin(EdgeTop, 10)
child0.StyleSetMargin(EdgeBottom, 10)
root.InsertChild(child0, 0)
child1 := NewNodeWithConfig(config)
child1.StyleSetWidth(80)
child1.StyleSetHeight(40)
child1.StyleSetMargin(EdgeBottom, 5)
root.InsertChild(child1, 1)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.True(t, root.Layout.HadOverflow)
child1.StyleSetFlexShrink(1)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.False(t, root.Layout.HadOverflow)
}
func TestSpacing_overflow_in_nested_nodes(t *testing.T) {
config, root := newHadOverflowTests()
child0 := NewNodeWithConfig(config)
child0.StyleSetWidth(80)
child0.StyleSetHeight(40)
child0.StyleSetMargin(EdgeTop, 10)
child0.StyleSetMargin(EdgeBottom, 10)
root.InsertChild(child0, 0)
child1 := NewNodeWithConfig(config)
child1.StyleSetWidth(80)
child1.StyleSetHeight(40)
root.InsertChild(child1, 1)
child1_1 := NewNodeWithConfig(config)
child1_1.StyleSetWidth(80)
child1_1.StyleSetHeight(40)
child1_1.StyleSetMargin(EdgeBottom, 5)
child1.InsertChild(child1_1, 0)
CalculateLayout(root, 200, 100, DirectionLTR)
assert.True(t, root.Layout.HadOverflow)
}