// The keyboard in Notes never hides what is being typed: the search field,// the tag picker's field and its Done (upright and at the largest text) and// the note's own words all stand above it. A drag down puts it away, and a// tap outside a field does too (the app's one keyboard rule,// Chrome/KeyboardDismissal.swift). Invented notes only.import XCTestfinalclassNotesKeyboardTests: NotesUITestCase { @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 search field stands above the keyboard, and a drag down on the list puts the keyboard away with the words kept. @MainActor func testSearchStandsAboveTheKeyboard() throws {let app = NotesUI.launch()NotesUI.list(app)try skipUnderTheShellsCard(app)let field = NotesUI.id(app, "notes-search-field") field.tap()let keys = NotesUI.keyboard(app) above(field, keys, "the search field") field.typeText("Invented") settle()NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.3), by: CGVector(dx: 0, dy: 300)) XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a drag down on the list put the keyboard away") XCTAssertEqual(field.value as? String, "Invented", "the words looked for stayed") }// RULE: with the keyboard up for search, a tap on the search box's own ground, outside its words, puts the keyboard away (the app's tap rule). @MainActor func testATapOutsideSearchPutsTheKeyboardAway() throws {let app = NotesUI.launch()NotesUI.list(app)try skipUnderTheShellsCard(app)let field = NotesUI.id(app, "notes-search-field") field.tap()let keys = NotesUI.keyboard(app)// The search box's magnifier, at the left of the field's words: no field, no button.let gap = field.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0.5)).withOffset(CGVector(dx: -18, dy: 0)) gap.tap() XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a tap outside the search field put the keyboard away") XCTAssertFalse(NotesUI.id(app, "side-page").exists, "and opened nothing") }// RULE: the tag picker's field and Done stand above the keyboard; a tap on its title puts the keyboard away and keeps the picker. @MainActor func testTheTagPickerStandsAboveTheKeyboard() throws {let app = NotesUI.launch(["-notes-open", "tags"])let field = NotesUI.id(app, "tag-field") XCTAssertTrue(field.waitForExistence(timeout: 90), "the tag picker opened")try skipUnderTheShellsCard(app, wait: 0) field.tap()let keys = NotesUI.keyboard(app) above(field, keys, "the tag field") above(NotesUI.id(app, "tag-done"), keys, "Done") field.typeText("crowd/") settle() above(field, keys, "the tag field with words in it") app.staticTexts["Tag this note"].tap() XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a tap on the picker's title put the keyboard away") XCTAssertTrue(field.exists, "the tag picker stayed") }// RULE: at the largest text, the tag picker's field and Done stand above the keyboard. @MainActor func testTheTagPickerStandsAboveTheKeyboardAtTheLargestText() throws {let app = NotesUI.launch(NotesUI.largestText + ["-notes-open", "many"])let field = NotesUI.id(app, "tag-field") XCTAssertTrue(field.waitForExistence(timeout: 90), "the tag picker opened on the note with many tags") field.tap()let keys = NotesUI.keyboard(app) above(field, keys, "the tag field") above(NotesUI.id(app, "tag-done"), keys, "Done") }// RULE: a new note's words and the key bar stand above the keyboard, and a drag down the note puts the keyboard away. @MainActor func testANotesWordsStandAboveTheKeyboard() throws {let app = NotesUI.launch(["-notes-open", "bar"])let writer = NotesUI.writer(app) XCTAssertTrue(writer.waitForExistence(timeout: 90), "a note opened")try skipUnderTheShellsCard(app, wait: 0)let keys = NotesUI.keyboard(app) writer.typeText("\nInvented words typed at the caret") settle()let typed = app.staticTexts.matching(NSPredicate(format: "label CONTAINS %@", "Invented words typed")).firstMatchif typed.exists { above(typed, keys, "the words typed") }let back = NotesUI.id(app, "note-back") XCTAssertTrue(NotesUI.inside(back, app), "Back stands inside the safe area with the keyboard up")NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.25), by: CGVector(dx: 0, dy: 520)) XCTAssertTrue(keys.waitForNonExistence(timeout: 4), "a drag down the note put the keyboard away") }}