-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathWidthSizeContentTests.swift
211 lines (169 loc) · 7.51 KB
/
WidthSizeContentTests.swift
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import FlexLayout
import XCTest
final class WidthSizeContentTests: XCTestCase {
var viewController: UIViewController!
var rootFlexContainer: UIView!
var aView: UIView!
var bView: UIView!
var cView: UIView!
override func setUp() {
super.setUp()
viewController = UIViewController()
rootFlexContainer = UIView()
rootFlexContainer.frame = CGRect(x: 0, y: 0, width: 400, height: 400)
viewController.view.addSubview(rootFlexContainer)
aView = UIView()
bView = UIView()
cView = UIView()
}
func test_basis_adjust_aView_size_and_position() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(100).height(200)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 100.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_aspectRatio() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).aspectRatio(2)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 100.0))
}
func test_basis_adjust_aView_size_and_position_with_aspectRatio_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).aspectRatio(2)
}
// Later reset the aspectRatio
aView.flex.aspectRatio(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 0.0))
}
func test_basis_adjust_aView_size_and_position_with_width_height() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_width_height_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).minWidth(100).height(200).minHeight(100)
}
// Later reset the width and the height
aView.flex.width(nil)
aView.flex.height(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0))
}
func test_basis_adjust_aView_size_and_position_with_minWidth() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).minWidth(300).height(200)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_minWidth_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).width(200).maxWidth(300).height(200)
}
// Later reset the minWidth
aView.flex.minWidth(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_maxWidth() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).maxWidth(300).height(200)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_maxWidth_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).maxWidth(300).height(200)
}
// Later reset the width and the height
aView.flex.maxWidth(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_minHeight() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).height(200).minHeight(300)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 300.0))
}
func test_basis_adjust_aView_size_and_position_with_minHeight_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).height(200).minHeight(300)
}
// Later reset the minHeight
aView.flex.minHeight(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))
}
func test_basis_adjust_aView_size_and_position_with_maxHeight() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).height(200).maxHeight(100)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 100.0))
}
func test_basis_adjust_aView_size_and_position_with_maxHeight_reset() {
rootFlexContainer.flex.define { flex in
flex.addItem(aView).height(200).maxHeight(100)
}
// Later reset the maxHeight
aView.flex.maxHeight(nil)
rootFlexContainer.flex.layout()
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))
}
func test_row_gap() {
rootFlexContainer.flex.direction(.row).define { flex in
flex.addItem(aView).height(100).width(100)
flex.addItem(bView).height(100).width(100)
flex.alignItems(.start)
flex.columnGap(50)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0))
}
func test_column_gap() {
rootFlexContainer.flex.direction(.column).define { flex in
flex.addItem(aView).height(100).width(100)
flex.addItem(bView).height(100).width(100)
flex.alignItems(.start)
flex.rowGap(50)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0))
}
func test_gap() {
rootFlexContainer.flex.direction(.column).define { flex in
flex.addItem().direction(.row).define { flex in
flex.addItem(aView).height(100).width(100)
flex.addItem(bView).height(100).width(100)
flex.gap(50)
}
flex.addItem(cView).height(100).width(100)
flex.alignItems(.start)
flex.gap(50)
}
rootFlexContainer.flex.layout()
XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0))
XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0))
}
}