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
import XCTest
final class PostLinkNavigationTests: XCTestCase {
func testNotificationPostLinksPresentBrowser() throws {
try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone tab layout")
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-rich-scroll"]
app.launchEnvironment["OLDFELLA_UI_TEST_LINK_HOST"] = "example.invalid"
app.launch()
app.tabBars.buttons["Notifications"].tap()
let card = app.buttons["notificationPost-notification-1"].firstMatch
XCTAssertTrue(card.waitForExistence(timeout: 10))
card.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
let postID = "at://mae.example/app.bsky.feed.post/scroll-0-main"
let postText = app.buttons["postText-\(postID)"].firstMatch
let facet = postText.links.matching(
NSPredicate(format: "label CONTAINS %@", "https://example.invalid/article/0")
).firstMatch
XCTAssertTrue(facet.waitForExistence(timeout: 5))
facet.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
assertBrowserDestination(in: app)
dismissBrowser(in: app)
let textLink = app.links["externalTextLink"].firstMatch
XCTAssertTrue(textLink.waitForExistence(timeout: 5))
textLink.tap()
assertBrowserDestination(in: app)
dismissBrowser(in: app)
XCTAssertTrue(app.navigationBars["Post"].exists)
app.navigationBars.buttons["Notifications"].tap()
XCTAssertTrue(card.waitForExistence(timeout: 5))
}
private func assertBrowserDestination(in app: XCUIApplication) {
XCTAssertTrue(app.buttons["Close"].firstMatch.waitForExistence(timeout: 10))
let address = app.buttons["URL"].firstMatch
XCTAssertTrue(address.waitForExistence(timeout: 10), app.debugDescription)
XCTAssertTrue((address.value as? String)?.contains("example.invalid") == true, app.debugDescription)
XCTAssertTrue(app.webViews.firstMatch.waitForExistence(timeout: 10), app.debugDescription)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.name = "Notification post browser"
screenshot.lifetime = .keepAlways
add(screenshot)
}
func testFeedAndThreadLinksKeepTheirDestinations() {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-rich-scroll"]
app.launchEnvironment["OLDFELLA_UI_TEST_LINK_HOST"] = "example.invalid"
app.launch()
let postID = "at://mae.example/app.bsky.feed.post/scroll-0-main"
let postText = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(postText.waitForExistence(timeout: 10))
let facet = postText.links.matching(
NSPredicate(format: "label CONTAINS %@", "https://example.invalid/article/0")
).firstMatch
XCTAssertTrue(facet.exists)
facet.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
dismissBrowser(in: app)
let textLink = app.links["externalTextLink"].firstMatch
XCTAssertTrue(textLink.exists)
textLink.tap()
dismissBrowser(in: app)
postText.coordinate(withNormalizedOffset: CGVector(dx: 0.04, dy: 0.1)).tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.links["externalTextLink"].firstMatch.tap()
dismissBrowser(in: app)
app.navigationBars.buttons["Following"].tap()
let mention = postText.links.matching(
NSPredicate(format: "label CONTAINS %@", "@alex.example")
).firstMatch
XCTAssertTrue(mention.exists)
mention.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
let name = app.staticTexts["profileDisplayName"]
XCTAssertTrue(name.waitForExistence(timeout: 5))
XCTAssertEqual(name.label, "Alex Kim")
app.navigationBars.buttons["Following"].tap()
app.buttons["profileLink-mae"].firstMatch.tap()
let website = app.links["profileWebsiteLink"]
XCTAssertTrue(website.waitForExistence(timeout: 5))
website.tap()
dismissBrowser(in: app)
}
private func dismissBrowser(in app: XCUIApplication) {
let close = app.buttons["Close"].firstMatch
XCTAssertTrue(close.waitForExistence(timeout: 10))
let banner = XCUIApplication(bundleIdentifier: "com.apple.springboard")
.descendants(matching: .any)["NotificationShortLookView"].firstMatch
if banner.exists { XCTAssertTrue(banner.waitForNonExistence(timeout: 10)) }
close.tap()
XCTAssertTrue(close.waitForNonExistence(timeout: 5))
}
func testSystemBrowserPreferenceKeepsMentionsInsideOldFella() {
continueAfterFailure = false
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-rich-scroll"]
app.launchEnvironment["OLDFELLA_UI_TEST_LINK_HOST"] = "example.invalid"
app.launch()
let postID = "at://mae.example/app.bsky.feed.post/scroll-0-main"
let postText = app.buttons["postText-\(postID)"].firstMatch
XCTAssertTrue(postText.waitForExistence(timeout: 10))
app.openSettings()
let preference = app.switches["openLinksInApp"]
for _ in 0..<3 {
if preference.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(preference.waitForExistence(timeout: 5))
XCTAssertEqual(preference.value as? String, "1")
XCTAssertTrue(preference.isHittable)
preference.coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
XCTAssertEqual(preference.value as? String, "0")
app.closeSettings()
app.links["externalTextLink"].firstMatch.tap()
let browser = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
let openedSystemBrowser = browser.wait(for: .runningForeground, timeout: 10)
if !openedSystemBrowser {
let attachment = XCTAttachment(string: app.debugDescription)
attachment.lifetime = .keepAlways
add(attachment)
}
XCTAssertTrue(openedSystemBrowser)
app.activate()
let mention = postText.links.matching(
NSPredicate(format: "label CONTAINS %@", "@alex.example")
).firstMatch
XCTAssertTrue(mention.waitForExistence(timeout: 5))
mention.tap()
let name = app.staticTexts["profileDisplayName"]
XCTAssertTrue(name.waitForExistence(timeout: 5))
XCTAssertEqual(name.label, "Alex Kim")
}
}