Repository navigation
Expand file tree
/
Copy pathConstraintGroupSpec.swift
More file actions
96 lines (70 loc) · 2.56 KB
/
Copy pathConstraintGroupSpec.swift
File metadata and controls
96 lines (70 loc) · 2.56 KB
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
import Cartography
import Nimble
import Quick
class ConstraintGroupSpec: QuickSpec {
override func spec() {
var window: TestWindow!
var view1: TestView!
beforeEach {
window = TestWindow(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
view1 = TestView(frame: CGRect.zero)
window.addSubview(view1)
}
describe("Activating a group") {
var a: ConstraintGroup!
var b: ConstraintGroup!
beforeEach {
a = cg_constrain(view1) { view in
view.width == 100
view.height == 100
}
a.active = false
b = cg_constrain(view1) { view in
view.width == 200
view.height == 200
}
b.active = false
}
it("should update the view") {
a.active = true
view1.layoutIfNeeded()
expect(view1.frame.width).to(equal(100))
expect(view1.frame.height).to(equal(100))
a.active = false
b.active = true
window.layoutIfNeeded()
expect(view1.frame.width).to(equal(200))
expect(view1.frame.height).to(equal(200))
}
}
describe("Replacing constraints") {
var view2: TestView!
beforeEach {
view2 = TestView(frame: CGRect.zero)
window.addSubview(view2)
cg_constrain(view1, view2) { view1, view2 in
view1.top == view1.superview!.top + 10
view1.left == view1.superview!.left + 10
view1.right == view1.superview!.right - 10
view1.height == 200
view2.centerX == view1.centerX
view2.top == view1.bottom
view2.width == view1.width
}
window.layoutIfNeeded()
}
it("should update the view") {
let group = cg_constrain(view2) { view2 in
view2.height == 100
}
window.layoutIfNeeded()
expect(view2.frame.height).to(equal(100))
cg_constrain(view2, replace: group) { view2 in
view2.bottom >= view2.superview!.bottom
}
window.layoutIfNeeded()
expect(view2.frame.height).to(equal(190))
}
}
}
}