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
import XCTest
final class NavigationTitleTransitionTests: XCTestCase {
func testFontSurvivesFeedRefresh() 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-refresh-new-post"]
app.launch()
app.openSettings()
let picker = app.buttons["appFont"]
if !picker.isHittable { app.swipeUp() }
XCTAssertTrue(picker.waitForExistence(timeout: 5))
picker.tap()
let choice = app.buttons["Iosevka"]
XCTAssertTrue(choice.waitForExistence(timeout: 5))
choice.tap()
app.closeSettings()
let post = app.buttons["postText-post-1"]
XCTAssertTrue(post.waitForExistence(timeout: 5))
XCTAssertTrue(
app.descendants(matching: .any)["initialFeedRefreshControl"].firstMatch.waitForNonExistence(timeout: 5))
let newPost = app.buttons["postText-refresh-new-post"]
XCTAssertFalse(newPost.exists)
let before = try titleScreenshot()
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(newPost.waitForExistence(timeout: 10))
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
XCTAssertEqual(before, try titleScreenshot(), "The feed title changed after new posts arrived.")
}
func testFontSurvivesReturningToApp() 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()
app.openSettings()
let picker = app.buttons["appFont"]
if !picker.isHittable { app.swipeUp() }
XCTAssertTrue(picker.waitForExistence(timeout: 5))
picker.tap()
let choice = app.buttons["Iosevka"]
XCTAssertTrue(choice.waitForExistence(timeout: 5))
choice.tap()
app.closeSettings()
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
let before = try titleScreenshot()
let start = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.995))
let end = app.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.45))
start.press(forDuration: 0.1, thenDragTo: end, withVelocity: .slow, thenHoldForDuration: 1)
app.activate()
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
XCTAssertEqual(before, try titleScreenshot(), "The feed title changed after the app switcher.")
XCUIDevice.shared.press(.home)
app.activate()
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
XCTAssertEqual(before, try titleScreenshot(), "The feed title changed after returning to the app.")
}
func titleScreenshot() throws -> Data {
let title = XCUIApplication().navigationBars["Following"].buttons["feedPickerButton"]
XCTAssertTrue(title.waitForExistence(timeout: 5))
return title.screenshot().pngRepresentation
}
func testCustomTitlesSurviveTabScrollAndNavigationTransitions() 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 tabs = app.tabBars.firstMatch
XCTAssertTrue(tabs.buttons["Saved Posts"].waitForExistence(timeout: 10))
for font in ["Atkinson Hyperlegible Next", "Iosevka", "Paper Mono", "System"] {
app.openSettings()
let picker = app.buttons["appFont"]
for _ in 0..<4 {
if picker.isHittable { break }
app.swipeDown()
}
for _ in 0..<6 {
if picker.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(picker.isHittable)
picker.tap()
app.buttons[font].tap()
app.closeSettings()
for (tab, title) in [
("Timeline", "Following"), ("Notifications", "Notifications"),
("Search", "Search"), ("Saved Posts", "Saved Posts")
] {
tabs.buttons[tab].tap()
XCTAssertTrue(app.navigationBars[title].waitForExistence(timeout: 5))
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "\(font) \(title)"
attachment.lifetime = .keepAlways
add(attachment)
}
app.openSettings()
app.swipeUp()
app.swipeDown()
let licenses = app.buttons["openSourceLicenses"]
for _ in 0..<6 {
if licenses.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(licenses.isHittable)
licenses.tap()
XCTAssertTrue(app.navigationBars["Open Source Licenses"].waitForExistence(timeout: 5))
let backButton = app.navigationBars["Open Source Licenses"].buttons["Settings"]
XCTAssertTrue(backButton.exists)
backButton.tap()
XCTAssertTrue(app.navigationBars["Settings"].waitForExistence(timeout: 5))
app.closeSettings()
}
}
}