forked from ashfurrow/Nimble-Snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicSizeTests.swift
142 lines (119 loc) · 6.16 KB
/
DynamicSizeTests.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
import Quick
import Nimble
import Nimble_Snapshots
import Bootstrap
class DynamicSizeTests: QuickSpec {
override func spec() {
describe("in some context", {
var view: UIView!
let sizes = ["SmallSize": CGSize(width: 44, height: 44),
"MediumSize": CGSize(width: 88, height: 88),
"LargeSize": CGSize(width: 132, height: 132)]
beforeEach {
setNimbleTolerance(0)
setNimbleTestFolder("tests")
}
context("using only frame") {
var view: UIView!
beforeEach {
view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = UIColor.blueColor()
}
it("has a valid snapshot to all sizes") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes))
}
it("has a valid snapshot to all sizes (using == operator)") {
expect(view) == snapshot(sizes: sizes)
// expect(view) == recordSnapshot(sizes: sizes)
}
}
context("using new constrains") {
beforeEach {
view = UIView()
view.backgroundColor = UIColor.blueColor()
view.autoresizingMask = []
view.translatesAutoresizingMaskIntoConstraints = false
}
it("has a valid snapshot to all sizes") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, resizeMode: .constrains))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, resizeMode: .constrains))
}
it("has a valid snapshot to all sizes (using == operator)") {
expect(view) == snapshot(sizes: sizes, resizeMode: .constrains)
// expect(view) == recordSnapshot(sizes: sizes, resizeMode: .constrains)
}
}
context("using constrains from view") {
beforeEach {
view = UIView()
view.backgroundColor = UIColor.blueColor()
view.autoresizingMask = []
view.translatesAutoresizingMaskIntoConstraints = false
view.widthAnchor.constraintEqualToConstant(10).active = true
view.heightAnchor.constraintEqualToConstant(10).active = true
}
it("has a valid snapshot to all sizes") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, resizeMode: .constrains))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, resizeMode: .constrains))
}
it("has a valid snapshot to all sizes (using == operator)") {
expect(view) == snapshot(sizes: sizes, resizeMode: .constrains)
// expect(view) == recordSnapshot(sizes: sizes, resizeMode: .constrains)
}
}
context("using block") {
beforeEach {
view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = UIColor.blueColor()
}
it("has a valid snapshot to all sizes") {
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, resizeMode: .block(resizeBlock: { (view, size) in
view.frame = CGRect(origin: CGPoint.zero, size: size)
view.layoutIfNeeded()
})))
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, resizeMode: .block(resizeBlock: { (view, size) in
// view.frame = CGRect(origin: CGPoint.zero, size: size)
// view.layoutIfNeeded()
// })))
}
it("has a valid snapshot to all sizes (using == operator)") {
expect(view) == snapshot(sizes: sizes, resizeMode: .block(resizeBlock: { (view, size) in
view.frame = CGRect(origin: CGPoint.zero, size: size)
view.layoutIfNeeded()
}))
// expect(view) == recordSnapshot(sizes: sizes, resizeMode: .block(resizeBlock: { (view, size) in
// view.frame = CGRect(origin: CGPoint.zero, size: size)
// view.layoutIfNeeded()
// }))
}
}
context("using custom resizer") {
beforeEach {
view = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
view.backgroundColor = UIColor.blueColor()
}
it("has a valid snapshot to all sizes") {
let resizer = CustomResizer()
expect(view).to(haveValidDynamicSizeSnapshot(sizes: sizes, resizeMode: .custom(ViewResizer: resizer)))
expect(resizer.used) == 3
// expect(view).to(recordDynamicSizeSnapshot(sizes: sizes, resizeMode: .custom(ViewResizer: resizer)))
}
it("has a valid snapshot to all sizes (using == operator)") {
let resizer = CustomResizer()
expect(view) == snapshot(sizes: sizes, resizeMode: .custom(ViewResizer: resizer))
expect(resizer.used) == 3
// expect(view) == recordSnapshot(sizes: sizes, resizeMode: .custom(ViewResizer: resizer))
}
}
})
}
}
class CustomResizer: ViewResizer {
var used = 0
func resize(view view: UIView, for size: CGSize) {
view.frame = CGRect(origin: CGPoint.zero, size: size)
view.layoutIfNeeded()
used += 1
}
}