// Days and Sometime each keep their place (DECISIONS, 21 Nov 2026): away // to the other and back, the list stands where it was left. The word Days // tapped while Days stands goes back to today; so does the round button at // the bottom left, which stands only while today is off screen. Invented // crowd only. import XCTest final class DaysPlacesTests: DaysUITestCase { @MainActor private func todaysDate(_ app: XCUIApplication) -> XCUIElement { app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", "Today, ")).firstMatch } /// A row standing mid-screen, and where. @MainActor private func mark(_ app: XCUIApplication, _ words: String, _ what: String) -> (label: String, y: CGFloat)? { guard let row = DaysUI.middleRows(app, words).first else { XCTFail("a row stands mid-screen in \(what)"); return nil } return (row.label, row.frame.minY) } // RULE: Days → Sometime → Days → Sometime: each list stands where it was left. @MainActor func testSwitchingKeepsEachPlace() { let app = DaysUI.launch() DaysUI.days(app) for _ in 0..<3 { DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -350)) } settle(1.5) guard let inDays = mark(app, "Invented chore", "Days") else { return } DaysUI.button(app, "Sometime").tap() DaysUI.sometime(app) for _ in 0..<2 { DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -350)) } settle(1.5) guard let inSometime = mark(app, "Invented", "Sometime") else { return } XCTAssertFalse(DaysUI.seen(app).contains { $0.label.hasPrefix("Invented chore") }, "Days' rows stand out of reach while Sometime is chosen") DaysUI.button(app, "Days").tap() settle(2) XCTAssertEqual(DaysUI.whereIs(app, inDays.label, near: inDays.y) ?? -1000, inDays.y, accuracy: 4, "Days stands where it was left") XCTAssertFalse(todaysDate(app).isHittable, "Days did not go back to today") DaysUI.button(app, "Sometime").tap() settle(2) XCTAssertEqual(DaysUI.whereIs(app, inSometime.label, near: inSometime.y) ?? -1000, inSometime.y, accuracy: 4, "Sometime stands where it was left") } // RULE: far down Days, the word Days tapped goes back to today. @MainActor func testTappingDaysOnDaysGoesToToday() { let app = DaysUI.launch() DaysUI.days(app) for _ in 0..<5 { DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -400)) } settle(1.5) XCTAssertFalse(todaysDate(app).isHittable, "today's date scrolled away") DaysUI.button(app, "Days").tap() settle(2) let today = todaysDate(app) XCTAssertTrue(today.exists && today.isHittable, "Days went back to today") XCTAssertLessThan(today.frame.minY, app.windows.firstMatch.frame.height * 0.5, "today's date stands near the top") } // RULE: the round button at the bottom left, mirroring the +, stands only while today is off screen, and a tap goes back to today. @MainActor func testTheRoundTodayButtonGoesBackToToday() { let app = DaysUI.launch() DaysUI.days(app) let back = DaysUI.button(app, "Back to today") XCTAssertTrue(todaysDate(app).waitForExistence(timeout: 5), "today's date stands") settle(1.5) XCTAssertTrue(todaysDate(app).isHittable, "today's date is on screen") XCTAssertFalse(back.exists, "no button while today's date is on screen") XCTAssertFalse(DaysUI.button(app, "Today").exists, "the Today pill is gone") for _ in 0..<5 { DaysUI.drag(app, from: CGVector(dx: 0.5, dy: 0.75), by: CGVector(dx: 0, dy: -400)) } settle(1.5) XCTAssertTrue(back.waitForExistence(timeout: 3), "the button stands while today is away") let window = app.windows.firstMatch.frame let plus = DaysUI.button(app, "Add") XCTAssertLessThan(back.frame.midX, window.width * 0.3, "it stands at the bottom left") XCTAssertEqual(back.frame.midY, plus.frame.midY, accuracy: 2, "level with the +") XCTAssertEqual(back.frame.width, plus.frame.width, accuracy: 1, "as large as the +") let day = Calendar.current.component(.day, from: Date()) XCTAssertTrue(app.staticTexts["\(day)"].exists || back.label == "Back to today", "it shows today's date") back.tap() settle(2) let today = todaysDate(app) XCTAssertTrue(today.exists && today.isHittable, "a tap went back to today") XCTAssertTrue(back.waitForNonExistence(timeout: 3), "with today on screen the button goes") } }