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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import XCTest
final class ThreadPostLayoutTests: XCTestCase {
func testNumberedPartsStayTogetherBeforeOtherReplies() {
let app = XCUIApplication()
app.launchArguments = [
"-ui-testing", "-ui-testing-signed-in", "-ui-testing-numbered-thread", "-ui-testing-thread-delay"
]
app.launch()
let root = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(root.waitForExistence(timeout: 5))
let rootBadge = app.staticTexts["threadPosition-post-1"]
XCTAssertFalse(rootBadge.exists)
root.tap()
let thread = app.scrollViews["threadScrollView"]
let loading = app.otherElements["postDetailLoading"].firstMatch
let threadHeading = thread.staticTexts["Thread Replies"]
let repliesHeading = thread.staticTexts["Replies"]
let reply = thread.buttons["openPost-post-2"]
XCTAssertTrue(loading.waitForExistence(timeout: 2))
XCTAssertFalse(thread.exists)
XCTAssertFalse(app.buttons["postText-post-1"].exists)
XCTAssertTrue(rootBadge.waitForExistence(timeout: 5))
XCTAssertFalse(loading.exists)
XCTAssertEqual(rootBadge.label, "Thread post 1 of 4")
var previous = rootBadge
for index in 2...4 {
let badge = thread.staticTexts["threadPosition-numbered-post-\(index)"]
XCTAssertTrue(badge.exists)
XCTAssertEqual(badge.label, "Thread post \(index) of 4")
XCTAssertLessThan(previous.frame.minY, badge.frame.minY)
previous = badge
}
let firstPart = thread.buttons["openPost-numbered-post-2"]
let lastPart = thread.buttons["openPost-numbered-post-4"]
XCTAssertTrue(threadHeading.exists)
XCTAssertTrue(firstPart.exists)
XCTAssertTrue(lastPart.exists)
XCTAssertTrue(repliesHeading.exists)
XCTAssertTrue(reply.exists)
XCTAssertLessThan(rootBadge.frame.maxY, threadHeading.frame.minY)
XCTAssertLessThan(threadHeading.frame.maxY, firstPart.frame.minY)
XCTAssertLessThan(lastPart.frame.maxY, repliesHeading.frame.minY)
XCTAssertLessThan(repliesHeading.frame.maxY, reply.frame.minY)
XCTAssertFalse(thread.staticTexts["threadPosition-post-2"].exists)
app.navigationBars["Post"].buttons.element(boundBy: 0).tap()
XCTAssertTrue(root.waitForExistence(timeout: 5))
root.tap()
XCTAssertTrue(loading.waitForExistence(timeout: 2))
XCTAssertFalse(thread.exists)
XCTAssertTrue(rootBadge.waitForExistence(timeout: 5))
}
func testShortReplyUsesOnlyItsContentHeight() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let root = app.buttons["postText-post-1"].firstMatch
XCTAssertTrue(root.waitForExistence(timeout: 5))
root.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
let thread = app.scrollViews["threadScrollView"]
let reply = thread.buttons["openPost-post-2"]
XCTAssertTrue(reply.waitForExistence(timeout: 5))
XCTAssertFalse(thread.staticTexts["Thread Replies"].exists)
XCTAssertTrue(thread.staticTexts["Replies"].exists)
let author = thread.buttons["profileLink-alex"]
let controls = thread.buttons["postControls-post-2"]
XCTAssertTrue(author.exists)
XCTAssertTrue(controls.exists)
XCTAssertEqual(author.frame.minY - reply.frame.minY, 20, accuracy: 1)
XCTAssertEqual(reply.frame.maxY - controls.frame.maxY, 16, accuracy: 1)
let screenshot = XCTAttachment(screenshot: app.screenshot())
screenshot.name = "Short reply content height"
screenshot.lifetime = .keepAlways
add(screenshot)
}
}