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") } }