// Every sheet over Notes (a held row's acts, the list's More, a note's More, // Export, Info, the tag picker, a tag's hold and its icons) 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 that // starts on a row runs no act. A pull on a list scrolled down takes the list // back first (the shared LookPanel pull, f9dd5183ce; Android's NotesSheet, // 38fb329f72). A tap on a sheet's own ground keeps it. Invented notes only. import XCTest final class NotesPanelTests: NotesUITestCase { /// 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)) { NotesUI.drag(element, at: at, by: CGVector(dx: 0, dy: 340), hold: 0.05) } /// A tap on the scrim above a sheet (every one rises from the bottom), a little above its top mark. @MainActor private func tapAbove(_ app: XCUIApplication, _ mark: XCUIElement) { app.windows.firstMatch.coordinate(withNormalizedOffset: .zero) .withOffset(CGVector(dx: app.windows.firstMatch.frame.width / 2, dy: mark.frame.minY - 60)).tap() } /// Opens a sheet 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. After each /// close, `ran` (what a row's act would have opened) has not appeared. @MainActor private func opensAndCloses(_ app: XCUIApplication, _ name: String, mark: XCUIElement, row: XCUIElement?, ran: XCUIElement? = nil, open: () -> Void) { open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened") XCTAssertTrue(NotesUI.inside(mark, app), "\(name) stands inside the safe area") if let row { XCTAssertTrue(NotesUI.inside(row, app), "\(name)'s rows stand inside the safe area") } settle() pullDown(mark) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a pull down on \(name)'s title closed it") if let row { settle() open() XCTAssertTrue(row.waitForExistence(timeout: 5), "\(name) opened again with its rows") settle() pullDown(row, at: CGVector(dx: 0.3, dy: 0.5)) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a pull down on \(name)'s rows closed it") if let ran { XCTAssertFalse(ran.exists, "a pull on \(name)'s row ran no act") } } settle() open() XCTAssertTrue(mark.waitForExistence(timeout: 5), "\(name) opened once more") settle() tapAbove(app, mark) XCTAssertTrue(mark.waitForNonExistence(timeout: 3), "a tap above closed \(name)") settle() } /// Holds a row standing mid-screen; its title, read before the hold. @MainActor private func holdARow(_ app: XCUIApplication) -> String? { guard let row = NotesUI.middleRow(app) else { return nil } NotesUI.point(app, row, CGVector(dx: 0.5, dy: 0.4)).press(forDuration: 0.9) return row.label.components(separatedBy: ",").first } // RULE: a held row's acts open on a hold and close by a pull on their title, a pull on their rows, and a tap above. @MainActor func testAHeldRowsActsOpenAndClose() throws { let app = NotesUI.launch() NotesUI.list(app) try skipUnderTheShellsCard(app) NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.8), by: CGVector(dx: 0, dy: -300)) settle() guard let title = NotesUI.middleRow(app)?.label.components(separatedBy: ",").first else { return XCTFail("a row stands mid-screen") } let mark = app.staticTexts.matching(NSPredicate(format: "identifier == %@ AND label BEGINSWITH %@", "notes-act-title", title)).firstMatch opensAndCloses(app, "a held row's acts", mark: mark, row: NotesUI.id(app, "notes-act-tags"), ran: NotesUI.id(app, "tag-picker")) { _ = holdARow(app) } } // RULE: the list's More opens from its button and closes by a pull on its rows and a tap above; a pull on Settings opens no Settings. @MainActor func testTheListsMoreOpensAndCloses() throws { let app = NotesUI.launch() NotesUI.list(app) try skipUnderTheShellsCard(app) opensAndCloses(app, "the list's More", mark: NotesUI.id(app, "notes-act-settings"), row: NotesUI.id(app, "notes-act-import"), ran: NotesUI.id(app, "notes-settings")) { NotesUI.id(app, "notes-more").tap() } } // RULE: Export opens from a held row's acts and closes by a pull on its title and its formats, and a tap above. @MainActor func testExportOpensAndCloses() throws { let app = NotesUI.launch() NotesUI.list(app) try skipUnderTheShellsCard(app) NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.8), by: CGVector(dx: 0, dy: -300)) settle() let export = app.staticTexts.matching(NSPredicate(format: "identifier == %@ AND label == %@", "notes-act-title", "Export")).firstMatch opensAndCloses(app, "Export", mark: export, row: NotesUI.id(app, "notes-act-markdown")) { _ = holdARow(app) let act = NotesUI.id(app, "notes-act-export") if act.waitForExistence(timeout: 3) { act.tap() } } } // RULE: a note's More opens from its button and closes by a pull on its rows and a tap above; a pull on Tags opens no tag picker. @MainActor func testANotesMoreOpensAndCloses() throws { let app = NotesUI.launch(["-notes-open", "note"]) XCTAssertTrue(NotesUI.writer(app).waitForExistence(timeout: 90), "a note opened") try skipUnderTheShellsCard(app) opensAndCloses(app, "a note's More", mark: NotesUI.id(app, "notes-act-find"), row: NotesUI.id(app, "notes-act-tags"), ran: NotesUI.id(app, "tag-picker")) { NotesUI.id(app, "note-more").tap() } } // RULE: Info opens from its button and closes by a pull on its tabs, a pull on its facts, and a tap above. @MainActor func testInfoOpensAndCloses() throws { let app = NotesUI.launch(["-notes-open", "note"]) XCTAssertTrue(NotesUI.writer(app).waitForExistence(timeout: 90), "a note opened") try skipUnderTheShellsCard(app) let fact = app.staticTexts.matching(NSPredicate(format: "identifier BEGINSWITH %@", "info-fact-")).firstMatch opensAndCloses(app, "Info", mark: NotesUI.id(app, "info-tab-statistics"), row: fact) { NotesUI.id(app, "note-info").tap() } } // RULE: the tag picker closes by a pull on its title, on its offers, and a tap above; with its offers scrolled down, a pull takes them back up first. @MainActor func testTheTagPickerOpensAndCloses() throws { let app = NotesUI.launch(["-notes-open", "note"]) XCTAssertTrue(NotesUI.writer(app).waitForExistence(timeout: 90), "a note opened") try skipUnderTheShellsCard(app) let title = app.staticTexts["Tag this note"] let offer = app.buttons.matching(identifier: "tag-offer").firstMatch let open = { NotesUI.id(app, "note-more").tap() let tags = NotesUI.id(app, "notes-act-tags") if tags.waitForExistence(timeout: 3) { tags.tap() } } opensAndCloses(app, "the tag picker", mark: title, row: offer, open: open) // Scrolled down, the offers take a pull back up first; the next pull closes. open() XCTAssertTrue(offer.waitForExistence(timeout: 5), "the tag picker opened with its offers") settle() // Every offer stands in the tree, scrolled out of sight or not (the list is not lazy): the first offer // stays the first match, so a scroll shows as where it stands, and a pull goes to one that shows. let top = offer.frame.minY NotesUI.drag(offer, at: CGVector(dx: 0.5, dy: 0.5), by: CGVector(dx: 0, dy: -200)) settle() XCTAssertLessThan(offer.frame.minY, top - 60, "the offers scrolled down") guard let mid = shownOffer(app, 1) else { return XCTFail("an offer shows in the scrolled list") } pullDown(mid) settle() XCTAssertTrue(title.exists, "a pull on scrolled offers took them back up and kept the picker") XCTAssertEqual(offer.frame.minY, top, accuracy: 2, "the pull took the offers back to their top") guard let next = shownOffer(app, 1) else { return XCTFail("an offer shows at the list's top") } pullDown(next) XCTAssertTrue(title.waitForNonExistence(timeout: 3), "the next pull closed the picker") } /// The `n`th offer (from 0) that shows whole between the picker's field and its Done. @MainActor private func shownOffer(_ app: XCUIApplication, _ n: Int) -> XCUIElement? { let above = NotesUI.id(app, "tag-field").frame.maxY, below = NotesUI.id(app, "tag-done").frame.minY let shown = app.buttons.matching(identifier: "tag-offer").allElementsBoundByIndex .filter { $0.frame.minY >= above && $0.frame.maxY <= below } return shown.count > n ? shown[n] : nil } // RULE: a held tag's acts, and its icons, close by a pull and a tap above; the side page stays. @MainActor func testATagsHoldAndItsIconsOpenAndClose() throws { let app = NotesUI.launch(["-notes-open", "side"]) let side = NotesUI.id(app, "side-page") XCTAssertTrue(side.waitForExistence(timeout: 90), "the side page opened") let tag = NotesUI.id(app, "side-tag-crowd") XCTAssertTrue(tag.waitForExistence(timeout: 10), "the crowd's root tag stands") opensAndCloses(app, "a tag's acts", mark: app.staticTexts.matching(NSPredicate(format: "identifier == %@ AND label == %@", "notes-act-title", "#crowd")).firstMatch, row: NotesUI.id(app, "notes-act-icon")) { tag.press(forDuration: 0.9) } XCTAssertTrue(side.exists, "the side page stayed under its tag's acts") tag.press(forDuration: 0.9) let icon = NotesUI.id(app, "notes-act-icon") XCTAssertTrue(icon.waitForExistence(timeout: 3), "a tag's acts offer its icon") icon.tap() let any = app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "icon-")).element(boundBy: 2) XCTAssertTrue(any.waitForExistence(timeout: 5), "the icons opened") XCTAssertTrue(NotesUI.inside(any, app), "the icons stand inside the safe area") pullDown(any) XCTAssertTrue(any.waitForNonExistence(timeout: 3), "a pull down on the icons closed them") XCTAssertTrue(side.exists, "the side page stayed") } // RULE: a tap on a sheet's own words (a held row's title), not on an act, keeps it open. @MainActor func testATapOnASheetsTitleKeepsIt() throws { let app = NotesUI.launch() NotesUI.list(app) try skipUnderTheShellsCard(app) NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.8), by: CGVector(dx: 0, dy: -300)) settle() guard let row = NotesUI.middleRow(app) else { return XCTFail("a row stands mid-screen") } NotesUI.point(app, row, CGVector(dx: 0.5, dy: 0.4)).press(forDuration: 0.9) let title = NotesUI.id(app, "notes-act-title") XCTAssertTrue(title.waitForExistence(timeout: 3), "the hold opened the row's acts") settle() title.coordinate(withNormalizedOffset: CGVector(dx: 0.3, dy: 0.5)).tap() settle() XCTAssertTrue(title.exists, "a tap on the sheet's title kept it open") } }