@@ -126,9 +126,11 @@ final class GrainUITests: XCTestCase { } } /// A gallery's own screen (its carousel `zoom`): a tap on its picture /// opens it full screen in the lightbox, swiped to the next, closed by /// its ✕. What it read goes to GRAIN_SHOTS/zoom.txt. /// A gallery's own screen (its carousel `zoom`), opened from its card /// below its picture (a tap on a feed's picture opens nothing, a /// double-tap favorites): a tap on its picture opens it full screen in /// the lightbox, swiped to the next, closed by its ✕. What it read goes /// to GRAIN_SHOTS/zoom.txt. func testGalleryZoom() throws { XCTAssertTrue(app.staticTexts["·"].firstMatch.waitForExistence(timeout: 30), "No cards in Home's feed") let width = app.windows.firstMatch.frame.width @@ -138,8 +140,30 @@ final class GrainUITests: XCTestCase { } XCTAssertTrue(dots.exists, "No gallery of several pictures in Home's feed") let screen = app.windows.firstMatch.coordinate(withNormalizedOffset: .zero) // Its picture, above its dots: in the feed it opens the gallery. screen.withOffset(CGVector(dx: width / 2, dy: dots.frame.minY - 80)).tap() // Its card's title, the line below its ♡ row: in the feed it opens the // gallery. The feed is drawn up a little at a time until the title shows. func cardTitle() -> XCUIElement? { let all: [XCUIElement] = app.otherElements.matching(NSPredicate(format: "label BEGINSWITH 'Picture 1 of '")).allElementsBoundByIndex let hearts: [CGRect] = app.buttons.matching(NSPredicate(format: "label BEGINSWITH 'Favorite'")).allElementsBoundByIndex.map(\.frame) let texts: [XCUIElement] = app.staticTexts.allElementsBoundByIndex for shown in all.map(\.frame) where shown.minY > 100 { guard let heart = hearts.filter({ (f: CGRect) -> Bool in f.minY > shown.maxY }).min(by: { $0.minY < $1.minY }) else { continue } if let title = texts.first(where: { (t: XCUIElement) -> Bool in t.frame.minY > heart.maxY && t.frame.minY < heart.maxY + 60 && t.frame.maxY < 720 }) { return title } } return nil } var found = cardTitle() for _ in 0..<6 where found == nil { screen.withOffset(CGVector(dx: 30, dy: 600)).press(forDuration: 0.2, thenDragTo: screen.withOffset(CGVector(dx: 30, dy: 480)), withVelocity: .slow, thenHoldForDuration: 0.3) found = cardTitle() } guard let title = found else { shot("zoom-no-title") return XCTFail("No title on the gallery's card") } title.tap() let back = app.navigationBars.buttons.firstMatch XCTAssertTrue(back.waitForExistence(timeout: 15), "The card didn't open the gallery") XCTAssertTrue(dots.waitForExistence(timeout: 15), "The gallery's screen has no carousel") sleep(3) shot("zoom-gallery") @@ -198,10 +222,11 @@ final class GrainUITests: XCTestCase { shot("follows-you") } /// Signed in, someone's story has a 💬 at the end of its top row, before /// its ⋯; tapped, the comments come up as a sheet over the story, which /// waits under it: after six seconds and the sheet let go, the same story /// shows. What it measured goes to GRAIN_SHOTS/comments.txt. /// Signed in, someone's story has a 💬 and a ♡ at the end of its top /// row, before its ⋯; tapped, the 💬 brings the comments up as a sheet /// over the story, which waits under it: after six seconds and the sheet /// let go, the same story shows. What it measured goes to /// GRAIN_SHOTS/comments.txt. func testStoryComments() throws { XCTAssertTrue(app.staticTexts["·"].firstMatch.waitForExistence(timeout: 30), "No cards in Home's feed") sleep(2) @@ -215,20 +240,22 @@ final class GrainUITests: XCTestCase { // The page in front's: its neighbours, drawn either side, have theirs too. let width = app.windows.firstMatch.frame.width // From one snapshot, as each slide redraws its row as it goes on. func snapshotFrame(_ label: String) -> CGRect? { func snapshotFrame(_ label: String, prefix: Bool = false) -> CGRect? { func all(_ node: XCUIElementSnapshot) -> [XCUIElementSnapshot] { [node] + node.children.flatMap(all) } let found = ((try? all(app.snapshot())) ?? []).filter { $0.elementType == .button && $0.label == label }.map { $0.frame } let found = ((try? all(app.snapshot())) ?? []).filter { $0.elementType == .button && (prefix ? $0.label.localizedCaseInsensitiveContains(label) : $0.label == label) }.map { $0.frame } return found.first { (f: CGRect) -> Bool in f.minX >= 0 && f.maxX <= width + 1 } } XCTAssertTrue(app.buttons["Comments"].firstMatch.waitForExistence(timeout: 10), "No 💬 on the story") sleep(1) guard let comments = snapshotFrame("Comments"), let more = snapshotFrame("More") else { return XCTFail("No 💬 or ⋯ on the story in front") } guard let comments = snapshotFrame("Comments"), let heart = snapshotFrame("favorite", prefix: true), let more = snapshotFrame("More") else { return XCTFail("No 💬, ♡ or ⋯ on the story in front") } let cross = close.frame var lines = ["💬 \(comments) centre \(comments.midX), \(comments.midY)", "⋯ \(more) centre \(more.midX), \(more.midY)", "✕ \(cross) centre \(cross.midX), \(cross.midY)"] var lines = ["💬 \(comments) centre \(comments.midX), \(comments.midY)", "♡ \(heart) centre \(heart.midX), \(heart.midY)", "⋯ \(more) centre \(more.midX), \(more.midY)", "✕ \(cross) centre \(cross.midX), \(cross.midY)"] XCTAssertEqual(comments.width, 44, accuracy: 0.5) XCTAssertEqual(comments.height, 44, accuracy: 0.5) XCTAssertEqual(comments.midY, cross.midY, accuracy: 1, "The 💬 isn't on the ⋯ and ✕'s line") XCTAssertEqual(more.midX - comments.midX, 44, accuracy: 0.5, "The 💬 isn't just before the ⋯") XCTAssertEqual(heart.midY, cross.midY, accuracy: 1, "The ♡ isn't on the ⋯ and ✕'s line") XCTAssertEqual(heart.midX - comments.midX, 44, accuracy: 0.5, "The ♡ isn't just after the 💬") XCTAssertEqual(more.midX - heart.midX, 44, accuracy: 0.5, "The ♡ isn't just before the ⋯") shot("story-comments-row") // Which story the page in front shows, as VoiceOver reads it ("… 2 of 5"). func showing() -> String {