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

geesawra.industries/old-fella

Old people's social media app

0
1
main
59 lines · 2.5 KB Raw History
import XCTest

final class ComposerEmojiUITests: XCTestCase {
    private func openComposer() -> XCUIApplication {
        let app = XCUIApplication()
        app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
        app.launch()
        XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10))
        app.buttons["New post"].tap()
        XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5))
        app.textViews["composeTextField"].tap()
        return app
    }

    func testChoosingEmojiReplacesShortcodeAndKeepsTyping() {
        let app = openComposer()
        let editor = app.textViews["composeTextField"]
        editor.typeText("Hello :eye")
        let eyes = app.buttons["emojiSuggestion-eyes"]
        XCTAssertTrue(eyes.waitForExistence(timeout: 5))
        XCTAssertTrue(eyes.isHittable)
        XCTAssertEqual(eyes.frame.maxX, app.frame.maxX - 16, accuracy: 1)
        XCTAssertLessThan(eyes.frame.maxY, app.keyboards.firstMatch.frame.minY)
        let screenshot = XCTAttachment(screenshot: app.screenshot())
        screenshot.name = "Emoji suggestions"
        screenshot.lifetime = .keepAlways
        add(screenshot)
        eyes.tap()
        XCTAssertEqual(editor.value as? String, "Hello 👀 ")
        XCTAssertFalse(app.buttons["emojiSuggestion-eyes"].exists)

        editor.typeText("again :joy")
        let joy = app.buttons["emojiSuggestion-joy"]
        XCTAssertTrue(joy.waitForExistence(timeout: 5))
        joy.tap()
        XCTAssertEqual(editor.value as? String, "Hello 👀 again 😂 ")
        editor.typeText("done")
        XCTAssertEqual(editor.value as? String, "Hello 👀 again 😂 done")
    }

    func testSuggestionsUpdateAndDismissWithoutChangingText() {
        let app = openComposer()
        let editor = app.textViews["composeTextField"]
        editor.typeText(":eyes")
        let eyes = app.buttons["emojiSuggestion-eyes"]
        XCTAssertTrue(eyes.waitForExistence(timeout: 5))
        editor.typeText(" ")
        XCTAssertTrue(eyes.waitForNonExistence(timeout: 3))
        XCTAssertEqual(editor.value as? String, ":eyes ")

        editor.typeText(":not_an_emoji")
        XCTAssertFalse(app.scrollViews["emojiSuggestions"].exists)
        editor.typeText("\n@ma")
        XCTAssertTrue(app.buttons["mentionSuggestion-mae"].waitForExistence(timeout: 5))
        XCTAssertFalse(eyes.exists)
        app.buttons["mentionSuggestion-mae"].tap()
        XCTAssertEqual(editor.value as? String, ":eyes :not_an_emoji\n@mae.example ")
    }
}