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

geesawra.industries/old-fella

Old people's social media app

0
1
main
219 lines · 11.1 KB Raw History
import XCTest

extension OldFellaUITests {
    func testLikeViewUpdateCounts() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-profile-view-updates"]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.buttons["Notifications"].tap()
        XCTAssertTrue(app.buttons["notificationPost-notification-1"].waitForExistence(timeout: 5))
        app.tabBars.buttons["Timeline"].tap()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
        func recordedViews() -> Set<String> {
            let counts = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
            return Set(counts.split(separator: ";").compactMap { $0.split(separator: "=").first.map(String.init) })
        }
        let unrelatedViews = [
            "RootView", "SignedInTabView", "FeedView", "NotificationsView", "PostRow-post-3",
            "NotificationRow-notification-3"
        ]
        app.buttons["Read view update counts"].tap()
        let initialViews = recordedViews()
        for name in unrelatedViews { XCTAssertTrue(initialViews.contains(name), "Missing initial view: \(name)") }
        app.buttons["Reset view update counts"].tap()
        app.buttons["Like"].firstMatch.tap()
        XCTAssertTrue(app.buttons["Unlike"].firstMatch.waitForExistence(timeout: 5))
        app.buttons["Read view update counts"].tap()
        let counts = app.staticTexts["viewUpdateCounts"].value as? String ?? ""
        let attachment = XCTAttachment(string: counts)
        attachment.name = "Like action view updates"
        attachment.lifetime = .keepAlways
        add(attachment)
        print("Like action view updates: \(counts)")
        let updatedViews = recordedViews()
        XCTAssertTrue(updatedViews.contains("PostRow-post-1"))
        for name in unrelatedViews { XCTAssertFalse(updatedViews.contains(name), "Unrelated view updated: \(name)") }
    }

    func testPostShareActionsInFeedAndDetail() {
        continueAfterFailure = false
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-share"]
        app.launch()
        let uri = "at://did:plc:sharetest/app.bsky.feed.post/abc123"
        let controls = app.buttons["postControls-\(uri)"].firstMatch
        XCTAssertTrue(controls.waitForExistence(timeout: 5))
        controls.tap()
        let share = app.buttons["Share post"].firstMatch
        XCTAssertTrue(share.waitForExistence(timeout: 5))
        share.tap()
        let copy = app.otherElements["ActivityListView"].cells["Copy"].firstMatch
        let showsCopy = copy.waitForExistence(timeout: 15)
        let screenshot = XCTAttachment(screenshot: app.screenshot())
        screenshot.name = "Post share sheet"
        screenshot.lifetime = .keepAlways
        add(screenshot)
        XCTAssertTrue(showsCopy, app.debugDescription)
        copy.tap()
        XCTAssertTrue(copy.waitForNonExistence(timeout: 5))
        app.buttons["postText-\(uri)"].firstMatch.tap()
        XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
        controls.tap()
        let detailShare = app.buttons["Share post"].firstMatch
        XCTAssertTrue(detailShare.waitForExistence(timeout: 5))
        detailShare.tap()
        XCTAssertTrue(
            app.otherElements["ActivityListView"].waitForExistence(timeout: 5)
                || copy.waitForExistence(timeout: 5))
    }

    func testGeneratedAltTextOpensEditorAndCanBeEdited() {
        let app = XCUIApplication()
        app.launchArguments = [
            "-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-success"
        ]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.tabBars.buttons["New post"].tap()
        let attachment = app.buttons["editAltText-0"]
        XCTAssertTrue(attachment.waitForExistence(timeout: 5))
        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let editor = app.textViews["altTextEditor"]
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        let generate = app.buttons["generateAltText-0"]
        XCTAssertTrue(generate.waitForExistence(timeout: 5))
        generate.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
        let generatedText = NSPredicate(format: "value CONTAINS %@", "A generated description")
        expectation(for: generatedText, evaluatedWith: editor)
        waitForExpectations(timeout: 5)
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()

        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let editableText = app.textViews["altTextEditor"]
        XCTAssertTrue(editableText.waitForExistence(timeout: 5))
        app.buttons["generateAltText-0"].tap()
        let regeneratedText = NSPredicate(format: "value CONTAINS %@", "A generated description")
        expectation(for: regeneratedText, evaluatedWith: editableText)
        waitForExpectations(timeout: 5)
        editableText.tap()
        editableText.typeText(" edited")
        app.buttons["Save"].tap()
        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        XCTAssertTrue((app.textViews["altTextEditor"].value as? String ?? "").contains("edited"))
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
    }

    func testManualAltTextCanBeCancelledOrSaved() {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.tabBars.buttons["New post"].tap()
        let attachment = app.buttons["editAltText-0"]
        XCTAssertTrue(attachment.waitForExistence(timeout: 5))
        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let editor = app.textViews["altTextEditor"]
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        let originalText = editor.value as? String ?? ""
        let counter = app.staticTexts["altTextCharacterCount"]
        XCTAssertTrue(counter.waitForExistence(timeout: 5))
        XCTAssertTrue(counter.label.hasPrefix("7 of "))
        editor.tap()
        editor.typeText(" changed")
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()

        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let cancelledEditor = app.textViews["altTextEditor"]
        XCTAssertTrue(cancelledEditor.waitForExistence(timeout: 5))
        XCTAssertEqual(cancelledEditor.value as? String, originalText)
        cancelledEditor.tap()
        cancelledEditor.typeText(" saved")
        app.buttons["Save"].tap()

        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        XCTAssertTrue((app.textViews["altTextEditor"].value as? String ?? "").contains("saved"))
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
    }

    func testDelayedAltTextCanBeReviewed() {
        let app = XCUIApplication()
        app.launchArguments = [
            "-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-delayed"
        ]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.tabBars.buttons["New post"].tap()
        app.buttons["editAltText-0"].tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let editor = app.textViews["altTextEditor"]
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        let generate = app.buttons["generateAltText-0"]
        XCTAssertTrue(generate.waitForExistence(timeout: 5))
        generate.tap()
        XCTAssertTrue(app.buttons["stopGeneratingAltTextButton"].waitForExistence(timeout: 2))
        XCTAssertFalse(app.buttons["publishButton"].isEnabled)
        XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        let generatedText = NSPredicate(format: "value == %@", "A delayed description")
        expectation(for: generatedText, evaluatedWith: editor)
        waitForExpectations(timeout: 10)
        app.buttons["Save"].tap()
        app.buttons["editAltText-0"].tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A delayed description")
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
    }

    func testCancelDelayedAltTextKeepsComposerUsable() {
        let app = XCUIApplication()
        app.launchArguments = [
            "-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-alt-delayed"
        ]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.tabBars.buttons["New post"].tap()
        let attachment = app.buttons["editAltText-0"]
        XCTAssertTrue(attachment.waitForExistence(timeout: 5))
        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        let editor = app.textViews["altTextEditor"]
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        let generate = app.buttons["generateAltText-0"]
        XCTAssertTrue(generate.waitForExistence(timeout: 5))
        let stop = app.buttons["stopGeneratingAltTextButton"]
        generate.tap()
        XCTAssertTrue(stop.waitForExistence(timeout: 2))
        XCTAssertFalse(generate.exists)
        XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
        stop.tap()
        XCTAssertTrue(generate.waitForExistence(timeout: 2))
        XCTAssertFalse(stop.exists)
        XCTAssertTrue(app.navigationBars["Alt text editor"].exists)
        XCTAssertEqual(editor.value as? String, "A photo")
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
        XCTAssertTrue(app.buttons["publishButton"].isEnabled)
        XCTAssertTrue(app.textViews["composeTextField"].isEnabled)

        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A photo")
        app.buttons["generateAltText-0"].tap()
        let generatedText = NSPredicate(format: "value == %@", "A delayed description")
        expectation(for: generatedText, evaluatedWith: app.textViews["altTextEditor"])
        waitForExpectations(timeout: 10)
        XCTAssertFalse(app.alerts["Alt text unavailable"].exists)
        app.buttons["Save"].tap()
        attachment.tap()
        XCTAssertTrue(app.navigationBars["Alt text editor"].waitForExistence(timeout: 5))
        XCTAssertEqual(app.textViews["altTextEditor"].value as? String, "A delayed description")
        app.navigationBars["Alt text editor"].buttons["Cancel"].tap()
    }
}