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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import XCTest
extension OldFellaUITests {
func testSearchAccountsPaginationAndPostMode() throws {
try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone tab layout")
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let searchTab = app.tabBars.buttons["Search"]
XCTAssertTrue(searchTab.waitForExistence(timeout: 10))
searchTab.tap()
let field = app.searchFields.firstMatch
XCTAssertTrue(field.waitForExistence(timeout: 5))
field.tap()
field.typeText("example")
XCTAssertTrue(app.buttons["searchAccount-mae"].waitForExistence(timeout: 5))
XCTAssertTrue(
app.buttons["searchAccount-mae"].label.contains(
"Writer, walker, and amateur cloud spotter. Sharing small things worth noticing."))
let more = app.buttons["loadMoreSearchButton"]
XCTAssertTrue(more.waitForExistence(timeout: 5))
more.tap()
XCTAssertTrue(app.buttons["searchAccount-alex"].waitForExistence(timeout: 5))
field.tap()
field.typeText("\n")
XCTAssertTrue(app.buttons["searchAccount-alex"].waitForExistence(timeout: 5))
more.tap()
XCTAssertTrue(app.buttons["searchAccount-sam"].waitForExistence(timeout: 5))
XCTAssertTrue(app.staticTexts["End of results"].waitForExistence(timeout: 5))
XCTAssertFalse(more.exists)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.lifetime = .keepAlways
add(screenshot)
let filter = app.buttons["searchFilterMenu"]
XCTAssertTrue(filter.waitForExistence(timeout: 5))
filter.tap()
XCTAssertFalse(app.buttons["My posts"].exists)
app.buttons["Posts"].tap()
XCTAssertTrue(app.buttons["My posts"].waitForExistence(timeout: 5))
app.buttons["My posts"].tap()
XCTAssertTrue(app.staticTexts["No results"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["searchAccount-mae"].exists)
XCTAssertEqual(filter.label, "Filter search: My posts")
filter.tap()
app.buttons["All posts"].tap()
XCTAssertEqual(filter.label, "Filter search: Posts")
filter.tap()
app.buttons["Accounts"].tap()
XCTAssertFalse(app.buttons["My posts"].exists)
app.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.7)).tap()
XCTAssertTrue(app.buttons["searchAccount-mae"].waitForExistence(timeout: 5))
app.buttons["searchAccount-mae"].tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
}
func testCustomFeedPickerSavesSelectionAcrossLaunches() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
XCTAssertTrue(app.buttons["feedPickerButton"].waitForExistence(timeout: 10))
app.buttons["feedPickerButton"].tap()
XCTAssertTrue(
app.buttons["feedChoice-at://did:plc:demo/app.bsky.feed.generator/nature"].waitForExistence(timeout: 5))
app.buttons["feedChoice-at://did:plc:demo/app.bsky.feed.generator/nature"].tap()
XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 5))
app.terminate()
app.launchArguments.append("-ui-testing-preserve-defaults")
app.launch()
XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 10))
XCTAssertTrue(app.tabBars.buttons["Timeline"].exists)
XCTAssertEqual(app.buttons["feedPickerButton"].value as? String, "Nature")
app.buttons["feedPickerButton"].tap()
XCTAssertTrue(app.buttons["feedChoice-following"].waitForExistence(timeout: 5))
app.buttons["feedChoice-following"].tap()
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
}
func testIPadPortraitLayoutAndComposeMatchDeviceSize() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .portrait
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let isMini = app.frame.width < 768
if isMini {
XCTAssertTrue(app.buttons["feedPickerButton"].waitForExistence(timeout: 10))
XCTAssertFalse(app.buttons["addFeedColumnButton"].exists)
let compose = app.buttons["floatingComposeButton"]
XCTAssertTrue(compose.waitForExistence(timeout: 5))
XCTAssertFalse(app.tabBars.buttons["New post"].exists)
XCTAssertGreaterThan(compose.frame.midX, app.frame.midX)
XCTAssertGreaterThan(compose.frame.midY, app.frame.midY)
compose.tap()
XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
app.buttons["Cancel"].tap()
app.buttons.matching(identifier: "Notifications").firstMatch.tap()
XCTAssertTrue(app.navigationBars["Notifications"].waitForExistence(timeout: 5))
XCTAssertFalse(app.navigationBars["Following"].exists)
XCTAssertTrue(compose.exists)
} else {
openPadActions(app)
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10))
XCTAssertTrue(app.navigationBars["Following"].exists)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
app.buttons["New post"].tap()
XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
app.buttons["Cancel"].tap()
}
let portrait = XCTAttachment(screenshot: app.screenshot())
portrait.name = "iPad portrait layout"
portrait.lifetime = .keepAlways
add(portrait)
XCUIDevice.shared.orientation = .landscapeLeft
openPadActions(app)
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10))
XCTAssertTrue(app.navigationBars["Following"].exists)
XCTAssertTrue(app.navigationBars["Notifications"].exists)
XCUIDevice.shared.orientation = .portrait
if isMini {
XCTAssertTrue(app.buttons["floatingComposeButton"].waitForExistence(timeout: 10))
XCTAssertFalse(app.buttons["addFeedColumnButton"].exists)
} else {
openPadActions(app)
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10))
XCTAssertTrue(app.navigationBars["Notifications"].exists)
}
}
func testIPadColumnCountSettingPersists() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
openPadActions(app)
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10))
XCTAssertFalse(app.buttons["showLeftColumnButton"].exists)
XCTAssertFalse(app.buttons["showRightColumnButton"].exists)
app.buttons["Settings"].tap()
let picker = app.segmentedControls["padVisibleColumnCount"]
XCTAssertTrue(picker.waitForExistence(timeout: 5))
XCTAssertTrue(picker.buttons["2"].isSelected)
picker.buttons["3"].tap()
XCTAssertTrue(picker.buttons["3"].isSelected)
picker.buttons["4"].tap()
XCTAssertTrue(picker.buttons["4"].isSelected)
app.buttons["Done"].tap()
XCTAssertFalse(app.buttons["showLeftColumnButton"].exists)
XCTAssertFalse(app.buttons["showRightColumnButton"].exists)
app.terminate()
app.launchArguments.append("-ui-testing-preserve-defaults")
app.launch()
openPadActions(app)
XCTAssertTrue(app.buttons["Settings"].waitForExistence(timeout: 10))
app.buttons["Settings"].tap()
XCTAssertTrue(picker.waitForExistence(timeout: 5))
XCTAssertTrue(picker.buttons["4"].isSelected)
}
func testIPadFeedColumnsPersistAndClose() throws {
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad")
XCUIDevice.shared.orientation = .landscapeLeft
defer { XCUIDevice.shared.orientation = .portrait }
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
openPadActions(app)
let feedID = "at://did:plc:demo/app.bsky.feed.generator/nature"
XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10))
app.buttons["addFeedColumnButton"].tap()
XCTAssertTrue(app.buttons["feedChoice-\(feedID)"].waitForExistence(timeout: 5))
app.buttons["feedChoice-\(feedID)"].tap()
let move = app.images["moveColumn-\(feedID)"]
XCTAssertTrue(move.waitForExistence(timeout: 5))
XCTAssertGreaterThanOrEqual(move.frame.minX, 0)
XCTAssertLessThan(move.frame.maxX, app.frame.maxX, "Adding a feed must scroll its handle into view")
XCTAssertLessThan(app.buttons["closeColumn-\(feedID)"].frame.maxX, app.frame.maxX)
XCTAssertLessThan(move.frame.minX, app.buttons["closeColumn-\(feedID)"].frame.minX)
XCTAssertTrue(app.buttons["showLeftColumnButton"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["showRightColumnButton"].exists)
app.buttons["showLeftColumnButton"].tap()
XCTAssertTrue(app.buttons["showRightColumnButton"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["showLeftColumnButton"].exists)
app.buttons["showRightColumnButton"].tap()
XCTAssertTrue(app.buttons["showLeftColumnButton"].waitForExistence(timeout: 5))
let destination = move.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
.withOffset(CGVector(dx: -(app.frame.width - 12) / 2, dy: 0))
move.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
.press(forDuration: 0.1, thenDragTo: destination)
XCTAssertFalse(app.buttons["closeColumn-following"].exists)
XCTAssertFalse(app.buttons["closeColumn-notifications"].exists)
app.terminate()
app.launchArguments.append("-ui-testing-preserve-defaults")
app.launch()
let close = app.buttons["closeColumn-\(feedID)"]
XCTAssertTrue(close.waitForExistence(timeout: 10))
let following = app.images["moveColumn-following"]
let nature = app.images["moveColumn-\(feedID)"]
let notifications = app.images["moveColumn-notifications"]
XCTAssertGreaterThanOrEqual(following.frame.minX, 0, "Restoring columns must not scroll to a custom feed")
XCTAssertLessThan(following.frame.minX, nature.frame.minX)
XCTAssertLessThan(nature.frame.minX, notifications.frame.minX)
close.tap()
XCTAssertFalse(close.exists)
app.terminate()
app.launch()
XCTAssertTrue(app.buttons["togglePadActionsButton"].waitForExistence(timeout: 10))
XCTAssertFalse(app.buttons["closeColumn-\(feedID)"].exists)
}
}