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

geesawra.industries/old-fella

Old people's social media app

0
1
main
134 lines · 6.8 KB Raw History
import XCTest

final class OldFellaUITests: XCTestCase {
    func testTabIconsKeepAccessibleNames() 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
        for name in ["Timeline", "Notifications", "Search", "Saved Posts", "New post"] {
            XCTAssertTrue(tabs.buttons[name].waitForExistence(timeout: 10))
        }
        let screenshot = XCTAttachment(screenshot: app.screenshot())
        screenshot.name = "Tab bar"
        screenshot.lifetime = .keepAlways
        add(screenshot)
        tabs.buttons["Saved Posts"].tap()
        XCTAssertTrue(app.navigationBars["Saved Posts"].waitForExistence(timeout: 5))
        tabs.buttons["Timeline"].tap()
        XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
    }

    func testFontSettingPersists() {
        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))
        let description = app.staticTexts["distractionsDescription"]
        XCTAssertTrue(description.waitForExistence(timeout: 5))
        let systemHeight = description.frame.height
        picker.tap()
        let atkinson = app.buttons["Atkinson Hyperlegible Next"]
        XCTAssertTrue(atkinson.waitForExistence(timeout: 5))
        atkinson.tap()
        XCTAssertLessThan(description.frame.height, systemHeight * 1.4)
        picker.tap()
        let choice = app.buttons["Paper Mono"]
        XCTAssertTrue(choice.waitForExistence(timeout: 5))
        choice.tap()
        XCTAssertLessThan(description.frame.height, systemHeight * 1.4)
        XCTAssertTrue(picker.waitForExistence(timeout: 5))
        XCTAssertTrue(picker.label.contains("Paper Mono") || (picker.value as? String) == "Paper Mono")
        app.terminate()
        app.launchArguments.append("-ui-testing-preserve-defaults")
        app.launch()
        app.openSettings()
        if !picker.isHittable { app.swipeUp() }
        XCTAssertTrue(picker.waitForExistence(timeout: 5))
        XCTAssertTrue(picker.label.contains("Paper Mono") || (picker.value as? String) == "Paper Mono")
    }

    func testHiddenPicturesOpenImageViewerDirectly() 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-image-grid", "3"]
        app.launch()
        app.openSettings()
        let setting = app.switches["showPictures"]
        XCTAssertTrue(setting.waitForExistence(timeout: 5))
        XCTAssertEqual(setting.value as? String, "1")
        setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        XCTAssertEqual(setting.value as? String, "0")
        app.closeSettings()
        let row = app.cells.containing(.button, identifier: "postText-post-1").firstMatch
        let first = row.buttons["showImageButton-1"]
        XCTAssertTrue(first.waitForExistence(timeout: 5))
        XCTAssertTrue(row.buttons["showImageButton-2"].exists)
        XCTAssertTrue(row.buttons["showImageButton-3"].exists)
        XCTAssertFalse(row.descendants(matching: .any)["postImageTile-1"].firstMatch.exists)
        XCTAssertFalse(row.descendants(matching: .any)["postImageTile-2"].firstMatch.exists)
        first.tap()
        let close = app.buttons["imageViewerClose"]
        XCTAssertTrue(close.waitForExistence(timeout: 5))
        XCTAssertTrue(app.images["Image 1 of 3"].firstMatch.waitForExistence(timeout: 5))
        close.tap()
        XCTAssertTrue(first.waitForExistence(timeout: 5))
        XCTAssertFalse(row.descendants(matching: .any)["postImageTile-1"].firstMatch.exists)
        row.buttons["showImageButton-2"].tap()
        XCTAssertTrue(close.waitForExistence(timeout: 5))
        XCTAssertTrue(app.images["Image 2 of 3"].firstMatch.waitForExistence(timeout: 5))
        close.tap()
        XCTAssertTrue(first.waitForExistence(timeout: 5))
        XCTAssertTrue(row.buttons["showImageButton-2"].exists)
        XCTAssertTrue(row.buttons["showImageButton-3"].exists)
        app.terminate()
        app.launchArguments.append("-ui-testing-preserve-defaults")
        app.launch()
        XCTAssertTrue(first.waitForExistence(timeout: 10))
        XCTAssertFalse(row.descendants(matching: .any)["postImageTile-1"].firstMatch.exists)
    }

    func testDisplayPreferencesPersistAndKeepProfileNavigation() 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 showAvatars = app.switches["showAvatars"]
        let showDisplayNames = app.switches["showDisplayNames"]
        XCTAssertTrue(showAvatars.waitForExistence(timeout: 5))
        XCTAssertEqual(showAvatars.value as? String, "1")
        XCTAssertEqual(showDisplayNames.value as? String, "1")
        showAvatars.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        XCTAssertEqual(showAvatars.value as? String, "0")
        showDisplayNames.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        XCTAssertEqual(showDisplayNames.value as? String, "0")
        app.closeSettings()
        let author = app.buttons["profileLink-mae"]
        XCTAssertTrue(author.waitForExistence(timeout: 5))
        XCTAssertTrue(author.label.contains("@mae.example"))
        XCTAssertFalse(author.label.contains("Mae Rivers"))
        author.tap()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "@mae.example")
        XCTAssertTrue(app.staticTexts["profileFollowsYou"].exists)
        XCTAssertFalse(app.buttons["profileAvatarButton"].exists)
        app.terminate()
        app.launchArguments.append("-ui-testing-preserve-defaults")
        app.launch()
        app.openSettings()
        XCTAssertTrue(showAvatars.waitForExistence(timeout: 5))
        XCTAssertEqual(showAvatars.value as? String, "0")
        XCTAssertEqual(showDisplayNames.value as? String, "0")
        app.closeSettings()
        app.openOwnProfile()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "@demo.bsky.social")
        XCTAssertFalse(app.staticTexts["profileFollowsYou"].exists)
        XCTAssertFalse(app.buttons["profileAvatarButton"].exists)
    }
}