// Every panel over Days (the month, the item's sheet, the // filter, When) opens from what names it, stands inside the safe area, and // closes by a pull down on its title, by a pull down on its rows, and by a // tap above it; a pull on a list scrolled down takes the list back first // (the shared LookPanel, f9dd5183ce; Android e88082f68c). A tap on a panel's // own blank paper keeps it (Android 24d736f97e). Settings goes by Back. // Invented days only. import XCTest final class DaysPanelTests: DaysUITestCase { /// A pull down from `element` by most of the screen. @MainActor private func pullDown(_ element: XCUIElement, at: CGVector = CGVector(dx: 0.5, dy: 0.5)) { DaysUI.drag(element, at: at, by: CGVector(dx: 0, dy: 340), hold: 0.05) } /// A tap on the scrim above a tall panel (it stands 48 points under Days' own top, `top`). @MainActor private func tapAbove(_ app: XCUIApplication, _ top: CGFloat) { app.windows.firstMatch.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: app.windows.firstMatch.frame.width / 2, dy: top + 22)).tap() } /// Opens a panel by `open` and sees `mark`; closes it by a pull from `mark`, /// then (opened again) by a pull from `row`, then by a tap above. @MainActor private func opensAndCloses(_ app: XCUIApplication, _ name: String, mark: XCUIElement, row: XCUIElement?, open: () -> Void) throws { _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5) try skipUnderTheShellsCard(app, wait: 0) open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened") XCTAssertTrue(DaysUI.inside(mark, app), "\(name) stands inside the safe area") pullDown(mark) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a pull down on \(name)'s title closed it") if let row { _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5) open() XCTAssertTrue(row.waitForExistence(timeout: 5), "\(name) opened again with its rows") pullDown(row, at: CGVector(dx: 0.3, dy: 0.5)) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a pull down on \(name)'s rows closed it") } _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5) open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened once more") // Days' top as it stands under the panel: the shell's card, when one stands, steps aside for a panel. _ = app.buttons["__settle__"].waitForExistence(timeout: 0.5) tapAbove(app, daysTop(app)) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a tap above closed \(name)") } // RULE: the month opens from today's date and closes by a pull on its title, a pull on its days, and a tap above, over Days scrolled to today (its list not at its top). @MainActor func testTheMonthOpensAndCloses() throws { let app = DaysUI.launch() DaysUI.days(app) try skipUnderTheShellsCard(app) let today = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Today, ")).firstMatch XCTAssertTrue(today.waitForExistence(timeout: 5), "today's date stands") try opensAndCloses(app, "the month", mark: DaysUI.button(app, "Previous month"), row: app.buttons.matching(NSPredicate(format: "label CONTAINS %@", " 15 ")).firstMatch, open: { today.tap() }) } // RULE: When (the adding pill) opens and closes by a pull on its title, its chips, and a tap above. @MainActor func testWhenOpensAndCloses() throws { let app = DaysUI.launch(["-days-open", "adding"]) DaysUI.days(app) try skipUnderTheShellsCard(app) let pill = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Understood as")).firstMatch XCTAssertTrue(pill.waitForExistence(timeout: 5), "the adding bar shows the pill") try opensAndCloses(app, "When", mark: app.staticTexts["WHEN"], row: app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Tomorrow")).firstMatch, open: { pill.tap() }) } // RULE: a tap on a panel's own blank paper keeps it open. @MainActor func testATapOnAPanelsBlankPaperKeepsIt() throws { let app = DaysUI.launch(["-days-open", "groups"]) let mark = app.staticTexts["SHOW"] XCTAssertTrue(mark.waitForExistence(timeout: 90), "the filter opened") try skipUnderTheShellsCard(app, wait: 0) // Under its last row (Done): Show's rows fill the rest. let last = DaysUI.button(app, "Done") XCTAssertTrue(last.exists, "Show lists Done last") app.windows.firstMatch.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: app.windows.firstMatch.frame.width * 0.5, dy: min(last.frame.maxY + 26, app.windows.firstMatch.frame.maxY - 30))).tap() settle() XCTAssertTrue(mark.exists, "a tap on Show's blank paper kept it open") let move = DaysUI.launch(["-days-open", "jump"]) let previous = DaysUI.button(move, "Previous month") XCTAssertTrue(previous.waitForExistence(timeout: 90), "the month opened") // Beside the grabber. previous.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: -150, dy: -12)).tap() settle() XCTAssertTrue(previous.exists, "a tap beside the month's grabber kept it open") } }