Cotton code
45 lines · 2.7 KB · SwiftRaw
// A row has two gestures only (DECISIONS, 21 Nov 2026): a hold is nothing// of its own. Held still it changes nothing; held and then dragged it is a// scroll, and nothing moves to another day.import XCTestfinal class DaysHoldTests: DaysUITestCase {    // RULE: a still hold on a row ticks nothing, moves nothing and opens nothing.    @MainActor func testAStillHoldChangesNothing() {        let app = DaysUI.launch()        DaysUI.days(app)        DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -300))        settle()        guard let row = DaysUI.middleChore(app) else { return XCTFail("a to-do stands mid-screen") }        let label = row.label        let y = row.frame.minY        DaysUI.point(app, row, CGVector(dx: 0.5, dy: 0.5)).press(forDuration: 1.0)        settle()        XCTAssertFalse(DaysUI.undo(app).exists, "a still hold ticked nothing")        XCTAssertFalse(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Moved to ")).firstMatch.exists, "a still hold moved nothing")        XCTAssertFalse(DaysUI.button(app, "Save").exists, "a still hold opened no item")        XCTAssertFalse(app.staticTexts["ANOTHER DAY"].exists, "a still hold offered no other day")        XCTAssertEqual(DaysUI.whereIs(app, label, near: y) ?? -1, y, accuracy: 2, "the row stands where it was")    }    // RULE: a hold on a row then a drag up scrolls the list like any swipe; nothing is lifted or moved to another day.    @MainActor func testAHoldThenADragScrollsAndMovesNothing() {        let app = DaysUI.launch()        DaysUI.days(app)        DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -300))        settle()        guard let row = DaysUI.middleChore(app) else { return XCTFail("a to-do stands mid-screen") }        let words = DaysUI.words(row.label)        let y = row.frame.minY        let from = DaysUI.point(app, row, CGVector(dx: 0.5, dy: 0.5))        from.press(forDuration: 0.8, thenDragTo: from.withOffset(CGVector(dx: 0, dy: -220)), withVelocity: .slow, thenHoldForDuration: 0.3)        settle(1.5)        XCTAssertFalse(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Moved to ")).firstMatch.exists, "the hold and drag moved nothing")        // Followed by its words (the synced crowd may hold copies of it, done or not).        let now = DaysUI.seen(app).filter { $0.type == .button && $0.label.hasPrefix(words + ",") }.map(\.frame.minY).min { abs($0 - (y - 220)) < abs($1 - (y - 220)) }        XCTAssertNotNil(now, "\(words) still stands")        XCTAssertFalse(DaysUI.button(app, "Save").exists, "the hold and drag opened nothing")        XCTAssertLessThan(now ?? .infinity, y - 120, "the list scrolled up under the drag")    }}