Cotton code
65 lines · 3.9 KB · SwiftRaw
// Words' tags in a note (FEEDBACK-4 C, owner 23 Nov 2026): the bar's `#` types `#` in the note and the tags it may// begin stand in the bar's quiet row above the keyboard, never over the words, typing on continuing the tag (C2);// a tag tapped in a note opens the list of the notes that carry it (C1). On the crowd's invented tags.import XCTestfinal class NotesTagTests: NotesUITestCase {    /// A new note, its keyboard up.    @MainActor private func newNote() -> (XCUIApplication, XCUIElement) {        let app = NotesUI.launch(["-notes-open", "list"])        let compose = NotesUI.id(app, "notes-compose")        XCTAssertTrue(compose.waitForExistence(timeout: 90), "the list stands")        compose.tap()        let body = NotesUI.writer(app)        XCTAssertTrue(body.waitForExistence(timeout: 20), "a new note opened")        _ = NotesUI.keyboard(app)        return (app, body)    }    @MainActor private func offers(_ app: XCUIApplication) -> XCUIElementQuery {        app.descendants(matching: .any).matching(identifier: "writing-tag-offer")    }    // RULE (C2): the bar's # types # in the note, raises nothing over it, and offers the tags in the bar above the    // keyboard; typing on continues the tag in the note; an offer taken is written in place.    @MainActor func testTheTagKeyTypesInTheNote() {        let (app, body) = newNote()        body.typeText("Invented market day\nBring the bag")        NotesUI.id(app, "writing-bar-tag").tap()        XCTAssertFalse(NotesUI.id(app, "tag-field").waitForExistence(timeout: 2), "no picker is raised over the note")        XCTAssertTrue((body.value as? String ?? "").hasSuffix("Bring the bag #"), "# is typed in the note, a space before it")        XCTAssertTrue(offers(app).firstMatch.waitForExistence(timeout: 10), "the tags are offered")        let keys = app.keyboards.firstMatch        let offer = offers(app).firstMatch        XCTAssertLessThanOrEqual(offer.frame.maxY, keys.frame.minY + 1, "the offers stand above the keyboard")        XCTAssertGreaterThanOrEqual(offer.frame.minY, keys.frame.minY - 100, "in the bar, just above it (the keyboard's own suggestions between)")        body.typeText("crowd")        XCTAssertTrue((body.value as? String ?? "").hasSuffix("#crowd"), "typing on continues the tag in the note")        XCTAssertTrue(offers(app).firstMatch.waitForExistence(timeout: 10), "the crowd's tags are offered")        let taken = offers(app).firstMatch.label        XCTAssertTrue(taken.hasPrefix("#crowd/"), "an offer is a crowd tag, \(taken)")        offers(app).firstMatch.tap()        XCTAssertTrue((body.value as? String ?? "").hasSuffix("Bring the bag \(taken) "), "the offer is written in place")    }    // RULE (C1): a tag tapped in a note opens the list of the notes that carry it.    @MainActor func testATagTappedOpensItsList() {        let (app, body) = newNote()        NotesUI.id(app, "writing-bar-tag").tap()        body.typeText("crowd")        XCTAssertTrue(offers(app).firstMatch.waitForExistence(timeout: 10), "the crowd's tags are offered")        let taken = offers(app).firstMatch.label        offers(app).firstMatch.tap()        body.typeText("\nInvented words under a tag")        NotesUI.id(app, "writing-bar-hide_keyboard").tap()        XCTAssertTrue(app.keyboards.firstMatch.waitForNonExistence(timeout: 4), "the keyboard went away")        // The tag is the note's first words, at the text's top left (its margin, 24, and inset, 8).        body.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: 24 + 16, dy: 8 + 12)).tap()        XCTAssertTrue(body.waitForNonExistence(timeout: 6), "the note closed")        let name = String(taken.dropFirst()).components(separatedBy: "/").last ?? taken        let place = NotesUI.id(app, "notes-place")        XCTAssertTrue(place.waitForExistence(timeout: 10), "the list stands")        XCTAssertTrue(place.label.contains(name), "the list stands on the tag tapped, \(taken): \(place.label)")    }}