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) } }