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

geesawra.industries/old-fella

Old people's social media app

0
1
main
35 lines · 1.8 KB Raw History
import XCTest

final class ComposerCharacterCountUITests: XCTestCase {
    func testCountShowsExcessAndRecoversWithoutMovingButtons() {
        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()
        let editor = app.textViews["composeTextField"]
        XCTAssertTrue(editor.waitForExistence(timeout: 5))
        editor.tap()
        let counter = app.descendants(matching: .any)["composeCharacterCount"].firstMatch
        XCTAssertTrue(counter.waitForExistence(timeout: 5))
        XCTAssertEqual(counter.label, "0 of 300 characters")
        let initialCounterWidth = counter.frame.width
        let photoButtonFrame = app.buttons["addPhotosButton"].frame
        let draftsButtonFrame = app.buttons["draftsButton"].frame

        editor.typeText(String(repeating: "a", count: 42))
        XCTAssertEqual(counter.label, "42 of 300 characters")
        editor.typeText(String(repeating: "a", count: 238))
        XCTAssertEqual(counter.label, "280 of 300 characters")
        editor.typeText(String(repeating: "a", count: 27))
        XCTAssertEqual(counter.label, "307 of 300 characters, 7 over the limit")
        XCTAssertGreaterThan(counter.frame.width, initialCounterWidth)
        XCTAssertFalse(app.buttons["publishButton"].isEnabled)
        XCTAssertEqual(app.buttons["addPhotosButton"].frame, photoButtonFrame)
        XCTAssertEqual(app.buttons["draftsButton"].frame, draftsButtonFrame)

        editor.typeText(String(repeating: XCUIKeyboardKey.delete.rawValue, count: 8))
        XCTAssertEqual(counter.label, "299 of 300 characters")
        XCTAssertTrue(app.buttons["publishButton"].isEnabled)
    }
}