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