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

geesawra.industries/old-fella

Old people's social media app

0
1
main
265 lines · 11.9 KB Raw History
import XCTest

extension OldFellaUITests {
    func testGroupedNotificationsUsePeopleListSheets() throws {
        try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .phone, "Requires iPhone")
        continueAfterFailure = false
        XCUIDevice.shared.orientation = .portrait
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-grouped-notifications"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()

        let likes = app.buttons["Many liked this post"]
        XCTAssertTrue(likes.waitForExistence(timeout: 5))
        likes.tap()

        let likedBy = app.navigationBars["Liked by"]
        XCTAssertTrue(likedBy.waitForExistence(timeout: 5))
        let mae = app.buttons["notificationGroupAccount-mae"]
        XCTAssertTrue(mae.label.contains("Mae Rivers"))
        XCTAssertTrue(mae.label.contains("@mae.example"))
        XCTAssertTrue(mae.label.contains("Writer, walker, and amateur cloud spotter"))
        XCTAssertTrue(app.buttons["notificationGroupAccountAvatar-mae"].exists)
        likedBy.buttons["Done"].tap()
        XCTAssertTrue(likedBy.waitForNonExistence(timeout: 5))

        let reposts = app.buttons["Many reposted this post"]
        XCTAssertTrue(reposts.waitForExistence(timeout: 5))
        reposts.tap()

        let repostedBy = app.navigationBars["Reposted by"]
        XCTAssertTrue(repostedBy.waitForExistence(timeout: 5))
        let alex = app.buttons["notificationGroupAccount-alex"]
        XCTAssertTrue(alex.label.contains("@alex.example"))
        alex.tap()
        XCTAssertTrue(repostedBy.waitForNonExistence(timeout: 5))
        let name = app.staticTexts["profileDisplayName"]
        XCTAssertTrue(name.waitForExistence(timeout: 5))
        XCTAssertEqual(name.label, "Alex Kim")
    }

    func testNotificationRefreshKeepsListVisibleAndUsable() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()
        let post = app.buttons["notificationPost-notification-1"]
        XCTAssertTrue(post.waitForExistence(timeout: 5))
        let list = app.collectionViews.firstMatch
        list.swipeDown()
        XCTAssertTrue(post.waitForExistence(timeout: 5))
        XCTAssertFalse(app.staticTexts["No notifications to show"].exists)
        XCTAssertFalse(app.alerts.firstMatch.exists)
        app.buttons["notificationAvatar-notification-1"].tap()
        XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
        app.tabBars.buttons["Timeline"].tap()
        XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
    }

    func testYourPostContextUsesCompactHeaderSpacing() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()
        let header = app.buttons["notificationPost-notification-1"]
        XCTAssertTrue(header.waitForExistence(timeout: 5))
        let text = app.descendants(matching: .any)["quotedPostText-post-1"].firstMatch
        XCTAssertTrue(text.exists)
        XCTAssertTrue(header.label.hasPrefix("Your post"))
        XCTAssertLessThan(header.frame.height, 44)
        XCTAssertEqual(text.frame.minY - header.frame.maxY, 12, accuracy: 1)
        header.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
    }

    func testNotificationsLoadNextPageAfterExplicitTap() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()
        XCTAssertTrue(app.buttons["notificationPost-notification-1"].waitForExistence(timeout: 5))
        let repost = app.buttons["notificationPost-notification-5"]
        XCTAssertFalse(repost.exists)
        let loadMore = app.buttons["loadMoreNotificationsButton"]
        for _ in 0..<5 {
            if loadMore.exists && loadMore.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(loadMore.waitForExistence(timeout: 5))
        loadMore.tap()
        for _ in 0..<5 {
            if repost.exists { break }
            app.swipeUp()
        }
        XCTAssertTrue(repost.waitForExistence(timeout: 5))
        XCTAssertTrue(repost.label.hasPrefix("Your post"))
        let quote = app.buttons["quotedPostLink"]
        for _ in 0..<5 {
            if quote.exists && quote.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(quote.waitForExistence(timeout: 5))
    }

    func testLikeNotificationAvatarOpensProfile() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()
        let avatar = app.buttons["notificationAvatar-notification-1"]
        XCTAssertTrue(avatar.waitForExistence(timeout: 5))
        avatar.tap()
        XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
    }

    func testFollowNotificationAvatarOpensProfile() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        app.tabBars.buttons["Notifications"].tap()
        let avatar = app.buttons["notificationAvatar-notification-3"]
        XCTAssertTrue(avatar.waitForExistence(timeout: 5))
        XCTAssertTrue(
            app.buttons["notification-notification-3"].label.contains(
                "Learning to cook one seasonal recipe at a time."))
        avatar.tap()
        XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Sam Lee")
    }

    func testMentionShowsFullPostAndActions() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        XCTAssertTrue(app.tabBars.buttons["Notifications"].waitForExistence(timeout: 5))
        app.tabBars.buttons["Notifications"].tap()
        let loadMore = app.buttons["loadMoreNotificationsButton"]
        XCTAssertTrue(loadMore.waitForExistence(timeout: 5))
        loadMore.tap()

        let post = app.buttons["postText-mention-post-1"]
        for _ in 0..<8 {
            if post.exists && post.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(post.isHittable)
        XCTAssertTrue(post.label.contains("Take a look at this, @demo.bsky.social."))
        XCTAssertTrue(app.staticTexts["notificationActivity-notification-7"].exists)
        XCTAssertFalse(app.buttons["notification-notification-7"].exists)
        post.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
    }

    func testSignInCanEnterEmailCodeAfterChallenge() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-auth-factor"]
        app.launch()
        let handleField = app.textFields["handleField"]
        XCTAssertTrue(handleField.waitForExistence(timeout: 5))
        handleField.tap()
        handleField.typeText("demo.bsky.social")
        let passwordField = app.secureTextFields["appPasswordField"]
        passwordField.tap()
        passwordField.typeText("test-only")
        let signInButton = app.buttons["signInButton"]
        signInButton.tap()

        let codeField = app.textFields["authFactorTokenField"]
        XCTAssertTrue(codeField.waitForExistence(timeout: 5))
        codeField.tap()
        XCTAssertTrue(app.keyboards.keys["a"].waitForExistence(timeout: 5))
        codeField.typeText(" ")
        XCTAssertFalse(signInButton.isEnabled)
        codeField.typeText("aB12c3 ")
        XCTAssertEqual(codeField.value as? String, " aB12c3 ")
        signInButton.tap()

        XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
    }

    func testThreadStartsAtSelectedPostAfterLoading() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-thread-delay"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let timelinePost = app.buttons["quotedPostText-post-2"]
        XCTAssertTrue(timelinePost.waitForExistence(timeout: 5))
        timelinePost.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))

        let thread = app.scrollViews["threadScrollView"]
        let loading = app.otherElements["postDetailLoading"].firstMatch
        XCTAssertTrue(loading.waitForExistence(timeout: 2))
        XCTAssertFalse(thread.exists)

        let selectedPost = thread.buttons["postText-post-2"]
        let rootPost = thread.buttons["postText-post-1"]
        XCTAssertTrue(selectedPost.waitForExistence(timeout: 5))
        XCTAssertTrue(rootPost.exists)
        let selectedAuthor = app.buttons["profileLink-alex"]
        let navigationBarBottom = app.navigationBars["Post"].frame.maxY
        XCTAssertGreaterThanOrEqual(selectedAuthor.frame.minY, navigationBarBottom)
        XCTAssertLessThan(selectedAuthor.frame.minY, navigationBarBottom + 40)
        XCTAssertGreaterThanOrEqual(selectedPost.frame.minY, navigationBarBottom)
        XCTAssertLessThan(selectedPost.frame.minY, navigationBarBottom + 120)

        app.swipeDown()
        let rootAuthor = app.buttons["profileLink-mae"]
        XCTAssertTrue(rootAuthor.isHittable)
        XCTAssertGreaterThanOrEqual(rootAuthor.frame.minY, navigationBarBottom)
        XCTAssertTrue(rootPost.isHittable)
        XCTAssertGreaterThanOrEqual(rootPost.frame.minY, navigationBarBottom)
    }

    func testThreadAuthorStaysBelowTopBarWithImmediateResponse() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let timelinePost = app.buttons["quotedPostText-post-2"]
        XCTAssertTrue(timelinePost.waitForExistence(timeout: 5))
        timelinePost.tap()

        let navigationBar = app.navigationBars["Post"]
        XCTAssertTrue(navigationBar.waitForExistence(timeout: 5))
        let selectedAuthor = app.buttons["profileLink-alex"]
        XCTAssertTrue(selectedAuthor.waitForExistence(timeout: 5))
        XCTAssertGreaterThanOrEqual(selectedAuthor.frame.minY, navigationBar.frame.maxY)
        XCTAssertLessThan(selectedAuthor.frame.minY, navigationBar.frame.maxY + 40)

        app.swipeDown()
        let rootAuthor = app.buttons["profileLink-mae"]
        XCTAssertTrue(rootAuthor.isHittable, app.debugDescription)
        XCTAssertGreaterThanOrEqual(rootAuthor.frame.minY, navigationBar.frame.maxY)
        XCTAssertTrue(app.buttons["postText-post-1"].isHittable)
    }

    func testProfileLoadsMorePostsOnlyAfterExplicitTap() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let avatar = app.buttons["profileLink-mae"].firstMatch
        XCTAssertTrue(avatar.waitForExistence(timeout: 5))
        avatar.tap()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))

        let nextPost = app.buttons["postText-profile-post-more"]
        XCTAssertFalse(nextPost.exists)
        let loadMore = app.buttons["loadMoreProfilePostsButton"]
        XCTAssertTrue(loadMore.waitForExistence(timeout: 5))
        XCTAssertTrue(loadMore.isHittable)
        loadMore.tap()
        XCTAssertTrue(nextPost.waitForExistence(timeout: 5))
        XCTAssertFalse(loadMore.exists)
        XCTAssertTrue(app.buttons["postText-post-1"].exists)

        app.navigationBars["Profile"].buttons["Following"].tap()
        XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
        XCTAssertFalse(nextPost.exists)
    }
}