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

geesawra.industries/old-fella

Old people's social media app

0
1
main
180 lines · 8.4 KB Raw History
import XCTest

extension OldFellaUITests {
    func testReplyBranchesShowNestedRepliesAndOpenThem() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        let rootPost = app.buttons["postText-post-1"]
        XCTAssertTrue(rootPost.waitForExistence(timeout: 5))
        rootPost.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
        XCTAssertTrue(app.staticTexts["Replies"].waitForExistence(timeout: 5))

        let child = app.buttons["postText-post-branch-child"]
        XCTAssertTrue(child.waitForExistence(timeout: 5))
        XCTAssertFalse(app.buttons["viewReplies-post-branch-a"].exists)
        XCTAssertFalse(app.buttons["viewReplies-post-branch-b"].exists)
        let thread = app.scrollViews.firstMatch
        thread.swipeUp()
        if !child.isHittable { thread.swipeUp() }
        XCTAssertTrue(child.isHittable)
        let parent = app.buttons["postText-post-branch-a"]
        XCTAssertEqual(parent.frame.minX, child.frame.minX, accuracy: 1)
        XCTAssertEqual(parent.frame.width, child.frame.width, accuracy: 1)
        XCTAssertEqual(child.frame.minX, 16, accuracy: 1)
        XCTAssertFalse(app.staticTexts["selectedPostLabel"].exists)
        let screenshot = XCTAttachment(screenshot: app.screenshot())
        screenshot.name = "Full-width thread posts"
        screenshot.lifetime = .keepAlways
        add(screenshot)
        child.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
        XCTAssertFalse(app.buttons["postText-post-branch-b"].exists)
        app.navigationBars["Post"].buttons.element(boundBy: 0).tap()
        XCTAssertTrue(child.waitForExistence(timeout: 5))
    }

    func testLinearThreadOpensRemainingReplies() {
        let app = XCUIApplication()
        app.launchArguments = [
            "-ui-testing", "-ui-testing-signed-in", "-ui-testing-reply-branches", "-ui-testing-long-reply-branch"
        ]
        app.launch()
        let root = app.buttons["postText-post-1"]
        XCTAssertTrue(root.waitForExistence(timeout: 5))
        root.tap()
        let more = app.buttons["viewReplies-post-branch-a"]
        XCTAssertTrue(more.waitForExistence(timeout: 5))
        XCTAssertTrue(app.buttons["postText-post-branch-child"].exists)
        for index in 1...9 {
            XCTAssertTrue(app.buttons["postText-post-branch-preview-\(index)"].exists)
        }
        XCTAssertFalse(app.buttons["postText-post-branch-sibling"].exists)
        XCTAssertFalse(app.buttons["postText-post-branch-grandchild"].exists)
        XCTAssertTrue(app.buttons["viewReplies-post-branch-child"].exists)
        for _ in 0..<20 {
            if more.isHittable { break }
            app.scrollViews.firstMatch.swipeUp()
        }
        XCTAssertTrue(more.isHittable)
        more.tap()
        XCTAssertTrue(app.buttons["postText-post-branch-sibling"].waitForExistence(timeout: 5))
        XCTAssertFalse(app.buttons["postText-post-branch-b"].exists)
    }

    func testFeedLoadsNextPageOnlyAfterExplicitTap() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
        XCTAssertFalse(app.buttons["postText-post-4"].exists)
        let loadMoreButton = app.buttons["loadMorePostsButton"]
        for _ in 0..<5 {
            if loadMoreButton.exists && loadMoreButton.isHittable { break }
            app.swipeUp()
        }
        XCTAssertTrue(loadMoreButton.waitForExistence(timeout: 5))
        loadMoreButton.tap()
        XCTAssertTrue(app.buttons["postText-post-4"].waitForExistence(timeout: 5))
        XCTAssertFalse(app.buttons["loadMorePostsButton"].exists)
    }

    func testLoadedImageStaysVisibleAfterScrollingAwayAndBack() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-image-scroll"]
        app.launch()
        let firstRow = app.cells.containing(.button, identifier: "postText-image-scroll-0").firstMatch
        let image = firstRow.buttons["Attached image"].firstMatch
        XCTAssertTrue(image.waitForExistence(timeout: 5))
        let list = app.collectionViews.firstMatch
        func imageIsVisible() -> Bool {
            guard image.exists else { return false }
            let frame = image.frame
            return frame.height > 0 && frame.minY >= app.navigationBars.firstMatch.frame.maxY
                && frame.maxY <= app.tabBars.firstMatch.frame.minY
        }
        for _ in 0..<2 {
            for _ in 0..<4 { list.swipeUp() }
            XCTAssertFalse(imageIsVisible())
            for _ in 0..<8 {
                if imageIsVisible() { break }
                list.swipeDown()
            }
            XCTAssertTrue(imageIsVisible())
            XCTAssertFalse(firstRow.progressIndicators["inlineImageLoading"].exists)
        }
        image.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
        XCTAssertTrue(app.descendants(matching: .any)["imageViewerImage"].waitForExistence(timeout: 5))
    }

    func testLoadedImageStaysVisibleAfterTabChanges() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-image-grid", "1"]
        app.launch()
        let tile = app.buttons["Attached image"].firstMatch
        XCTAssertTrue(tile.waitForExistence(timeout: 5))
        for _ in 0..<2 {
            app.tabBars.buttons["Notifications"].tap()
            app.tabBars.buttons["Timeline"].tap()
            XCTAssertTrue(tile.exists)
            XCTAssertFalse(app.progressIndicators["inlineImageLoading"].exists)
        }
        tile.tap()
        XCTAssertTrue(app.descendants(matching: .any)["imageViewerImage"].waitForExistence(timeout: 5))
    }

    func testWideImageDoesNotExpandFeedRow() {
        let app = XCUIApplication()
        app.launchArguments = [
            "-ui-testing", "-ui-testing-signed-in", "-ui-testing-image-grid", "1", "-ui-testing-wide-image"
        ]
        app.launch()
        let row = app.cells.containing(.button, identifier: "postText-post-1").firstMatch
        let image = row.buttons["Attached image"].firstMatch
        XCTAssertTrue(image.waitForExistence(timeout: 10))
        let viewport = app.collectionViews.firstMatch.frame
        let attachment = XCTAttachment(screenshot: app.screenshot())
        attachment.name = "Wide image feed row"
        attachment.lifetime = .keepAlways
        add(attachment)
        for element in [image, row.buttons["postText-post-1"]] {
            XCTAssertGreaterThanOrEqual(element.frame.minX, viewport.minX - 1)
            XCTAssertLessThanOrEqual(element.frame.maxX, viewport.maxX + 1)
        }
        XCTAssertEqual(image.frame.height, 260, accuracy: 1)
    }

    func testSingleImageTileFillsItsSpaceAndViewerImageFitsViewport() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
        app.launchArguments.append("-ui-testing-signed-in")
        app.launch()

        let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)[
            "postImageGrid"]
        XCTAssertTrue(grid.waitForExistence(timeout: 5))
        let gridImage = grid.buttons["Attached image"]
        XCTAssertTrue(gridImage.waitForExistence(timeout: 5))
        let tile = gridImage
        XCTAssertTrue(tile.waitForExistence(timeout: 5))
        XCTAssertEqual(tile.frame.width, grid.frame.width, accuracy: 1)
        XCTAssertEqual(tile.frame.height, grid.frame.height, accuracy: 1)

        tile.tap()
        let viewerImage = app.descendants(matching: .any)["imageViewerImage"]
        XCTAssertTrue(viewerImage.waitForExistence(timeout: 5))
        let viewport = app.scrollViews.containing(.any, identifier: "imageViewerImage").firstMatch
        XCTAssertTrue(viewport.waitForExistence(timeout: 5))
        XCTAssertLessThanOrEqual(viewerImage.frame.width, viewport.frame.width + 1)
        XCTAssertLessThanOrEqual(viewerImage.frame.height, viewport.frame.height + 1)
        XCTAssertEqual(viewerImage.frame.width, viewerImage.frame.height, accuracy: 1)
        XCTAssertEqual(
            min(viewerImage.frame.width, viewerImage.frame.height),
            min(viewport.frame.width, viewport.frame.height),
            accuracy: 3
        )
    }
}