This repository has been archived by the owner on Sep 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMakerTests.swift
417 lines (297 loc) · 13.8 KB
/
MakerTests.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
//
// MakerTests.swift
// Framezilla
//
// Created by Nikita on 06/09/16.
// Copyright © 2016 Nikita. All rights reserved.
//
import XCTest
class MakerTests: BaseTest {
/* Array configurator */
func testThatCorrectlyConfiguresFramesForArrayOfViews() {
let label = UILabel(frame: .zero)
let view = UIView(frame: .zero)
[label, view].configureFrames { maker in
maker.width(100)
maker.height(50)
}
XCTAssertEqual(label.frame, CGRect(x: 0, y: 0, width: 100, height: 50))
XCTAssertEqual(view.frame, CGRect(x: 0, y: 0, width: 100, height: 50))
}
/* bottom_to with nui_top */
func testThatCorrectlyConfigures_bottom_to_withAnotherView_top_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_top)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 100, width: 50, height: 50))
}
func testThatCorrectlyConfigures_bottom_to_withAnotherView_top_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_top, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 90, width: 50, height: 50))
}
/* bottom_to with nui_centerY */
func testThatCorrectlyConfigures_bottom_to_withAnotherView_centerY_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_centerY)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 200, width: 50, height: 50))
}
func testThatCorrectlyConfigures_bottom_to_withAnotherView_centerY_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_centerY, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 190, width: 50, height: 50))
}
/* bottom_to with nui_bottom */
func testThatCorrectlyConfigures_bottom_to_withAnotherView_bottom_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_bottom)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 300, width: 50, height: 50))
}
func testThatCorrectlyConfigures_bottom_to_withAnotherView_bottom_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.bottom(to: nestedView2.nui_bottom, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 290, width: 50, height: 50))
}
/* top_to with nui_top */
func testThatCorrectlyConfigures_top_to_withAnotherView_top_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_top)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 150, width: 50, height: 50))
}
func testThatCorrectlyConfigures_top_to_withAnotherView_top_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_top, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 160, width: 50, height: 50))
}
/* top_to with nui_centerY */
func testThatCorrectlyConfigures_top_to_withAnotherView_centerY_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_centerY)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 250, width: 50, height: 50))
}
func testThatCorrectlyConfigures_top_to_withAnotherView_centerY_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_centerY, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 260, width: 50, height: 50))
}
/* top_to with nui_bottom */
func testThatCorrectlyConfigures_top_to_withAnotherView_bottom_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_bottom)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 350, width: 50, height: 50))
}
func testThatCorrectlyConfigures_top_to_withAnotherView_bottom_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.top(to: nestedView2.nui_bottom, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 360, width: 50, height: 50))
}
/* right_to with nui_right */
func testThatCorrectlyConfigures_right_to_withAnotherView_right_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_right)
}
XCTAssertEqual(testingView.frame, CGRect(x: 300, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_right_to_withAnotherView_right_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_right, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 290, y: 0, width: 50, height: 50))
}
/* top_to with nui_centerX */
func testThatCorrectlyConfigures_right_to_withAnotherView_centerX_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_centerX)
}
XCTAssertEqual(testingView.frame, CGRect(x: 200, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_right_to_withAnotherView_centerX_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_centerX, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 190, y: 0, width: 50, height: 50))
}
/* top_to with nui_left */
func testThatCorrectlyConfigures_right_to_withAnotherView_left_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_left)
}
XCTAssertEqual(testingView.frame, CGRect(x: 100, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_right_to_withAnotherView_left_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.right(to: nestedView2.nui_left, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 90, y: 0, width: 50, height: 50))
}
/* left_to with nui_right */
func testThatCorrectlyConfigures_left_to_withAnotherView_right_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_right)
}
XCTAssertEqual(testingView.frame, CGRect(x: 350, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_left_to_withAnotherView_right_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_right, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 360, y: 0, width: 50, height: 50))
}
/* left_to with nui_centerX */
func testThatCorrectlyConfigures_left_to_withAnotherView_centerX_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_centerX)
}
XCTAssertEqual(testingView.frame, CGRect(x: 250, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_left_to_withAnotherView_centerX_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_centerX, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 260, y: 0, width: 50, height: 50))
}
/* left_to with nui_left */
func testThatCorrectlyConfigures_left_to_withAnotherView_left_relationWith_zeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_left)
}
XCTAssertEqual(testingView.frame, CGRect(x: 150, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_left_to_withAnotherView_left_relationWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.left(to: nestedView2.nui_left, inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 160, y: 0, width: 50, height: 50))
}
/* left to superview */
func testThatCorrectlyConfigures_left_toSuperviewWith_zeroInset() {
testingView.configureFrame { maker in
maker.left()
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_left_toSuperviewWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.left(inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 10, y: 0, width: 50, height: 50))
}
/* top to superview */
func testThatCorrectlyConfigures_top_toSuperviewWith_zeroInset() {
testingView.configureFrame { maker in
maker.top()
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_top_toSuperviewWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.top(inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 10, width: 50, height: 50))
}
/* bottom to superview */
func testThatCorrectlyConfigures_bottom_toSuperviewWith_zeroInset() {
testingView.configureFrame { maker in
maker.bottom()
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 450, width: 50, height: 50))
}
func testThatCorrectlyConfigures_bottom_toSuperviewWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.bottom(inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 0, y: 440, width: 50, height: 50))
}
/* right to superview */
func testThatCorrectlyConfigures_right_toSuperviewWith_zeroInset() {
testingView.configureFrame { maker in
maker.right()
}
XCTAssertEqual(testingView.frame, CGRect(x: 450, y: 0, width: 50, height: 50))
}
func testThatCorrectlyConfigures_right_toSuperviewWith_nonZeroInset() {
testingView.configureFrame { maker in
maker.right(inset: 10)
}
XCTAssertEqual(testingView.frame, CGRect(x: 440, y: 0, width: 50, height: 50))
}
/* edges */
func testThatCorrectlyConfigures_margin_relation() {
let inset: CGFloat = 5
testingView.configureFrame { maker in
maker.margin(inset)
}
XCTAssertEqual(testingView.frame, CGRect(x: inset, y: inset, width: 490, height: 490))
}
func testThatCorrectlyConfigures_equal_to_relationForNearSubview() {
let insets = UIEdgeInsetsMake(5, 10, 15, 20)
testingView.configureFrame { maker in
maker.equal(to: nestedView1, insets: insets)
}
XCTAssertEqual(testingView.frame, CGRect(x: nestedView1.frame.minX + insets.left,
y: nestedView1.frame.minY + insets.top,
width: nestedView1.bounds.width-(insets.left + insets.right),
height: nestedView1.bounds.height-(insets.top + insets.bottom)))
}
func testThatCorrectlyConfigures_equal_to_dependsOnSuperview() {
testingView.configureFrame { maker in
maker.equal(to: mainView)
}
XCTAssertEqual(testingView.frame, mainView.frame)
}
func testThatCorrectlyConfigures_edge_insets_toSuperview() {
testingView.configureFrame { maker in
maker.edges(insets: UIEdgeInsetsMake(10, 20, 40, 60))
}
XCTAssertEqual(testingView.frame, CGRect(x: 20, y: 10, width: 420, height: 450))
}
func testThatCorrectlyConfigures_edge_toSuperview() {
testingView.configureFrame { maker in
maker.edges(top: 20, left: 20, bottom: 20, right: 20)
}
XCTAssertEqual(testingView.frame, CGRect(x: 20, y: 20, width: 460, height: 460))
}
/* container */
func testThatCorrectlyConfiguresContainer() {
let view1 = UIView(frame: CGRect(x: 50, y: 50, width: 50, height: 50))
let view2 = UIView(frame: CGRect(x: 70, y: 70, width: 50, height: 50))
let containet = UIView()
containet.addSubview(view1)
containet.addSubview(view2)
containet.configureFrame { maker in
maker.container()
}
XCTAssertEqual(containet.frame, CGRect(x: 0, y: 0, width: 120, height: 120))
}
/* sizeToFit */
func testThat_sizeToFit_correctlyConfigures() {
let label = UILabel()
label.text = "Hello"
label.configureFrame { maker in
maker.sizeToFit()
}
XCTAssertGreaterThan(label.bounds.width, 0)
XCTAssertGreaterThan(label.bounds.height, 0)
}
/* sizeThatFits */
func testThat_sizeThatFits_correctlyConfigures() {
let label = UILabel()
label.text = "HelloHelloHelloHello"
label.configureFrame { maker in
maker.sizeThatFits(size: CGSize(width: 30, height: 0))
}
XCTAssertEqual(label.bounds.width, 30)
XCTAssertEqual(label.bounds.height, 0)
}
}