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
import XCTest
extension OldFellaUITests {
func testImageViewerShortFlickDismisses() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1", "-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: 60)),
withVelocity: .fast,
thenHoldForDuration: 0
)
let viewerDismissed = XCTNSPredicateExpectation(
predicate: NSPredicate(format: "exists == false"),
object: close
)
XCTAssertEqual(XCTWaiter.wait(for: [viewerDismissed], timeout: 5), .completed)
XCTAssertTrue(grid.exists)
}
func testImageViewerFlickDismissalDependsOnDirectionAndZoom() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1", "-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))
for zoomed in [false, true] {
for offset in [
CGVector(dx: 0, dy: -75), CGVector(dx: 0, dy: 75),
CGVector(dx: -75, dy: 0), CGVector(dx: 75, dy: 0)
] {
grid.buttons["Attached image"].tap()
let close = app.buttons["imageViewerClose"]
let image = app.descendants(matching: .any)["imageViewerImage"].firstMatch
let viewport = app.scrollViews.containing(.any, identifier: "imageViewerImage").firstMatch
XCTAssertTrue(close.waitForExistence(timeout: 5))
XCTAssertTrue(image.waitForExistence(timeout: 5))
if zoomed {
image.pinch(withScale: 2, velocity: 1)
XCTAssertNotEqual(image.value as? String, "100%")
}
let start = viewport.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
start.press(
forDuration: 0.01, thenDragTo: start.withOffset(offset), withVelocity: .fast, thenHoldForDuration: 0
)
let shouldDismiss = !zoomed || offset.dx == 0
XCTAssertEqual(
close.waitForNonExistence(timeout: shouldDismiss ? 5 : 1), shouldDismiss,
"Zoomed: \(zoomed), offset: \(offset)")
if !shouldDismiss && close.exists {
XCTAssertTrue(image.isHittable)
XCTAssertNotEqual(image.value as? String, "100%")
close.tap()
XCTAssertTrue(close.waitForNonExistence(timeout: 5))
}
if close.exists { return }
}
}
}
func testImageGridWithOneImage() {
assertImageGrid(imageCount: 1, expectedColumnCount: 1)
}
func testImageGridWithThreeImages() {
assertImageGrid(imageCount: 3, expectedColumnCount: 2)
}
func testImageGridWithSevenImages() {
assertImageGrid(imageCount: 7, expectedColumnCount: 4)
}
func testImageGridWithTenImages() {
assertImageGrid(imageCount: 10, expectedColumnCount: 5)
}
func assertImageGrid(imageCount: Int, expectedColumnCount: Int) {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "\(imageCount)"]
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))
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
XCTAssertFalse(grid.buttons["showMoreImagesButton"].exists)
let images = (1...imageCount).map { index in
let imageLabel = imageCount == 1 ? "Attached image" : "Attached image \(index) of \(imageCount)"
return grid.buttons[imageLabel]
}
for image in images {
XCTAssertTrue(image.waitForExistence(timeout: 5))
XCTAssertGreaterThan(image.frame.width, 0)
XCTAssertGreaterThan(image.frame.height, 0)
XCTAssertGreaterThanOrEqual(image.frame.minX, grid.frame.minX - 1)
XCTAssertGreaterThanOrEqual(image.frame.minY, grid.frame.minY - 1)
XCTAssertLessThanOrEqual(image.frame.maxX, grid.frame.maxX + 1)
XCTAssertLessThanOrEqual(image.frame.maxY, grid.frame.maxY + 1)
}
let attachedImages = grid.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Attached image"))
XCTAssertEqual(attachedImages.count, imageCount)
let firstRowY = images[0].frame.minY
let firstRowCount = images.filter { abs($0.frame.minY - firstRowY) < 2 }.count
XCTAssertEqual(firstRowCount, expectedColumnCount)
}
func openPadActions(_ app: XCUIApplication) {
let toggle = app.buttons["togglePadActionsButton"]
XCTAssertTrue(toggle.waitForExistence(timeout: 10))
if !app.buttons["addFeedColumnButton"].exists { toggle.tap() }
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 5))
}
}