// The keyboard in Days never hides what is being typed: the adding bar// (upright and at the largest text), the item's title and note, and When's// time all stand above it; a drag down puts it away, and a tap on the bar's// own Add keeps it up for the next line. Invented days only.import XCTestfinalclassDaysKeyboardTests: DaysUITestCase { @MainActor privatefunc above(_ element: XCUIElement, _ keys: XCUIElement, _ what: String) { XCTAssertTrue(element.exists, "\(what) is there") XCTAssertLessThanOrEqual(element.frame.maxY, keys.frame.minY + 1, "\(what) stands above the keyboard") XCTAssertGreaterThan(element.frame.minY, 44, "\(what) stands under the clock, not above the screen") }// RULE: the adding bar stands whole above the keyboard, and a drag down on the list puts the keyboard away. @MainActor func testTheAddingBarStandsAboveTheKeyboard() throws {let app = DaysUI.launch()DaysUI.days(app)try skipUnderTheShellsCard(app)DaysUI.button(app, "Add").tap()let field = DaysUI.field(app, "What, and when?") XCTAssertTrue(field.waitForExistence(timeout: 5), "the adding bar opened")let keys = DaysUI.keyboard(app) above(field, keys, "the line being typed") above(DaysUI.button(app, "Close"), keys, "the bar's close") field.typeText("Invented keyboard check") above(DaysUI.button(app, "Add"), keys, "Add") above(app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Understood as")).firstMatch, keys, "the pill")DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.25), by: CGVector(dx: 0, dy: 300)) XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a drag down on the list put the keyboard away") XCTAssertTrue(field.exists, "the adding bar stayed, with its words") }// RULE: a tap outside the adding bar, on the list, puts the keyboard away and opens nothing. @MainActor func testATapOnTheListPutsTheKeyboardAway() throws {let app = DaysUI.launch()DaysUI.days(app)try skipUnderTheShellsCard(app)DaysUI.button(app, "Add").tap()let keys = DaysUI.keyboard(app)// Today's date: a tap there with the keyboard up only puts it away.let today = app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Today, ")).firstMatch XCTAssertTrue(today.exists) app.windows.firstMatch.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.3)).tap() XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a tap on the list put the keyboard away") }// RULE: the item's title and note stand above the keyboard as they are typed in. @MainActor func testTheItemsFieldsStandAboveTheKeyboard() throws {let app = DaysUI.launch(["-days-open", "todo"])let title = DaysUI.field(app, "Title") XCTAssertTrue(title.waitForExistence(timeout: 90), "the item's sheet opened")try skipUnderTheShellsCard(app, wait: 0) title.tap()let keys = DaysUI.keyboard(app) above(title, keys, "the title")let note = DaysUI.field(app, "Note") XCTAssertTrue(note.exists, "the note is on the sheet")// Scroll it up into reach, as a person would, then type in it.for _ in0..<6where !(note.isHittable && note.frame.maxY < keys.frame.minY) {DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.45), by: CGVector(dx: 0, dy: -150)) } note.tap()let keys2 = DaysUI.keyboard(app) above(note, keys2, "the note") }// RULE: at the largest text, When's time field stands above the keyboard. @MainActor func testWhensTimeStandsAboveTheKeyboardAtTheLargestText() throws {let app = DaysUI.launch(DaysUI.largestText + ["-days-open", "when"])let time = DaysUI.field(app, "Time") XCTAssertTrue(time.waitForExistence(timeout: 90), "When opened")try skipUnderTheShellsCard(app, wait: 0)for _ in0..<6where !(time.isHittable && DaysUI.inside(time, app, bottom: 120)) {DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.7), by: CGVector(dx: 0, dy: -200)) } time.tap()let keys = DaysUI.keyboard(app) above(time, keys, "When's time") }}