import XCTest extension OldFellaUITests { func testQuoteHeaderSpacingMatchesFeedContextAndDetail() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-context-quote"] app.launch() app.openSettings() let toggle = app.switches["filterReplies"] XCTAssertTrue(toggle.waitForExistence(timeout: 5)) toggle.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() app.closeSettings() let context = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch XCTAssertTrue(context.waitForExistence(timeout: 5)) let header = context.buttons["quotedPostLink"] let text = context.descendants(matching: .any)["quotedPostText-post-3"].firstMatch XCTAssertTrue(header.exists) XCTAssertTrue(text.exists) let contextHeight = header.frame.height XCTAssertEqual(text.frame.minY - header.frame.maxY, 12, accuracy: 1) context.descendants(matching: .any)["replyContext-post-1"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) let detailHeader = app.buttons["quotedPostLink"].firstMatch let detailText = app.descendants(matching: .any)["quotedPostText-post-3"].firstMatch XCTAssertTrue(detailHeader.waitForExistence(timeout: 5)) XCTAssertTrue(detailText.exists) XCTAssertEqual(detailHeader.frame.height, contextHeight, accuracy: 1) XCTAssertEqual(detailText.frame.minY - detailHeader.frame.maxY, 12, accuracy: 1) } func testThreadContextQuoteFollowsText() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-context-quote"] app.launch() let context = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch for _ in 0..<5 { if context.exists && context.isHittable { break } app.swipeUp() } XCTAssertTrue(context.waitForExistence(timeout: 5)) let text = context.buttons["replyContext-post-1"] let quote = context.buttons["quotedPostLink"] XCTAssertTrue(text.exists) XCTAssertTrue(quote.exists) XCTAssertEqual(quote.frame.minY - text.frame.maxY, 14, accuracy: 1) quote.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["postText-post-3"].waitForExistence(timeout: 5)) } func testHideQuotedPostsSetting() { let app = XCUIApplication() app.launchArguments = ["-ui-testing"] app.launchArguments.append("-ui-testing-signed-in") app.launch() app.openSettings() let setting = app.switches["showQuotedPosts"] XCTAssertTrue(setting.waitForExistence(timeout: 5)) setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() XCTAssertEqual(String(describing: setting.value ?? ""), "0") app.closeSettings() let quote = app.buttons["quotedPostLink"] for _ in 0..<5 { if quote.exists && quote.isHittable { break } app.swipeUp() } XCTAssertTrue(quote.exists) XCTAssertEqual(quote.label, "See post") quote.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) app.openSettings() setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() } func testNotificationTabShowsUnreadStatusAndClearsAfterOpening() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() let notifications = app.tabBars.buttons["Notifications"] XCTAssertTrue(notifications.waitForExistence(timeout: 5)) expectation(for: NSPredicate(format: "value CONTAINS %@", "Unread notifications"), evaluatedWith: notifications) waitForExpectations(timeout: 5) let unread = XCTAttachment(screenshot: app.screenshot()) unread.name = "Unread notification bell" unread.lifetime = .keepAlways add(unread) notifications.tap() expectation( for: NSPredicate(format: "value CONTAINS %@", "No unread notifications"), evaluatedWith: notifications) waitForExpectations(timeout: 5) XCTAssertTrue(app.navigationBars["Notifications"].exists) let read = XCTAttachment(screenshot: app.screenshot()) read.name = "Read notification bell" read.lifetime = .keepAlways add(read) } func testNotificationsAndSettingsTabs() { let app = XCUIApplication() app.launchArguments = ["-ui-testing"] app.launchArguments.append("-ui-testing-signed-in") app.launch() let notifications = app.tabBars.buttons["Notifications"] XCTAssertTrue(notifications.waitForExistence(timeout: 5)) notifications.tap() XCTAssertTrue(app.navigationBars["Notifications"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["postText-reply-post-1"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["postText-reply-post-1"].label.contains("Thanks for the thoughtful reply.")) XCTAssertFalse(app.staticTexts["Alex Kim replied to your post"].exists) let likedPost = app.buttons["notificationPost-notification-1"] XCTAssertTrue(likedPost.exists) likedPost.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) app.navigationBars.buttons["Notifications"].tap() app.openSettings() XCTAssertTrue(app.navigationBars["Settings"].waitForExistence(timeout: 5)) let account = app.buttons["settingsEditProfile"] XCTAssertTrue(account.label.contains("Demo Account")) XCTAssertTrue(account.label.contains("@demo.bsky.social")) let signOut = app.buttons["settingsSignOutButton"] for _ in 0..<3 where !signOut.isHittable { app.swipeUp() } XCTAssertTrue(signOut.isHittable) signOut.tap() app.buttons.matching(identifier: "settingsConfirmSignOutButton").firstMatch.tap() XCTAssertTrue(app.staticTexts["Sign in"].waitForExistence(timeout: 5)) } func testNotificationReplyShowsContextAndOpensReply() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() app.tabBars.buttons["Notifications"].tap() let reply = app.buttons["postText-reply-post-1"] XCTAssertTrue(reply.waitForExistence(timeout: 5)) let context = app.descendants(matching: .any)["replyContext-post-1"].firstMatch XCTAssertTrue(context.waitForExistence(timeout: 5)) XCTAssertTrue(context.label.contains("Morning walk along the water.")) XCTAssertTrue( app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "Thread started by Mae Rivers")).firstMatch .exists) reply.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["postText-reply-post-1"].waitForExistence(timeout: 5)) } func testNotificationReplyParentAvatarOpensProfile() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() app.tabBars.buttons["Notifications"].tap() let avatar = app.buttons["notificationReplyAvatar-post-1"] XCTAssertTrue(avatar.waitForExistence(timeout: 5)) avatar.tap() XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers") } func testNotificationReplyShowsOwnParentAuthor() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-own-reply-parent"] app.launch() app.tabBars.buttons["Notifications"].tap() let context = app.descendants(matching: .any)["replyContext-own-parent"].firstMatch XCTAssertTrue(context.waitForExistence(timeout: 5)) XCTAssertTrue(context.label.contains("A post by the signed-in account.")) XCTAssertTrue( app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "Thread started by Demo Account")).firstMatch .exists) } func testNotificationReplyAlwaysShowsContextWhenSettingHidesIt() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() app.openSettings() let setting = app.switches["showReplyContexts"] XCTAssertTrue(setting.waitForExistence(timeout: 5)) setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() app.closeSettings() app.tabBars.buttons["Notifications"].tap() let context = app.buttons["replyContext-post-1"] XCTAssertTrue(context.waitForExistence(timeout: 5)) XCTAssertTrue(context.label.contains("Morning walk along the water.")) XCTAssertFalse(app.buttons["replyContextLink-reply-post-1"].exists) context.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5)) } func testNativeRefreshLoadsNewPosts() { let app = XCUIApplication() app.launchArguments = [ "-ui-testing", "-ui-testing-signed-in", "-ui-testing-pull-refresh-delay", "-ui-testing-refresh-new-post" ] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) XCTAssertTrue( app.descendants(matching: .any)["initialFeedRefreshControl"].firstMatch.waitForNonExistence(timeout: 5)) let list = app.collectionViews.firstMatch let start = list.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.4)) let end = list.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.85)) start.press(forDuration: 0.05, thenDragTo: end, withVelocity: .slow, thenHoldForDuration: 0.2) XCTAssertTrue(app.buttons["postText-refresh-new-post"].waitForExistence(timeout: 10)) XCTAssertTrue(app.navigationBars["Following"].exists) let screenshot = XCTAttachment(screenshot: app.screenshot()) screenshot.name = "Native refresh with new posts" screenshot.lifetime = .keepAlways add(screenshot) } func testFollowingRefreshKeepsPostsVisibleAndUsable() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() let post = app.buttons["postText-post-1"] XCTAssertTrue(post.waitForExistence(timeout: 5)) app.collectionViews.firstMatch.swipeDown() XCTAssertTrue(post.waitForExistence(timeout: 5)) XCTAssertFalse(app.alerts.firstMatch.exists) post.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) app.tabBars.buttons["Notifications"].tap() XCTAssertTrue(app.navigationBars["Notifications"].waitForExistence(timeout: 5)) } }