Cotton code
95 lines · 5.7 KB · SwiftRaw
// A hold on a row opens its acts and moves nothing; a tap opens the note; a// read (coming back to the app, back from a note) keeps the list where it// stands, as Android's keyed list does (9e95dcb983). The tag picker shows// every one of a note's tags, wrapped, and offers every tag, at the largest// text too (Android 1f20eb2031, c56e1758d8). Invented notes only.import XCTestfinal class NotesHoldTests: NotesUITestCase {    // RULE: a still hold on a row opens its acts and leaves the list where it was.    @MainActor func testAStillHoldOpensTheActsAndMovesNothing() 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.5)).press(forDuration: 0.9)        XCTAssertTrue(NotesUI.id(app, "notes-act-pin").waitForExistence(timeout: 3), "the hold opened the row's acts")        XCTAssertFalse(NotesUI.writer(app).exists, "the hold opened no note")        NotesUI.id(app, "notes-act-scrim").coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1)).tap()        settle()        let now = NotesUI.whereIs(app, row.label) ?? -1        XCTAssertEqual(now, row.frame.minY, accuracy: 4, "the list stood still under the hold")    }    // RULE: coming back to the app, and back from a note, the list keeps its place.    @MainActor func testAReadKeepsTheListsPlace() throws {        let app = NotesUI.launch()        NotesUI.list(app)        try skipUnderTheShellsCard(app)        // What the dev account holds comes down first: the list is read whole before the place is taken.        settle(8)        for _ in 0..<3 { NotesUI.drag(app, from: CGVector(dx: 0.5, dy: 0.8), by: CGVector(dx: 0, dy: -400)) }        settle(1)        guard let row = NotesUI.middleRow(app) else { return XCTFail("a row stands mid-screen") }        XCUIDevice.shared.press(.home)        settle(1)        app.activate()        settle(2)        let back = NotesUI.whereIs(app, row.label)        XCTAssertNotNil(back, "\(row.label) still stands on screen after coming back to the app")        if let back { XCTAssertEqual(back, row.frame.minY, accuracy: 30, "the list kept its place after a read") }        // Back from a note opened above it.        let rows = NotesUI.rowsOnScreen(app)        guard let above = rows.last(where: { $0.frame.maxY < row.frame.minY && $0.frame.minY > 150 }) else { return }        NotesUI.point(app, above, CGVector(dx: 0.5, dy: 0.5)).tap()        XCTAssertTrue(NotesUI.writer(app).waitForExistence(timeout: 5), "a note opened")        NotesUI.id(app, "note-back").tap()        XCTAssertTrue(NotesUI.writer(app).waitForNonExistence(timeout: 5), "Back closed it")        settle(1)        let after = NotesUI.whereIs(app, row.label)        XCTAssertNotNil(after, "\(row.label) still stands on screen after Back")        if let after { XCTAssertEqual(after, row.frame.minY, accuracy: 120, "the list kept its place after Back") }    }    // RULE: at the largest text, every one of a note's seven tags stands in the picker as a chip with its words (none squeezed to a letter a line), and every tag is offered.    @MainActor func testTheTagPickerShowsEveryTagAtTheLargestText() 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")        XCTAssertTrue(NotesUI.inside(field, app), "the tag field stands inside the safe area")        XCTAssertTrue(NotesUI.inside(NotesUI.id(app, "tag-done"), app), "Done stands inside the safe area")        var chips: Set<String> = []        let mine = app.buttons.matching(identifier: "tag-mine")        for _ in 0..<10 {            for chip in NotesUI.seen(app) where chip.id == "tag-mine" && chip.frame.height > 0 && NotesUI.inside(chip.frame, app) {                XCTAssertGreaterThanOrEqual(chip.frame.width, chip.frame.height * 0.9, "\(chip.label) keeps its words on a line or two, not a letter a line (\(chip.frame))")                chips.insert(chip.label)            }            if chips.count >= 7 { break }            // The chips scroll when they are more than their room.            NotesUI.drag(mine.element(boundBy: 0), at: CGVector(dx: 0.5, dy: 0.5), by: CGVector(dx: 0, dy: -80))            settle()        }        XCTAssertGreaterThanOrEqual(chips.count, 7, "every one of the note's seven tags stands in the picker: \(chips.sorted())")    }    // RULE: the tag picker offers every tag, past thirty (as Android, c56e1758d8).    @MainActor func testTheTagPickerOffersEveryTag() throws {        let app = NotesUI.launch(["-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")        var offered: Set<String> = []        let offers = app.buttons.matching(identifier: "tag-offer")        for _ in 0..<12 {            NotesUI.seen(app).filter { $0.id == "tag-offer" }.forEach { offered.insert($0.label) }            guard offers.count > 2 else { break }            NotesUI.drag(offers.element(boundBy: offers.count / 2), at: CGVector(dx: 0.5, dy: 0.5), by: CGVector(dx: 0, dy: -150))            settle()        }        // Thirty-six crowd tags and the seed's own, seven worn by the note: more than thirty offered.        XCTAssertGreaterThan(offered.count, 30, "every tag the note does not wear is offered, past thirty: \(offered.count)")    }}