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
import XCTest
final class PadDetailNavigationTests: XCTestCase {
func testPostAndProfileOpenToTheRightOfTheirSource() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = launchApp()
let following = app.navigationBars["Following"]
let post = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(post.waitForExistence(timeout: 10))
post.tap()
let postBar = app.navigationBars["Post"]
XCTAssertTrue(postBar.waitForExistence(timeout: 5))
waitForVisibleColumn(postBar, in: app)
XCTAssertTrue(following.exists)
XCTAssertGreaterThan(postBar.frame.minX, following.frame.minX)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
XCTAssertFalse(postBar.buttons["Following"].exists)
let postColumn = detailColumn(in: app, navigationBar: postBar)
postColumn.buttons["profileLink-mae"].firstMatch.tap()
let profileBar = app.navigationBars["Profile"]
XCTAssertTrue(profileBar.waitForExistence(timeout: 5))
waitForVisibleColumn(profileBar, in: app)
XCTAssertTrue(postBar.exists)
XCTAssertGreaterThan(profileBar.frame.minX, postBar.frame.minX)
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertFalse(profileBar.buttons["Post"].exists)
let screenshot = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
screenshot.name = "Post and profile columns"
screenshot.lifetime = .keepAlways
add(screenshot)
closeButton(in: profileBar).tap()
XCTAssertTrue(profileBar.waitForNonExistence(timeout: 5))
XCTAssertTrue(postBar.exists)
closeButton(in: postBar).tap()
XCTAssertTrue(postBar.waitForNonExistence(timeout: 5))
XCTAssertTrue(following.exists)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
}
func testNotificationPostOpensInTheNextColumn() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = launchApp()
let notification = app.buttons["notificationPost-notification-1"]
XCTAssertTrue(notification.waitForExistence(timeout: 10))
notification.tap()
let postBar = app.navigationBars["Post"]
XCTAssertTrue(postBar.waitForExistence(timeout: 5))
let notifications = app.navigationBars["Notifications"]
XCTAssertTrue(notifications.exists)
XCTAssertGreaterThan(postBar.frame.minX, notifications.frame.minX)
XCTAssertFalse(postBar.buttons["Notifications"].exists)
XCTAssertTrue(closeButton(in: postBar).exists)
}
func testProfileConnectionsAndListedProfileOpenToTheRight() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = launchApp()
let mae = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(mae.waitForExistence(timeout: 10))
mae.tap()
let profileBar = app.navigationBars["Profile"].firstMatch
XCTAssertTrue(profileBar.waitForExistence(timeout: 5))
waitForVisibleColumn(profileBar, in: app)
let followers = detailColumn(in: app, navigationBar: profileBar).buttons["profile-followers"]
XCTAssertTrue(followers.waitForExistence(timeout: 5))
followers.tap()
let followersBar = app.navigationBars["Followers"]
XCTAssertTrue(followersBar.waitForExistence(timeout: 5))
waitForVisibleColumn(followersBar, in: app)
let alex = detailColumn(in: app, navigationBar: followersBar).buttons["profileConnection-alex"]
XCTAssertTrue(alex.waitForExistence(timeout: 5))
alex.tap()
let destinationBar = app.navigationBars.matching(identifier: "Profile").element(boundBy: 1)
XCTAssertTrue(destinationBar.waitForExistence(timeout: 5))
waitForVisibleColumn(destinationBar, in: app)
XCTAssertGreaterThan(destinationBar.frame.minX, followersBar.frame.minX)
let name = detailColumn(in: app, navigationBar: destinationBar).staticTexts["profileDisplayName"]
XCTAssertTrue(name.waitForExistence(timeout: 5))
XCTAssertEqual(name.label, "Alex Kim")
}
func testPortraitKeepsNavigationInTheSourceColumn() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .portrait
let app = launchApp()
let post = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(post.waitForExistence(timeout: 10))
post.tap()
let postBar = app.navigationBars["Post"]
XCTAssertTrue(postBar.waitForExistence(timeout: 5))
XCTAssertTrue(postBar.buttons["Following"].exists)
XCTAssertFalse(closeButton(in: postBar).exists)
}
func testSearchResultOpensAProfileColumn() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
continueAfterFailure = false
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = launchApp()
let actions = app.buttons["togglePadActionsButton"]
XCTAssertTrue(actions.waitForExistence(timeout: 10))
actions.tap()
app.buttons["padSearchButton"].tap()
let field = app.searchFields.firstMatch
XCTAssertTrue(field.waitForExistence(timeout: 5))
field.tap()
field.typeText("example\n")
let result = app.buttons["searchAccount-mae"]
XCTAssertTrue(result.waitForExistence(timeout: 5))
result.tap()
let profileBar = app.navigationBars["Profile"]
XCTAssertTrue(profileBar.waitForExistence(timeout: 5))
XCTAssertTrue(app.navigationBars["Search"].waitForNonExistence(timeout: 5))
XCTAssertTrue(closeButton(in: profileBar).exists)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
}
private func launchApp() -> XCUIApplication {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
return app
}
private func waitForVisibleColumn(_ navigationBar: XCUIElement, in app: XCUIApplication) {
let visible = XCTNSPredicateExpectation(
predicate: NSPredicate { _, _ in
navigationBar.frame.minX >= 0 && navigationBar.frame.maxX <= app.frame.maxX
&& self.closeButton(in: navigationBar).isHittable
}, object: nil)
XCTAssertEqual(XCTWaiter.wait(for: [visible], timeout: 5), .completed)
}
private func closeButton(in navigationBar: XCUIElement) -> XCUIElement {
navigationBar.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "closeColumn-detail-"))
.firstMatch
}
private func detailColumn(in app: XCUIApplication, navigationBar: XCUIElement) -> XCUIElement {
let columnID = String(closeButton(in: navigationBar).identifier.dropFirst("closeColumn-".count))
return app.otherElements["padColumn-\(columnID)"].firstMatch
}
}