Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 7e506cc

Browse files
authored
Fix pre-iOS 11 unit test failure. (#89)
1 parent 573b192 commit 7e506cc

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

tests/unit/QuartzCoreBehavioralTests.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ import MotionAnimator
2424
class QuartzCoreBehavioralTests: XCTestCase {
2525
var layer: CAShapeLayer!
2626

27+
var window: UIWindow!
2728
var originalImplementation: IMP?
2829
override func setUp() {
2930
super.setUp()
3031

31-
let window = UIWindow()
32+
window = UIWindow()
3233
window.makeKeyAndVisible()
33-
layer = CAShapeLayer()
34-
window.layer.addSublayer(layer)
35-
36-
rebuildLayer()
3734
}
3835

3936
override func tearDown() {
@@ -43,10 +40,8 @@ class QuartzCoreBehavioralTests: XCTestCase {
4340
}
4441

4542
private func rebuildLayer() {
46-
let oldSuperlayer = layer.superlayer!
47-
layer.removeFromSuperlayer()
4843
layer = CAShapeLayer()
49-
oldSuperlayer.addSublayer(layer)
44+
window.layer.addSublayer(layer)
5045

5146
// Connect our layers to the render server.
5247
CATransaction.flush()

tests/unit/UIKitBehavioralTests.swift

+26-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ class UIKitBehavioralTests: XCTestCase {
7070
// MARK: Each animatable property needs to be added to exactly one of the following three tests
7171

7272
func testSomePropertiesImplicitlyAnimateAdditively() {
73-
let properties: [AnimatableKeyPath: Any] = [
73+
let baselineProperties: [AnimatableKeyPath: Any] = [
7474
.bounds: CGRect(x: 0, y: 0, width: 123, height: 456),
75-
.cornerRadius: 3,
7675
.height: 100,
7776
.position: CGPoint(x: 50, y: 20),
7877
.rotation: 42,
@@ -82,6 +81,15 @@ class UIKitBehavioralTests: XCTestCase {
8281
.x: 12,
8382
.y: 23,
8483
]
84+
let properties: [AnimatableKeyPath: Any]
85+
if #available(iOS 11.0, *) {
86+
// Corner radius became implicitly animatable in iOS 11.
87+
var baselineWithCornerRadiusProperties = baselineProperties
88+
baselineWithCornerRadiusProperties[.cornerRadius] = 3
89+
properties = baselineWithCornerRadiusProperties
90+
} else {
91+
properties = baselineProperties
92+
}
8593
for (keyPath, value) in properties {
8694
rebuildView()
8795

@@ -103,11 +111,11 @@ class UIKitBehavioralTests: XCTestCase {
103111
}
104112

105113
func testSomePropertiesImplicitlyAnimateButNotAdditively() {
106-
let properties: [AnimatableKeyPath: Any] = [
114+
let baselineProperties: [AnimatableKeyPath: Any] = [
107115
.backgroundColor: UIColor.blue,
108116
.opacity: 0.5,
109117
]
110-
for (keyPath, value) in properties {
118+
for (keyPath, value) in baselineProperties {
111119
rebuildView()
112120

113121
UIView.animate(withDuration: 0.01) {
@@ -128,13 +136,26 @@ class UIKitBehavioralTests: XCTestCase {
128136
}
129137

130138
func testSomePropertiesDoNotImplicitlyAnimate() {
131-
let properties: [AnimatableKeyPath: Any] = [
139+
let baselineProperties: [AnimatableKeyPath: Any] = [
140+
.cornerRadius: 3,
132141
.shadowOffset: CGSize(width: 1, height: 1),
133142
.shadowOpacity: 0.3,
134143
.shadowRadius: 5,
135144
.strokeStart: 0.2,
136145
.strokeEnd: 0.5,
137146
]
147+
148+
let properties: [AnimatableKeyPath: Any]
149+
if #available(iOS 11.0, *) {
150+
// Corner radius became implicitly animatable in iOS 11.
151+
var baselineWithOutCornerRadius = baselineProperties
152+
baselineWithOutCornerRadius.removeValue(forKey: .cornerRadius)
153+
properties = baselineWithOutCornerRadius
154+
155+
} else {
156+
properties = baselineProperties
157+
}
158+
138159
for (keyPath, value) in properties {
139160
rebuildView()
140161

0 commit comments

Comments
 (0)