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

geesawra.industries/old-fella

Old people's social media app

0
1
main
226 lines · 10.8 KB Raw History
import XCTest

extension OldFellaUITests {
    func testProfileReplyShowsCompactParentPostAndOpensProfile() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let profile = app.buttons["profileLink-alex"].firstMatch
        XCTAssertTrue(profile.waitForExistence(timeout: 5))
        profile.tap()
        let parent = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
        XCTAssertTrue(parent.waitForExistence(timeout: 5))
        XCTAssertTrue(app.buttons["replyContext-post-1"].label.contains("Morning walk along the water."))
        XCTAssertFalse(app.buttons["replyContext-replyButton"].exists)

        let author = app.buttons["replyContextAvatar-post-1"]
        XCTAssertLessThanOrEqual(author.frame.height, 30)
        XCTAssertTrue(author.isHittable)
        author.tap()
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
    }

    func testHideReplyContextSetting() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-context-quote"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        app.openSettings()
        let filter = app.switches["filterReplies"]
        XCTAssertTrue(filter.waitForExistence(timeout: 5))
        filter.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        app.closeSettings()
        let parent = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
        XCTAssertTrue(parent.waitForExistence(timeout: 5))
        XCTAssertFalse(app.staticTexts["Content warning"].exists)

        app.openSettings()
        let setting = app.switches["showReplyContexts"]
        XCTAssertTrue(setting.waitForExistence(timeout: 5))
        setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        XCTAssertEqual(String(describing: setting.value ?? ""), "0")
        app.closeSettings()
        let link = app.buttons["replyContextLink-post-2"]
        XCTAssertTrue(link.waitForExistence(timeout: 5))
        XCTAssertTrue(link.label.contains("In reply to Mae Rivers"))
        XCTAssertFalse(parent.exists)
        XCTAssertFalse(app.staticTexts["Reply context hidden by content preferences"].exists)
        link.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
        XCTAssertTrue(app.buttons["postText-post-1"].exists)

        app.openSettings()
        setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
        app.closeSettings()
        XCTAssertTrue(parent.waitForExistence(timeout: 5))
    }

    func testFollowingReplyContextOpensRootPost() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let parent = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
        for _ in 0..<5 {
            if parent.exists && parent.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(parent.waitForExistence(timeout: 5))
        let rootPost = app.buttons["replyContext-post-1"]
        XCTAssertTrue(rootPost.label.contains("Morning walk along the water."))
        XCTAssertFalse(app.buttons["replyContext-replyButton"].exists)
        rootPost.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
    }

    func testReplyContextFacetsNavigateAndPlainTextOpensRootPost() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-facets"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()

        let context = app.descendants(matching: .any)["replyContext-post-1"].firstMatch
        for _ in 0..<5 {
            if context.exists && context.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(context.waitForExistence(timeout: 5))
        XCTAssertTrue(context.label.contains("@alex.example"))
        XCTAssertTrue(context.label.contains("https://example.com/reply"))

        let mention = context.links.matching(NSPredicate(format: "label CONTAINS %@", "@alex.example")).firstMatch
        XCTAssertTrue(mention.waitForExistence(timeout: 5))
        mention.tap()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Alex Kim")
        app.navigationBars.buttons["Following"].tap()

        let postLink = context.links.matching(
            NSPredicate(format: "label CONTAINS %@", "https://oldsky.app/post?uri=post-2")
        ).firstMatch
        XCTAssertTrue(postLink.waitForExistence(timeout: 5))
        postLink.tap()
        XCTAssertTrue(app.buttons["postText-post-2"].waitForExistence(timeout: 5))
        app.navigationBars.buttons["Following"].tap()

        let plainText = app.descendants(matching: .any)["replyContext-post-1"].firstMatch
        XCTAssertTrue(plainText.waitForExistence(timeout: 5))
        plainText.coordinate(withNormalizedOffset: CGVector(dx: 0.04, dy: 0.1)).tap()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
    }

    func testQuotedPostFacetsNavigateAndPlainTextOpensQuotedPost() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-facets"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()

        let quoteText = app.descendants(matching: .any)["quotedPostText-post-2"].firstMatch
        for _ in 0..<6 {
            if quoteText.exists && quoteText.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(quoteText.waitForExistence(timeout: 5))
        XCTAssertTrue(quoteText.label.contains("@mae.example"))
        XCTAssertTrue(quoteText.label.contains("https://example.com/quote"))

        let mention = quoteText.links.matching(NSPredicate(format: "label CONTAINS %@", "@mae.example")).firstMatch
        XCTAssertTrue(mention.waitForExistence(timeout: 5))
        mention.tap()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
        app.navigationBars.buttons["Following"].tap()

        let postLink = quoteText.links.matching(
            NSPredicate(format: "label CONTAINS %@", "https://oldsky.app/post?uri=post-1")
        ).firstMatch
        XCTAssertTrue(postLink.waitForExistence(timeout: 5))
        postLink.tap()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
        app.navigationBars.buttons["Following"].tap()

        let plainText = app.descendants(matching: .any)["quotedPostText-post-2"].firstMatch
        XCTAssertTrue(plainText.waitForExistence(timeout: 5))
        plainText.coordinate(withNormalizedOffset: CGVector(dx: 0.04, dy: 0.1)).tap()
        XCTAssertTrue(app.buttons["postText-post-2"].waitForExistence(timeout: 5))
    }

    func testFollowingReplyContextUsesMissingGapRow() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let gap = app.descendants(matching: .any)["missingReplyContext"].firstMatch
        for _ in 0..<5 {
            if gap.exists && gap.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(gap.waitForExistence(timeout: 5))
        XCTAssertTrue(gap.label.contains("More posts in this thread"))
        XCTAssertFalse(app.staticTexts["Earlier reply not available"].exists)
    }

    func testProfileReplyUsesFeedGapRow() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let profile = app.buttons["profileLink-alex"].firstMatch
        XCTAssertTrue(profile.waitForExistence(timeout: 5))
        profile.tap()
        let gap = app.descendants(matching: .any)["missingReplyContext"].firstMatch
        XCTAssertTrue(gap.waitForExistence(timeout: 5))
        XCTAssertTrue(gap.label.contains("More posts in this thread"))
        XCTAssertFalse(app.staticTexts["Earlier reply not available"].exists)
    }

    func testProfilePostsShareTimelineActionsAndNavigation() {
        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 profileList = app.collectionViews["profilePostList"]
        XCTAssertTrue(profileList.waitForExistence(timeout: 5))
        let post = app.buttons["postText-post-1"]
        XCTAssertTrue(post.isHittable)
        app.buttons["Like"].firstMatch.tap()
        XCTAssertTrue(app.buttons["Unlike"].firstMatch.waitForExistence(timeout: 5))
        let reply = app.buttons["replyButton"].firstMatch
        let quote = app.buttons["quoteButton"].firstMatch
        XCTAssertEqual(reply.label, "Reply")
        XCTAssertNotNil(reply.value as? String)
        XCTAssertTrue(reply.staticTexts.firstMatch.exists)
        XCTAssertEqual(quote.label, "Quote")
        XCTAssertTrue(reply.isHittable)
        XCTAssertTrue(quote.isHittable)
        XCTAssertGreaterThanOrEqual(reply.frame.height, 44)
        XCTAssertGreaterThanOrEqual(quote.frame.height, 44)
        XCTAssertGreaterThanOrEqual(reply.frame.width, 43.9)
        XCTAssertGreaterThanOrEqual(quote.frame.width, 43.9)
        XCTAssertLessThanOrEqual(quote.frame.minX - reply.frame.maxX, 9)
        let controls = app.buttons["postControls-post-1"].firstMatch
        XCTAssertGreaterThanOrEqual(controls.frame.width, 44)
        XCTAssertGreaterThanOrEqual(controls.frame.height, 44)
        XCTAssertGreaterThan(controls.frame.minX, quote.frame.maxX)
        reply.tap()
        XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
        app.buttons["Cancel"].tap()
        quote.tap()
        XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
        app.buttons["Cancel"].tap()
        XCTAssertTrue(post.waitForExistence(timeout: 5))
        post.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
        XCTAssertTrue(app.buttons["postText-post-2"].waitForExistence(timeout: 5))
        XCTAssertTrue(app.buttons["Unlike"].firstMatch.waitForExistence(timeout: 5))
        app.navigationBars["Post"].buttons.element(boundBy: 0).tap()
        XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
        XCTAssertTrue(post.isHittable)
    }
}