-
Notifications
You must be signed in to change notification settings - Fork 36
/
DemoTests.swift
96 lines (82 loc) · 3.77 KB
/
DemoTests.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
import Hammer
import UIKit
import XCTest
import MapKit
/// These are skipped by default because they're too slow
private let kSkipDemoTests = true
private let kMapDefaultCoordinate = CLLocationCoordinate2D(latitude: 37.773972, longitude: -122.431297)
private let kMapDefaultCoordinateDistance = CLLocationDistance(100000)
private let kMapDefaultCamera = MKMapCamera(lookingAtCenter: kMapDefaultCoordinate,
fromDistance: kMapDefaultCoordinateDistance,
pitch: 0, heading: 0)
/// These tests are used to generate the recording for the readme, too slow for normal testing
final class DemoTests: XCTestCase {
func testASwitchToggleOnOff() throws {
try XCTSkipIf(kSkipDemoTests, "Demo tests are disabled")
let view = UISwitch()
let eventGenerator = try EventGenerator(view: view)
try eventGenerator.waitUntilHittable(timeout: 1)
try eventGenerator.wait(0.5)
XCTAssertEqual(view.isOn, false)
try eventGenerator.fingerDown(at: view.frame.center.offset(x: -20, y: 0))
try eventGenerator.fingerMove(to: view.frame.center.offset(x: 20, y: 0), duration: 1)
try eventGenerator.fingerUp()
XCTAssertEqual(view.isOn, true)
try eventGenerator.fingerDown(at: view.frame.center.offset(x: 20, y: 0))
try eventGenerator.fingerMove(to: view.frame.center.offset(x: -40, y: 0), duration: 1)
try eventGenerator.fingerUp()
XCTAssertEqual(view.isOn, false)
try eventGenerator.wait(1)
}
func testBTypeOnTextField() throws {
try XCTSkipIf(kSkipDemoTests, "Demo tests are disabled")
let view = UITextField()
view.textAlignment = .center
view.autocapitalizationType = .none
view.setSize(width: 300)
let eventGenerator = try EventGenerator(view: view)
try eventGenerator.waitUntilHittable(timeout: 1)
try eventGenerator.wait(0.5)
view.becomeFirstResponder()
XCTAssertEqual(view.isFirstResponder, true)
let text1 = "I can type in a text field!"
let text2 = "Symbols too! @#$%"
try eventGenerator.keyType(text1)
try eventGenerator.wait(0.5)
try eventGenerator.keyPress(.deleteOrBackspace, numberOfTimes: text1.count)
try eventGenerator.keyType(text2)
try eventGenerator.wait(0.5)
}
func testCMapDrag() throws {
try XCTSkipIf(kSkipDemoTests, "Demo tests are disabled")
let view = MapView()
view.setSize(width: 600, height: 300)
let eventGenerator = try EventGenerator(view: view)
try eventGenerator.waitUntilHittable(timeout: 1)
try eventGenerator.wait(0.5)
try eventGenerator.fingerDrag(from: view.frame.center.offset(x: -20, y: -100),
to: view.frame.center.offset(x: 20, y: 100),
duration: 1)
try eventGenerator.wait(0.5)
try eventGenerator.fingerPinchOpen(at: view.frame.center, duration: 2)
try eventGenerator.wait(0.5)
try eventGenerator.fingerPinchClose(at: view.frame.center, duration: 2)
try eventGenerator.wait(0.5)
try eventGenerator.fingerRotate(at: view.frame.center, angle: .pi/2, duration: 2)
try eventGenerator.wait(0.5)
try eventGenerator.fingerRotate(at: view.frame.center, angle: -.pi, duration: 2)
try eventGenerator.wait(0.5)
}
}
private final class MapView: MKMapView {
init() {
super.init(frame: .zero)
self.showsCompass = false
self.showsUserLocation = false
self.setCamera(kMapDefaultCamera, animated: false)
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}