1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
}
}