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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 ")
}
}