~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
119 lines · 5.6 KB Raw History
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()
        }
    }
}