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
import XCTest
extension OldFellaUITests {
func testImageViewerOpensSelectedImageZoomsAndDismisses() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
let selectedGridImage = grid.buttons["Attached image 2 of 3"].firstMatch
XCTAssertTrue(selectedGridImage.waitForExistence(timeout: 5))
selectedGridImage.tap()
let viewer = app.buttons["imageViewerClose"]
XCTAssertTrue(viewer.waitForExistence(timeout: 5))
let viewerImage = app.descendants(matching: .any)["imageViewerImage"]
XCTAssertTrue(viewerImage.waitForExistence(timeout: 5))
XCTAssertTrue(viewerImage.label.contains("2 of 3"), viewerImage.label)
viewerImage.pinch(withScale: 2, velocity: 1)
XCTAssertTrue(viewerImage.exists)
XCTAssertTrue(viewerImage.label.contains("2 of 3"), viewerImage.label)
app.buttons["imageViewerClose"].tap()
let viewerDismissed = XCTNSPredicateExpectation(
predicate: NSPredicate(format: "exists == false"),
object: viewer
)
XCTAssertEqual(XCTWaiter.wait(for: [viewerDismissed], timeout: 5), .completed)
XCTAssertTrue(grid.exists)
XCTAssertTrue(grid.buttons["Attached image 1 of 3"].firstMatch.exists)
XCTAssertTrue(grid.buttons["Attached image 2 of 3"].firstMatch.exists)
XCTAssertTrue(grid.buttons["Attached image 3 of 3"].firstMatch.exists)
}
func testImageViewerSwipesBetweenImages() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"
].firstMatch
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.buttons["Attached image 2 of 3"].firstMatch.tap()
let second = app.images["Image 2 of 3"].firstMatch
XCTAssertTrue(second.waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["imageDescriptionButton"].firstMatch.isHittable)
second.swipeLeft()
let third = app.images["Image 3 of 3"].firstMatch
XCTAssertTrue(third.waitForExistence(timeout: 5))
XCTAssertTrue(third.isHittable)
third.swipeRight()
XCTAssertTrue(second.waitForExistence(timeout: 5))
XCTAssertTrue(second.isHittable)
second.swipeRight()
let first = app.images["Image 1 of 3"].firstMatch
XCTAssertTrue(first.waitForExistence(timeout: 5))
XCTAssertTrue(first.isHittable)
XCTAssertTrue(app.buttons["imageDescriptionButton"].firstMatch.isHittable)
let close = app.buttons["imageViewerClose"]
let start = first.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(
forDuration: 0.01, thenDragTo: start.withOffset(CGVector(dx: 75, dy: 0)), withVelocity: .fast,
thenHoldForDuration: 0)
let viewerDismissed = XCTNSPredicateExpectation(
predicate: NSPredicate(format: "exists == false"),
object: close
)
XCTAssertEqual(XCTWaiter.wait(for: [viewerDismissed], timeout: 5), .completed)
}
func testImageViewerShowsDescriptionWithButton() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"
].firstMatch
XCTAssertTrue(grid.waitForExistence(timeout: 5))
let tile = grid.descendants(matching: .any)["postImageTile-1"].firstMatch
XCTAssertTrue(tile.waitForExistence(timeout: 5))
XCTAssertEqual(tile.value as? String, "A blue square.")
tile.tap()
let image = app.descendants(matching: .any)["imageViewerImage"].firstMatch
XCTAssertTrue(image.waitForExistence(timeout: 5))
image.tap()
XCTAssertFalse(app.staticTexts["A blue square."].exists)
let button = app.buttons["imageDescriptionButton"].firstMatch
XCTAssertTrue(button.waitForExistence(timeout: 5))
button.tap()
XCTAssertTrue(app.staticTexts["A blue square."].waitForExistence(timeout: 5))
button.tap()
XCTAssertFalse(app.staticTexts["A blue square."].exists)
}
func testImageViewerShortDownwardDragKeepsViewerOpen() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.buttons["Attached image"].tap()
let close = app.buttons["imageViewerClose"]
let viewerImage = app.descendants(matching: .any)["imageViewerImage"]
XCTAssertTrue(close.waitForExistence(timeout: 5))
XCTAssertTrue(viewerImage.waitForExistence(timeout: 5))
let originalFrame = viewerImage.frame
let start = viewerImage.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(
forDuration: 0.1,
thenDragTo: start.withOffset(CGVector(dx: 0, dy: 45)),
withVelocity: .slow,
thenHoldForDuration: 0
)
XCTAssertTrue(viewerImage.exists)
XCTAssertEqual(viewerImage.frame.midX, originalFrame.midX, accuracy: 2)
XCTAssertEqual(viewerImage.frame.midY, originalFrame.midY, accuracy: 2)
XCTAssertTrue(close.exists)
XCTAssertTrue(close.isHittable)
}
func testImageViewerZoomAndPanStayOpen() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.buttons["Attached image 2 of 3"].firstMatch.tap()
let close = app.buttons["imageViewerClose"]
let viewerImage = app.descendants(matching: .any)["imageViewerImage"]
XCTAssertTrue(close.waitForExistence(timeout: 5))
XCTAssertTrue(viewerImage.waitForExistence(timeout: 5))
XCTAssertEqual(viewerImage.value as? String, "100%")
viewerImage.pinch(withScale: 2, velocity: 1)
XCTAssertNotEqual(viewerImage.value as? String, "100%", "Pinching must enlarge the image")
let start = viewerImage.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(
forDuration: 0.1, thenDragTo: start.withOffset(CGVector(dx: 100, dy: 0)), withVelocity: .slow,
thenHoldForDuration: 0)
start.press(
forDuration: 0.1, thenDragTo: start.withOffset(CGVector(dx: 0, dy: 180)), withVelocity: .slow,
thenHoldForDuration: 0)
XCTAssertTrue(viewerImage.exists)
XCTAssertTrue(close.exists)
XCTAssertTrue(close.isHittable)
}
func testImageViewerDownwardFlickDismisses() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
"postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.buttons["Attached image"].tap()
let close = app.buttons["imageViewerClose"]
let viewport = app.scrollViews.containing(.any, identifier: "imageViewerImage").firstMatch
XCTAssertTrue(close.waitForExistence(timeout: 5))
XCTAssertTrue(viewport.waitForExistence(timeout: 5))
let start = viewport.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(forDuration: 0.01, thenDragTo: start.withOffset(CGVector(dx: 0, dy: 180)))
let viewerDismissed = XCTNSPredicateExpectation(
predicate: NSPredicate(format: "exists == false"),
object: close
)
XCTAssertEqual(XCTWaiter.wait(for: [viewerDismissed], timeout: 5), .completed)
XCTAssertTrue(grid.exists)
}
}