import XCTest final class ImageGalleryTests: XCTestCase { func testFivePhotosFillTwoRows() { assertGallery(rowSizes: [3, 2]) } func testSevenPhotosFillTwoRows() { assertGallery(rowSizes: [4, 3]) } func testNinePhotosFillThreeRows() { assertGallery(rowSizes: [3, 3, 3]) } func testTenPhotosFillTwoRows() { assertGallery(rowSizes: [5, 5]) } func testAccessibilityTextUsesOneColumn() { assertGallery(rowSizes: [1, 1, 1, 1, 1], accessibilityText: true) } func testReplyContextShowsThreeImages() { assertGallery(rowSizes: [2, 1], isReplyContext: true) } func testReplyContextShowsFiveImages() { assertGallery(rowSizes: [3, 2], isReplyContext: true) } func testReplyContextShowsTenImages() { assertGallery(rowSizes: [5, 5], isReplyContext: true) } private func assertGallery(rowSizes: [Int], isReplyContext: Bool = false, accessibilityText: Bool = false) { let count = rowSizes.reduce(0, +) let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-image-grid", "\(count)"] if isReplyContext { app.launchArguments.append("-ui-testing-image-grid-reply-context") } if accessibilityText { app.launchArguments += ["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityM"] } app.launch() let container = isReplyContext ? app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch : app.cells.containing(.button, identifier: "postText-post-1").firstMatch XCTAssertTrue(container.waitForExistence(timeout: 5)) let grid = container.descendants(matching: .any)["postImageGrid"].firstMatch XCTAssertTrue(grid.waitForExistence(timeout: 5)) XCTAssertFalse(grid.buttons["showMoreImagesButton"].exists) let tileHeight: CGFloat = isReplyContext ? 80 : 112 var index = 1 for (rowIndex, rowSize) in rowSizes.enumerated() { let tileWidth = (grid.frame.width - CGFloat(rowSize - 1) * 6) / CGFloat(rowSize) for column in 0..