import XCTest final class TabScrollToTopTests: XCTestCase { func testReselectingTimelineScrollsToTop() throws { try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone tab layout") let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-rich-scroll"] app.launch() let first = app.buttons["postText-at://mae.example/app.bsky.feed.post/scroll-0-main"] XCTAssertTrue(first.waitForExistence(timeout: 10)) let navigationBar = app.navigationBars["Following"] let titleHeight = navigationBar.frame.height let list = app.collectionViews.firstMatch for _ in 0..<4 { list.swipeUp() } XCTAssertFalse(first.isHittable) XCTAssertEqual(navigationBar.frame.height, titleHeight, accuracy: 1) app.tabBars.buttons["Search"].tap() app.tabBars.buttons["Timeline"].tap() XCTAssertFalse(first.isHittable) app.tabBars.buttons["Timeline"].tap() expectation( for: NSPredicate { _, _ in first.isHittable && abs(navigationBar.frame.height - titleHeight) < 1 }, evaluatedWith: nil) waitForExpectations(timeout: 5) } func testReselectingNotificationsScrollsToTop() 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 notificationsTab = app.tabBars.buttons["Notifications"] XCTAssertTrue(notificationsTab.waitForExistence(timeout: 10)) notificationsTab.tap() let first = app.buttons["notificationPost-notification-1"] XCTAssertTrue(first.waitForExistence(timeout: 10)) XCTAssertTrue(first.isHittable) let navigationBar = app.navigationBars["Notifications"] let titleHeight = navigationBar.frame.height let more = app.buttons["loadMoreNotificationsButton"] for _ in 0..<5 { if more.isHittable { break } app.swipeUp() } XCTAssertTrue(more.isHittable) more.tap() for _ in 0..<5 { if !first.isHittable { break } app.swipeUp() } XCTAssertFalse(first.isHittable) XCTAssertEqual(navigationBar.frame.height, titleHeight, accuracy: 1) app.tabBars.buttons["Search"].tap() app.tabBars.buttons["Notifications"].tap() XCTAssertFalse(first.isHittable) app.tabBars.buttons["Notifications"].tap() let returnedToTop = NSPredicate { _, _ in first.isHittable && abs(navigationBar.frame.height - titleHeight) < 1 } expectation(for: returnedToTop, evaluatedWith: nil) waitForExpectations(timeout: 5) } }