Glimmer / app · glimmertoday.ai / native / GlimmerUITests / GlimmerUITests.swift
| 1 | import XCTest |
| 2 | |
| 3 | @MainActor |
| 4 | final class GlimmerUITests: XCTestCase { |
| 5 | override func setUp() { |
| 6 | super.setUp() |
| 7 | continueAfterFailure = false |
| 8 | } |
| 9 | |
| 10 | #if os(macOS) |
| 11 | func testTodayInlineQuickActionsReceivePointerClicks() { |
| 12 | let app = makeApp() |
| 13 | app.launchArguments += ["-ApplePersistenceIgnoreState", "YES", "-NSQuitAlwaysKeepsWindows", "NO"] |
| 14 | app.launch() |
| 15 | if !app.windows.firstMatch.waitForExistence(timeout: 3) { |
| 16 | app.typeKey("n", modifierFlags: .command) |
| 17 | } |
| 18 | onboard(app) |
| 19 | |
| 20 | // The toolbar also opens both sheets. A center click on the inline control |
| 21 | // catches artwork intercepting clicks outside its visible frame. |
| 22 | let center = CGVector(dx: 0.5, dy: 0.5) |
| 23 | let energy = app.buttons["today.energy"] |
| 24 | XCTAssertTrue(energy.waitForExistence(timeout: 5)) |
| 25 | energy.coordinate(withNormalizedOffset: center).click() |
| 26 | let saveEnergy = app.buttons["Set today’s energy"] |
| 27 | XCTAssertTrue(saveEnergy.waitForExistence(timeout: 5)) |
| 28 | saveEnergy.click() |
| 29 | |
| 30 | let log = app.buttons["today.log"] |
| 31 | XCTAssertTrue(log.waitForExistence(timeout: 5)) |
| 32 | log.coordinate(withNormalizedOffset: center).click() |
| 33 | XCTAssertTrue(app.staticTexts["What did you do?"].waitForExistence(timeout: 5)) |
| 34 | press("Continue", in: app) |
| 35 | press("Skip tags", in: app) |
| 36 | let saveLog = app.buttons["saveMoment"] |
| 37 | XCTAssertTrue(saveLog.waitForExistence(timeout: 5)) |
| 38 | saveLog.click() |
| 39 | XCTAssertTrue(app.staticTexts["1 logged today"].waitForExistence(timeout: 5)) |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | func testOnboardLogAndRelaunch() throws { |
| 44 | let app = makeApp() |
| 45 | app.launch() |
| 46 | onboard(app) |
| 47 | capture("Today", app) |
| 48 | |
| 49 | press("Log a moment", in: app) |
| 50 | press("Continue", in: app) |
| 51 | press("Short-form video", in: app) |
| 52 | press("Continue", in: app) |
| 53 | XCTAssertTrue(app.staticTexts["How did it leave you?"].waitForExistence(timeout: 5)) |
| 54 | capture("Aftertaste dial", app) |
| 55 | press("saveMoment", in: app) |
| 56 | XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "1 logged today")).firstMatch.waitForExistence(timeout: 5)) |
| 57 | |
| 58 | app.terminate() |
| 59 | app.launch() |
| 60 | XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "1 logged today")).firstMatch.waitForExistence(timeout: 5)) |
| 61 | press("Insights", in: app) |
| 62 | XCTAssertTrue(app.staticTexts["Your first moment"].waitForExistence(timeout: 5)) |
| 63 | |
| 64 | press("Today", in: app) |
| 65 | press("Plan my day", in: app) |
| 66 | press("Complete Drink some water", in: app) |
| 67 | XCTAssertTrue(app.staticTexts["1 of 4 complete"].waitForExistence(timeout: 5)) |
| 68 | #if os(iOS) |
| 69 | if UIDevice.current.userInterfaceIdiom == .phone { |
| 70 | XCTAssertFalse(app.tabBars.firstMatch.isHittable) |
| 71 | let quickAdd = app.textFields["Quick add a task"] |
| 72 | reveal(quickAdd, in: app, down: true) |
| 73 | quickAdd.tap() |
| 74 | quickAdd.typeText("Read a few pages\n") |
| 75 | XCTAssertTrue(button("Complete Read a few pages", in: app).waitForExistence(timeout: 5)) |
| 76 | } |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | func testPersonalTodoShowsOnTodayWithoutChangingPlanProgress() { |
| 81 | let app = makeApp() |
| 82 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 83 | app.launch() |
| 84 | press("Plan my day", in: app) |
| 85 | press("personalTodos.add", in: app) |
| 86 | let title = app.textFields["personalTodos.title"] |
| 87 | XCTAssertTrue(title.waitForExistence(timeout: 5)) |
| 88 | activate(title) |
| 89 | title.typeText("Return the library book") |
| 90 | press("Due date", in: app) |
| 91 | #if os(iOS) |
| 92 | if app.keyboards.firstMatch.exists { app.swipeDown(velocity: .slow) } |
| 93 | #endif |
| 94 | capture("Personal to-do editor", app) |
| 95 | press("personalTodos.save", in: app) |
| 96 | let checkbox = button("Complete Return the library book", in: app) |
| 97 | XCTAssertTrue(checkbox.waitForExistence(timeout: 5)) |
| 98 | reveal(checkbox, in: app) |
| 99 | capture("Personal to-dos in Plan", app) |
| 100 | #if os(iOS) |
| 101 | if UIDevice.current.userInterfaceIdiom == .phone { goBack(in: app) } |
| 102 | #endif |
| 103 | goTo("Today", in: app) |
| 104 | XCTAssertTrue(checkbox.waitForExistence(timeout: 5)) |
| 105 | reveal(checkbox, in: app) |
| 106 | capture("Personal to-dos in Today", app) |
| 107 | activate(checkbox) |
| 108 | XCTAssertTrue(app.staticTexts["0 of 4 complete"].exists) |
| 109 | XCTAssertFalse(checkbox.exists) |
| 110 | } |
| 111 | |
| 112 | func testToolkitUnloadBreakDownAndOneThing() { |
| 113 | let app = makeApp() |
| 114 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 115 | app.launchEnvironment["GLIMMER_UNLOAD_TEXT"] = "Call the dentist|Buy cat food on Friday" |
| 116 | app.launch() |
| 117 | press("Plan my day", in: app) |
| 118 | |
| 119 | press("personalTodos.unload", in: app) |
| 120 | press("unload.sort", in: app) |
| 121 | XCTAssertTrue(app.buttons["unload.add"].waitForExistence(timeout: 10)) |
| 122 | capture("Unload review", app) |
| 123 | press("unload.add", in: app) |
| 124 | XCTAssertTrue(app.buttons["unload.sort"].waitForExistence(timeout: 5), "Unload clears for the next brain dump") |
| 125 | goBack(in: app) |
| 126 | let dentist = button("Complete Call the dentist", in: app) |
| 127 | XCTAssertTrue(dentist.waitForExistence(timeout: 5)) |
| 128 | XCTAssertTrue(button("Complete Buy cat food", in: app).exists) |
| 129 | |
| 130 | press("Toolkit for Call the dentist", in: app) |
| 131 | press("Break it down", in: app) |
| 132 | let save = app.buttons["breakItDown.save"] |
| 133 | if !save.waitForExistence(timeout: 10) { press("breakItDown.generate", in: app) } |
| 134 | XCTAssertTrue(save.waitForExistence(timeout: 10)) |
| 135 | XCTAssertTrue(app.staticTexts["From Glimmer’s offline guide"].exists) |
| 136 | capture("Break it down", app) |
| 137 | press("breakItDown.save", in: app) |
| 138 | XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "steps")).firstMatch.waitForExistence(timeout: 5)) |
| 139 | |
| 140 | press("Toolkit for Call the dentist", in: app) |
| 141 | press("One thing", in: app) |
| 142 | XCTAssertTrue(app.descendants(matching: .any)["oneThing.step"].waitForExistence(timeout: 5)) |
| 143 | capture("One thing", app) |
| 144 | for _ in 0..<12 where app.buttons["oneThing.done"].exists { |
| 145 | activate(app.buttons["oneThing.done"]) |
| 146 | pause(0.4) |
| 147 | } |
| 148 | XCTAssertTrue(app.staticTexts["That’s one thing finished. Rest, or pick the next."].waitForExistence(timeout: 5)) |
| 149 | XCTAssertTrue(app.buttons["oneThing.choice"].exists, "Offers what to do next") |
| 150 | capture("One thing finished", app) |
| 151 | press("Close", in: app) |
| 152 | XCTAssertFalse(button("Complete Call the dentist", in: app).waitForExistence(timeout: 2)) |
| 153 | } |
| 154 | |
| 155 | func testToolkitMessageAndDecisionTools() { |
| 156 | let app = makeApp() |
| 157 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 158 | app.launch() |
| 159 | #if os(iOS) |
| 160 | if UIDevice.current.userInterfaceIdiom == .phone { |
| 161 | press("Plan my day", in: app) |
| 162 | press("plan.toolkit", in: app) |
| 163 | } else { |
| 164 | goTo("Toolkit", in: app) |
| 165 | } |
| 166 | #else |
| 167 | goTo("Toolkit", in: app) |
| 168 | #endif |
| 169 | XCTAssertTrue(app.descendants(matching: .any)["toolkit.stepSize"].waitForExistence(timeout: 5)) |
| 170 | capture("Toolkit", app) |
| 171 | |
| 172 | press("toolkit.readTheRoom", in: app) |
| 173 | type("Per my last email, I still need the slides ASAP. Thanks.", into: app.textViews["room.text"], in: app) |
| 174 | press("room.read", in: app) |
| 175 | XCTAssertTrue(app.staticTexts["Urgent"].waitForExistence(timeout: 10)) |
| 176 | capture("Read the room", app) |
| 177 | goBack(in: app) |
| 178 | |
| 179 | press("toolkit.reword", in: app) |
| 180 | type("I just wanted to say I really think the draft is done. Sorry it took so long.", into: app.textViews["reword.text"], in: app) |
| 181 | press("reword.run", in: app) |
| 182 | XCTAssertTrue(app.descendants(matching: .any)["reword.result"].waitForExistence(timeout: 10)) |
| 183 | capture("Reword", app) |
| 184 | goBack(in: app) |
| 185 | |
| 186 | press("toolkit.weighIt", in: app) |
| 187 | type("Should I take the evening pottery class?", into: app.textViews["weigh.decision"], in: app) |
| 188 | press("weigh.run", in: app) |
| 189 | XCTAssertTrue(app.buttons["weigh.experiment"].waitForExistence(timeout: 10)) |
| 190 | capture("Weigh it", app) |
| 191 | press("weigh.experiment", in: app) |
| 192 | } |
| 193 | |
| 194 | private func type(_ text: String, into field: XCUIElement, in app: XCUIApplication) { |
| 195 | XCTAssertTrue(field.waitForExistence(timeout: 5), "Missing text field") |
| 196 | activate(field) |
| 197 | field.typeText(text) |
| 198 | #if os(iOS) |
| 199 | if app.keyboards.firstMatch.exists { app.swipeDown(velocity: .slow) } |
| 200 | #endif |
| 201 | } |
| 202 | |
| 203 | private func expandPractice(in app: XCUIApplication) { |
| 204 | if !app.buttons["coach.practice"].exists { press("More ways to practice", in: app) } |
| 205 | } |
| 206 | |
| 207 | func testMomentDisclosureAndCoinReward() { |
| 208 | let app = makeApp() |
| 209 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 210 | app.launchEnvironment["GLIMMER_FLOW"] = "log" |
| 211 | app.launch() |
| 212 | let people = app.buttons["People"].firstMatch |
| 213 | XCTAssertTrue(people.waitForExistence(timeout: 8)) |
| 214 | activate(people) |
| 215 | let option = app.buttons["📞 Called a friend"].firstMatch |
| 216 | XCTAssertTrue(option.waitForExistence(timeout: 5)) |
| 217 | activate(people) |
| 218 | XCTAssertTrue(option.waitForNonExistence(timeout: 5)) |
| 219 | press("Continue", in: app) |
| 220 | press("Skip tags", in: app) |
| 221 | press("saveMoment", in: app) |
| 222 | let earned = app.descendants(matching: .any).matching(NSPredicate(format: |
| 223 | "identifier == %@ AND label == %@", "earnedCoins", "10 coins earned")).firstMatch |
| 224 | XCTAssertTrue(earned.waitForExistence(timeout: 5)) |
| 225 | XCTAssertTrue(earned.waitForNonExistence(timeout: 5)) |
| 226 | } |
| 227 | |
| 228 | func testHabitStoneAndMoodSky() { |
| 229 | let app = makeApp() |
| 230 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 231 | app.launchEnvironment["GLIMMER_SCREEN"] = "Habits" |
| 232 | app.launch() |
| 233 | |
| 234 | let sky = app.descendants(matching: .any).matching(identifier: "habits.mood").firstMatch |
| 235 | XCTAssertTrue(sky.waitForExistence(timeout: 8)) |
| 236 | reveal(sky, in: app) |
| 237 | XCTAssertEqual(sky.value as? String, "Not set") |
| 238 | // The sun's last stop sits at the right end of its path. |
| 239 | let brightest = sky.coordinate(withNormalizedOffset: CGVector(dx: 0.87, dy: 0.3)) |
| 240 | #if os(macOS) |
| 241 | brightest.click() |
| 242 | #else |
| 243 | brightest.tap() |
| 244 | #endif |
| 245 | XCTAssertTrue(sky.waitForValue("Great")) |
| 246 | capture("Mood sky", app) |
| 247 | press("Clear today’s mood", in: app) |
| 248 | XCTAssertTrue(sky.waitForValue("Not set")) |
| 249 | |
| 250 | let stone = app.descendants(matching: .any).matching(identifier: "habit.h1").firstMatch |
| 251 | XCTAssertTrue(stone.waitForExistence(timeout: 5)) |
| 252 | reveal(stone, in: app) |
| 253 | XCTAssertEqual(stone.value as? String, "Not done today, 0 of the last 7 days") |
| 254 | activate(stone) |
| 255 | let earned = app.descendants(matching: .any).matching(NSPredicate(format: |
| 256 | "identifier == %@ AND label == %@", "earnedCoins", "5 coins earned")).firstMatch |
| 257 | XCTAssertTrue(earned.waitForExistence(timeout: 5), "Checking off a habit plays the coin celebration") |
| 258 | XCTAssertEqual(stone.value as? String, "Done today, 1 of the last 7 days") |
| 259 | capture("Habit stones", app) |
| 260 | XCTAssertTrue(earned.waitForNonExistence(timeout: 5)) |
| 261 | activate(stone) |
| 262 | XCTAssertTrue(stone.waitForValue("Not done today, 0 of the last 7 days")) |
| 263 | } |
| 264 | |
| 265 | func testCoachChatRecommendationsAndFollowUp() { |
| 266 | let app = makeApp() |
| 267 | app.launchEnvironment["GLIMMER_SCREEN"] = "Coach" |
| 268 | app.launchEnvironment["GLIMMER_TEST_COACH_GUIDE"] = "1" |
| 269 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 270 | app.launch() |
| 271 | XCTAssertTrue(app.staticTexts["What’s on your mind?"].waitForExistence(timeout: 8)) |
| 272 | capture("Coach welcome", app) |
| 273 | |
| 274 | press("Help me choose one small practice", in: app) |
| 275 | let save = app.buttons["Add to today’s plan"].firstMatch |
| 276 | reveal(save, in: app, down: true) |
| 277 | // Let the inline card finish scrolling into place before sending the pointer. |
| 278 | pause(0.45) |
| 279 | activate(save) |
| 280 | XCTAssertTrue(app.staticTexts["Saved to today’s plan"].firstMatch.waitForExistence(timeout: 8)) |
| 281 | capture("Coach inline practice saved", app) |
| 282 | |
| 283 | let composer = app.descendants(matching: .any)["coach.question"].firstMatch |
| 284 | XCTAssertTrue(composer.waitForExistence(timeout: 8)) |
| 285 | activate(composer) |
| 286 | composer.typeText("What should I read today?") |
| 287 | // The composer rides up with the keyboard; let it settle so the send tap lands on the button. |
| 288 | pause(0.8) |
| 289 | press("coach.send", in: app) |
| 290 | if app.staticTexts["What should I read today?"].firstMatch.waitForExistence(timeout: 3) == false { |
| 291 | pause(0.8) |
| 292 | press("coach.send", in: app) |
| 293 | } |
| 294 | let reading = app.buttons["Read lesson"].firstMatch |
| 295 | reveal(reading, in: app, down: true) |
| 296 | capture("Coach lesson follow-up", app) |
| 297 | activate(reading) |
| 298 | goBack(in: app) |
| 299 | press("New chat", in: app) |
| 300 | XCTAssertTrue(app.staticTexts["What’s on your mind?"].exists) |
| 301 | } |
| 302 | |
| 303 | func testLifeCoachingPracticeAndWeeklyComparison() throws { |
| 304 | let app = makeApp() |
| 305 | app.launch() |
| 306 | XCTAssertTrue(app.staticTexts["A quiet place to get unstuck"].waitForExistence(timeout: 8)) |
| 307 | capture("Life coach onboarding", app) |
| 308 | onboard(app) |
| 309 | goTo("Coach", in: app) |
| 310 | press("coach.library", in: app) |
| 311 | expandPractice(in: app) |
| 312 | press("coach.practice", in: app) |
| 313 | capture("Work and learning exercises", app) |
| 314 | let exercise = "See if your manager teaches you" |
| 315 | press(exercise, in: app) |
| 316 | XCTAssertFalse(button(exercise, in: app).isEnabled) |
| 317 | goBack(in: app) |
| 318 | XCTAssertTrue(app.staticTexts[exercise].waitForExistence(timeout: 6)) |
| 319 | press("Close library", in: app) |
| 320 | goTo("Weekly", in: app) |
| 321 | press("weekly.screenTime", in: app) |
| 322 | XCTAssertTrue(app.staticTexts["Find your weekly total"].waitForExistence(timeout: 6)) |
| 323 | capture("Weekly Screen Time comparison", app) |
| 324 | goTo("Coach", in: app) |
| 325 | press("coach.library", in: app) |
| 326 | expandPractice(in: app) |
| 327 | XCTAssertTrue(app.staticTexts["Daily Glimmer"].waitForExistence(timeout: 6)) |
| 328 | capture("Daily Glimmer practice", app) |
| 329 | press("coach.author", in: app) |
| 330 | XCTAssertTrue(app.staticTexts["Brad Dunlap, author and life coach"].waitForExistence(timeout: 6)) |
| 331 | capture("About this guidance", app) |
| 332 | } |
| 333 | |
| 334 | func testSpiritualLifeCoachReflection() throws { |
| 335 | let app = makeApp() |
| 336 | app.launch() |
| 337 | XCTAssertTrue(app.staticTexts["A quiet place to get unstuck"].waitForExistence(timeout: 8)) |
| 338 | capture("01 Welcome", app) |
| 339 | onboard(app) |
| 340 | let reflection = app.staticTexts["A moment to reflect"] |
| 341 | reveal(reflection, in: app, down: true) |
| 342 | capture("02 Reflection on Today", app) |
| 343 | goTo("Coach", in: app) |
| 344 | press("coach.library", in: app) |
| 345 | reveal(app.staticTexts["Today’s reflection"], in: app, down: false) |
| 346 | capture("03 Coach reflection", app) |
| 347 | press("coach.reflections", in: app) |
| 348 | let confidence = app.buttons.matching(NSPredicate(format: "identifier == %@", "practice.practice-one-small-skill")).firstMatch |
| 349 | reveal(confidence, in: app, down: true) |
| 350 | capture("04 Confidence practice", app) |
| 351 | activate(confidence) |
| 352 | XCTAssertFalse(confidence.isEnabled) |
| 353 | goBack(in: app) |
| 354 | expandPractice(in: app) |
| 355 | press("coach.community", in: app) |
| 356 | let offer = app.buttons["practice.offer-school-hour"].firstMatch |
| 357 | reveal(offer, in: app, down: false) |
| 358 | capture("05 Offer time to a school", app) |
| 359 | goBack(in: app) |
| 360 | let signal = app.buttons["coach.signal"] |
| 361 | reveal(signal, in: app, down: false) |
| 362 | activate(signal) |
| 363 | let save = app.buttons["coach.save.try-an-80-20-day"] |
| 364 | XCTAssertTrue(save.waitForExistence(timeout: 5)) |
| 365 | capture("06 The 80-20 practice", app) |
| 366 | activate(save) |
| 367 | XCTAssertFalse(save.isEnabled) |
| 368 | } |
| 369 | |
| 370 | func testOnboardingBackKeepsChoices() { |
| 371 | let app = makeApp() |
| 372 | app.launch() |
| 373 | press("onboardingContinue", in: app) |
| 374 | let labels = ["Spend less time on feeds I regret", "Rebuild my attention span", "Read & learn with more focus"] |
| 375 | for label in labels { press(label, in: app) } |
| 376 | for label in labels { XCTAssertTrue(button(label, in: app).isSelected) } |
| 377 | pause(1) |
| 378 | capture("Several goals selected", app) |
| 379 | press("onboardingContinue", in: app) |
| 380 | XCTAssertTrue(app.staticTexts["What tends to pull you off track?"].waitForExistence(timeout: 5)) |
| 381 | press("onboardingBack", in: app) |
| 382 | press(labels[1], in: app) |
| 383 | XCTAssertFalse(button(labels[1], in: app).isSelected) |
| 384 | press("onboardingBack", in: app) |
| 385 | press("onboardingContinue", in: app) |
| 386 | app.terminate() |
| 387 | app.launch() |
| 388 | XCTAssertTrue(button(labels[0], in: app).waitForExistence(timeout: 8)) |
| 389 | XCTAssertTrue(button(labels[0], in: app).isSelected) |
| 390 | XCTAssertFalse(button(labels[1], in: app).isSelected) |
| 391 | XCTAssertTrue(button(labels[2], in: app).isSelected) |
| 392 | press(labels[0], in: app) |
| 393 | press(labels[2], in: app) |
| 394 | XCTAssertFalse(button("onboardingContinue", in: app).isEnabled) |
| 395 | } |
| 396 | |
| 397 | func testCompleteOnboardingAndMainRoutes() throws { |
| 398 | let app = makeApp() |
| 399 | app.launch() |
| 400 | press("Continue", in: app) |
| 401 | XCTAssertFalse(button("onboardingContinue", in: app).isEnabled) |
| 402 | press("onboardingBack", in: app) |
| 403 | onboard(app, captureSetup: true) |
| 404 | |
| 405 | for title in ["Today", "Insights", "Weekly", "Coach", "Plan", "Habits", "Challenges", "Lessons", "Cleaning", "Settings"] { |
| 406 | app.terminate() |
| 407 | app.launchEnvironment["GLIMMER_SCREEN"] = title |
| 408 | app.launch() |
| 409 | XCTAssertFalse(app.staticTexts["A quiet place to get unstuck"].exists) |
| 410 | pause(0.8) |
| 411 | capture("Route " + title, app) |
| 412 | } |
| 413 | for title in ["Privacy & backups", "Ratings & support"] { |
| 414 | reveal(app.staticTexts[title].firstMatch, in: app, down: true) |
| 415 | capture("Settings " + title, app) |
| 416 | } |
| 417 | |
| 418 | for flow in ["energy", "log"] { |
| 419 | app.terminate() |
| 420 | app.launchEnvironment["GLIMMER_SCREEN"] = "Today" |
| 421 | app.launchEnvironment["GLIMMER_FLOW"] = flow |
| 422 | app.launch() |
| 423 | pause(0.8) |
| 424 | capture("Journal " + flow, app) |
| 425 | } |
| 426 | goThroughLog(in: app) |
| 427 | capture("Journal returning Today", app) |
| 428 | } |
| 429 | |
| 430 | private func goThroughLog(in app: XCUIApplication) { |
| 431 | press("Continue", in: app) |
| 432 | press("Short-form video", in: app) |
| 433 | press("Continue", in: app) |
| 434 | capture("Journal aftertaste", app) |
| 435 | press("saveMoment", in: app) |
| 436 | XCTAssertTrue(app.staticTexts.containing(NSPredicate(format: "label CONTAINS %@", "1 logged today")).firstMatch.waitForExistence(timeout: 6)) |
| 437 | } |
| 438 | |
| 439 | func testSavedPracticeAndReadyExperimentReview() throws { |
| 440 | guard let id = ProcessInfo.processInfo.environment["GLIMMER_STAGED_JOURNAL"], UUID(uuidString: id) != nil else { |
| 441 | throw XCTSkip("This review uses an isolated example journal with seven experiment check-ins.") |
| 442 | } |
| 443 | let app = makeApp() |
| 444 | app.launchEnvironment["GLIMMER_TEST_JOURNAL"] = id |
| 445 | app.launchEnvironment["GLIMMER_SCREEN"] = "Coach" |
| 446 | app.launch() |
| 447 | press("coach.library", in: app) |
| 448 | press("Start the review", in: app) |
| 449 | XCTAssertTrue(button("Keep it", in: app).waitForExistence(timeout: 6)) |
| 450 | capture("Experiment review", app) |
| 451 | app.terminate() |
| 452 | app.launchEnvironment["GLIMMER_SCREEN"] = "Plan" |
| 453 | app.launch() |
| 454 | let row = app.buttons.matching(NSPredicate(format: "label CONTAINS %@ AND NOT label BEGINSWITH %@ AND NOT label BEGINSWITH %@", "One small skill", "Uncheck", "Complete")).firstMatch |
| 455 | reveal(row, in: app, down: true) |
| 456 | activate(row) |
| 457 | XCTAssertTrue(app.staticTexts["Edit task"].waitForExistence(timeout: 5)) |
| 458 | capture("Existing task editor", app) |
| 459 | } |
| 460 | |
| 461 | func testWeeklyComparisonAndGuidanceSources() { |
| 462 | let app = makeApp() |
| 463 | app.launchEnvironment["GLIMMER_TEST_START_PLAN"] = "1" |
| 464 | app.launch() |
| 465 | XCTAssertTrue(app.buttons["Log a moment"].waitForExistence(timeout: 8)) |
| 466 | let quick = app.buttons["Quick actions"].firstMatch |
| 467 | if quick.isHittable { |
| 468 | activate(quick) |
| 469 | capture("Quick actions", app) |
| 470 | } |
| 471 | app.terminate() |
| 472 | app.launchEnvironment["GLIMMER_SCREEN"] = "Weekly" |
| 473 | app.launch() |
| 474 | press("weekly.screenTime", in: app) |
| 475 | XCTAssertTrue(app.staticTexts["Find your weekly total"].waitForExistence(timeout: 5)) |
| 476 | capture("Weekly Screen Time comparison", app) |
| 477 | app.terminate() |
| 478 | app.launchEnvironment["GLIMMER_SCREEN"] = "Coach" |
| 479 | app.launch() |
| 480 | press("coach.library", in: app) |
| 481 | let disclosure = app.buttons["coach.author"].firstMatch |
| 482 | reveal(disclosure, in: app, down: true) |
| 483 | pause(0.4) |
| 484 | activate(disclosure) |
| 485 | let credit = app.staticTexts["Brad Dunlap, author and life coach"].firstMatch |
| 486 | reveal(credit, in: app, down: true) |
| 487 | XCTAssertTrue(credit.waitForExistence(timeout: 5)) |
| 488 | capture("About this guidance", app) |
| 489 | } |
| 490 | |
| 491 | /// Ratings & support offers only free actions: rate, free support, share, feedback and more apps. |
| 492 | func testSupportRowsAreFree() throws { |
| 493 | let app = makeApp() |
| 494 | app.launch() |
| 495 | onboard(app) |
| 496 | press("Settings", in: app) |
| 497 | for row in ["reviewGlimmer", "glimmerSupportTickets"] { |
| 498 | XCTAssertTrue(button(row, in: app).waitForExistence(timeout: 8), row) |
| 499 | } |
| 500 | XCTAssertFalse(app.buttons["glimmerTipJar"].exists) |
| 501 | #if os(macOS) |
| 502 | press("glimmerSupportCard", in: app) |
| 503 | for action in ["feedback", "share", "support", "apps"] { |
| 504 | XCTAssertTrue(button("support." + action, in: app).waitForExistence(timeout: 8), action) |
| 505 | } |
| 506 | XCTAssertFalse(app.buttons["support.tip"].exists) |
| 507 | capture("Support card", app) |
| 508 | #else |
| 509 | reveal(app.buttons["glimmerSupportTickets"], in: app) |
| 510 | pause(0.6) |
| 511 | capture("Ratings and support", app) |
| 512 | #endif |
| 513 | } |
| 514 | |
| 515 | private func makeApp() -> XCUIApplication { |
| 516 | let app = XCUIApplication() |
| 517 | app.launchEnvironment["GLIMMER_TEST_JOURNAL"] = UUID().uuidString |
| 518 | if let appearance = ProcessInfo.processInfo.environment["GLIMMER_APPEARANCE"] { |
| 519 | app.launchEnvironment["GLIMMER_APPEARANCE"] = appearance |
| 520 | } |
| 521 | return app |
| 522 | } |
| 523 | |
| 524 | func testReviewScreens() throws { |
| 525 | let app = makeApp() |
| 526 | app.launch() |
| 527 | onboard(app, captureSetup: true) |
| 528 | capture("01 Today", app) |
| 529 | press("How’s your energy?", in: app) |
| 530 | capture("02 Energy check-in", app) |
| 531 | app.terminate() |
| 532 | app.launch() |
| 533 | press("Log a moment", in: app) |
| 534 | capture("03 Choose input", app) |
| 535 | press("Continue", in: app) |
| 536 | capture("04 Describe input", app) |
| 537 | press("Short-form video", in: app) |
| 538 | press("Continue", in: app) |
| 539 | capture("05 Aftertaste dial", app) |
| 540 | press("saveMoment", in: app) |
| 541 | for title in ["Insights", "Weekly", "Coach"] { |
| 542 | press(title, in: app) |
| 543 | capture("06 \(title)", app) |
| 544 | } |
| 545 | app.terminate() |
| 546 | app.launch() |
| 547 | press("Plan my day", in: app) |
| 548 | capture("07 Plan", app) |
| 549 | press("New scheduled task", in: app) |
| 550 | capture("08 Task editor", app) |
| 551 | app.terminate() |
| 552 | app.launch() |
| 553 | press("Plan my day", in: app) |
| 554 | press("Browse the task library", in: app) |
| 555 | capture("09 Task library", app) |
| 556 | for title in ["Habits", "Challenges", "Cleaning & maintenance", "Settings"] { |
| 557 | app.terminate() |
| 558 | app.launch() |
| 559 | press(title, in: app) |
| 560 | capture("10 \(title)", app) |
| 561 | } |
| 562 | reveal(app.buttons["glimmerSupportTickets"], in: app) |
| 563 | capture("11 Ratings and support", app) |
| 564 | } |
| 565 | |
| 566 | func testDesignReviewDeepScreens() throws { |
| 567 | let app = makeApp() |
| 568 | app.launch() |
| 569 | onboard(app) |
| 570 | |
| 571 | press("Lessons", in: app) |
| 572 | capture("20 Lessons", app) |
| 573 | press("Read lesson", in: app) |
| 574 | capture("21 Lesson reader", app) |
| 575 | press("Next page", in: app) |
| 576 | press("Next page", in: app) |
| 577 | capture("22 Lesson reflection", app) |
| 578 | press("💬 A reply that changes my mood", in: app) |
| 579 | press("Next page", in: app) |
| 580 | press("Next page", in: app) |
| 581 | press("Next page", in: app) |
| 582 | capture("23 Lesson takeaway", app) |
| 583 | press("Complete lesson", in: app) |
| 584 | |
| 585 | relaunch(app) |
| 586 | press("Challenges", in: app) |
| 587 | capture("30 Challenges", app) |
| 588 | press("The One-Item Landing Pad", in: app) |
| 589 | capture("31 Challenge intro", app) |
| 590 | press("Get started", in: app) |
| 591 | capture("32 Challenge lesson", app) |
| 592 | press("Continue", in: app) |
| 593 | press("Continue", in: app) |
| 594 | capture("33 Challenge choice", app) |
| 595 | press("Keys or wallet", in: app) |
| 596 | press("Continue", in: app) |
| 597 | #if !os(macOS) |
| 598 | app.swipeUp() // Bring the timer above the pinned action bar before tapping it. |
| 599 | #endif |
| 600 | press("Start 3-minute timer", in: app) |
| 601 | capture("34 Challenge timer", app) |
| 602 | press("I’m done", in: app) |
| 603 | press("Lighter", in: app) |
| 604 | capture("35 Challenge complete", app) |
| 605 | |
| 606 | relaunch(app) |
| 607 | press("Habits", in: app) |
| 608 | capture("40 Habits today", app) |
| 609 | press("Month", in: app) |
| 610 | capture("41 Habits month", app) |
| 611 | |
| 612 | relaunch(app) |
| 613 | press("Cleaning & maintenance", in: app) |
| 614 | capture("42 Cleaning", app) |
| 615 | press("Daily reset", in: app) |
| 616 | capture("43 Cleaning list", app) |
| 617 | |
| 618 | relaunch(app) |
| 619 | press("Coach", in: app) |
| 620 | press("coach.library", in: app) |
| 621 | press("Design it together", in: app) |
| 622 | capture("44 Coach experiments", app) |
| 623 | |
| 624 | relaunch(app) |
| 625 | press("Plan my day", in: app) |
| 626 | press("New scheduled task", in: app) |
| 627 | let repeatSwitch = app.switches["Repeat"].firstMatch |
| 628 | if repeatSwitch.waitForExistence(timeout: 5) { |
| 629 | #if os(macOS) |
| 630 | repeatSwitch.click() |
| 631 | #else |
| 632 | repeatSwitch.switches.firstMatch.exists ? repeatSwitch.switches.firstMatch.tap() : repeatSwitch.tap() |
| 633 | #endif |
| 634 | } |
| 635 | capture("50 Task editor repeating", app) |
| 636 | |
| 637 | relaunch(app) |
| 638 | press("Plan my day", in: app) |
| 639 | press("Plan my day with suggestions", in: app) |
| 640 | capture("51 Suggestions", app) |
| 641 | |
| 642 | relaunch(app) |
| 643 | press("Plan my day", in: app) |
| 644 | press("Browse the task library", in: app) |
| 645 | press("Easy wins & momentum", in: app) |
| 646 | capture("52 Library category", app) |
| 647 | |
| 648 | relaunch(app) |
| 649 | press("Settings", in: app) |
| 650 | capture("60 Settings", app) |
| 651 | press("reviewGlimmer", in: app) |
| 652 | capture("61 Settings support", app) |
| 653 | } |
| 654 | |
| 655 | /// A paced tour of the logging flow for screen recordings. It taps and drags like a person would. |
| 656 | func testRecordedTour() throws { |
| 657 | let app = makeApp() |
| 658 | app.launch() |
| 659 | XCTAssertTrue(app.staticTexts["A quiet place to get unstuck"].waitForExistence(timeout: 8)) |
| 660 | pause(1.5) |
| 661 | // The name field sits below the fold on iPhone; scroll it clear of the action bar first. |
| 662 | let name = app.textFields.firstMatch |
| 663 | for _ in 0..<3 where name.frame.maxY > app.buttons["onboardingContinue"].frame.minY { app.swipeUp() } |
| 664 | type("Alex", into: name, in: app) |
| 665 | pause(1) |
| 666 | onboard(app) |
| 667 | pause(1.5) |
| 668 | |
| 669 | press("Log a moment", in: app) |
| 670 | pause(1.2) |
| 671 | press("Apps & sites", in: app) |
| 672 | pause(1.5) |
| 673 | press("Add Claude to favorites", in: app) |
| 674 | pause(1) |
| 675 | let search = app.textFields["Search or add an app or site"] |
| 676 | XCTAssertTrue(search.waitForExistence(timeout: 5)) |
| 677 | search.tap() |
| 678 | search.typeText("gem") |
| 679 | pause(1.5) |
| 680 | press("Gemini", in: app) |
| 681 | pause(1.2) |
| 682 | press("Activities", in: app) |
| 683 | pause(1.5) |
| 684 | press("🧘 Meditated", in: app) |
| 685 | pause(1.2) |
| 686 | press("Apps & sites", in: app) |
| 687 | pause(1.5) |
| 688 | press("Claude", in: app) |
| 689 | pause(1.2) |
| 690 | press("Continue", in: app) |
| 691 | pause(1) |
| 692 | press("Coding help", in: app) |
| 693 | pause(0.8) |
| 694 | press("Continue", in: app) |
| 695 | pause(1.2) |
| 696 | turnDial("Aftertaste", in: app) |
| 697 | press("More", in: app) |
| 698 | pause(1) |
| 699 | press("saveMoment", in: app) |
| 700 | pause(2.5) |
| 701 | |
| 702 | press("Check in", in: app) |
| 703 | pause(1.2) |
| 704 | turnDial("Energy", in: app) |
| 705 | press("Set today’s energy", in: app) |
| 706 | pause(2.5) |
| 707 | |
| 708 | press("Plan my day", in: app) |
| 709 | pause(1) |
| 710 | let quickAdd = app.textFields["Quick add a task"] |
| 711 | XCTAssertTrue(quickAdd.waitForExistence(timeout: 5)) |
| 712 | quickAdd.tap() |
| 713 | quickAdd.typeText("Call the dentist\n") |
| 714 | pause(2.5) |
| 715 | } |
| 716 | |
| 717 | /// Run with two isolated review journals installed in the app container. |
| 718 | func testRecordedScreenTour() throws { |
| 719 | let environment = ProcessInfo.processInfo.environment |
| 720 | guard let tour = environment["GLIMMER_TOUR_JOURNAL"], |
| 721 | let empty = environment["GLIMMER_TOUR_EMPTY_JOURNAL"], |
| 722 | UUID(uuidString: tour) != nil, UUID(uuidString: empty) != nil, tour != empty else { |
| 723 | throw XCTSkip("Install the onboarding and empty review journal fixtures to record this tour.") |
| 724 | } |
| 725 | #if os(iOS) |
| 726 | XCUIDevice.shared.orientation = .portrait |
| 727 | #endif |
| 728 | let app = makeApp() |
| 729 | #if os(macOS) |
| 730 | app.launchArguments += ["-ApplePersistenceIgnoreState", "YES"] |
| 731 | #endif |
| 732 | app.launchEnvironment["GLIMMER_TEST_JOURNAL"] = tour |
| 733 | app.launch() |
| 734 | onboard(app, paced: true) |
| 735 | holdScreen("Today") |
| 736 | recordCheckIns(in: app) |
| 737 | recordReflection(in: app) |
| 738 | recordPlan(in: app) |
| 739 | recordWellness(in: app) |
| 740 | recordLessons(in: app) |
| 741 | recordSettings(in: app) |
| 742 | |
| 743 | app.terminate() |
| 744 | app.launchEnvironment["GLIMMER_TEST_JOURNAL"] = empty |
| 745 | app.launch() |
| 746 | XCTAssertTrue(app.buttons["Log a moment"].waitForExistence(timeout: 8)) |
| 747 | holdScreen("Empty Today") |
| 748 | goTo("Insights", in: app) |
| 749 | XCTAssertTrue(app.staticTexts["What stayed with you today?"].waitForExistence(timeout: 5)) |
| 750 | holdScreen("Empty Insights") |
| 751 | goTo("Coach", in: app) |
| 752 | holdScreen("Empty Coach", for: 2.5) |
| 753 | } |
| 754 | |
| 755 | /// Isolate the long app list when recording the picker on a smaller sheet. |
| 756 | func testRecordedAppSources() throws { |
| 757 | guard let journal = ProcessInfo.processInfo.environment["GLIMMER_TOUR_JOURNAL"], |
| 758 | UUID(uuidString: journal) != nil else { |
| 759 | throw XCTSkip("Install the review journal fixture to record the app picker.") |
| 760 | } |
| 761 | let app = makeApp() |
| 762 | app.launchEnvironment["GLIMMER_TEST_JOURNAL"] = journal |
| 763 | app.launchEnvironment["GLIMMER_FLOW"] = "log" |
| 764 | app.launch() |
| 765 | press("Apps & sites", in: app) |
| 766 | showAllAppSources(in: app) |
| 767 | } |
| 768 | |
| 769 | private func recordCheckIns(in app: XCUIApplication) { |
| 770 | press("Log a moment", in: app) |
| 771 | holdScreen("Log source, collapsed") |
| 772 | press("Apps & sites", in: app) |
| 773 | holdScreen("Apps and sites, Favorites and Recent") |
| 774 | showAllAppSources(in: app) |
| 775 | let search = app.textFields["Search or add an app or site"] |
| 776 | // The field is above the All section on compact displays. |
| 777 | reveal(search, in: app, down: false) |
| 778 | activate(search) |
| 779 | search.typeText("gem") |
| 780 | holdScreen("App search") |
| 781 | press("Gemini", in: app) |
| 782 | press("Activities", in: app) |
| 783 | holdScreen("Activities") |
| 784 | press("🧘 Meditated", in: app) |
| 785 | press("People", in: app) |
| 786 | holdScreen("People") |
| 787 | press("📞 Called a friend", in: app) |
| 788 | press("Apps & sites", in: app) |
| 789 | press("Claude", in: app) |
| 790 | press("Continue", in: app) |
| 791 | holdScreen("Log tags") |
| 792 | press("Coding help", in: app) |
| 793 | press("Continue", in: app) |
| 794 | holdScreen("Aftertaste") |
| 795 | turnDial("Aftertaste", in: app) |
| 796 | // The iPad's form sheet can place these controls under the pinned Save bar. |
| 797 | scrollTour(in: app, nearEdge: true) |
| 798 | for decision in ["Less", "Same", "More"] { |
| 799 | press(decision, in: app) |
| 800 | holdScreen(decision, for: 0.7) |
| 801 | } |
| 802 | press("saveMoment", in: app) |
| 803 | holdScreen("Log saved with coins", for: 2.8) |
| 804 | |
| 805 | press("How’s your energy?", in: app) |
| 806 | holdScreen("Energy check-in") |
| 807 | turnDial("Energy", in: app) |
| 808 | press("Set today’s energy", in: app) |
| 809 | holdScreen("Energy saved", for: 2.6) |
| 810 | } |
| 811 | |
| 812 | private func showAllAppSources(in app: XCUIApplication) { |
| 813 | scrollTour(in: app, nearEdge: true) |
| 814 | reveal(app.staticTexts["All"].firstMatch, in: app) |
| 815 | holdScreen("All apps and sites", for: 2.2) |
| 816 | } |
| 817 | |
| 818 | private func recordReflection(in app: XCUIApplication) { |
| 819 | goTo("Insights", in: app) |
| 820 | holdScreen("Insights") |
| 821 | scrollTour(in: app) |
| 822 | holdScreen("Insight charts") |
| 823 | scrollTour(in: app) |
| 824 | holdScreen("Platform aftertaste and logs") |
| 825 | goTo("Weekly", in: app) |
| 826 | holdScreen("Weekly") |
| 827 | scrollTour(in: app) |
| 828 | holdScreen("Weekly patterns and experiments") |
| 829 | goTo("Coach", in: app) |
| 830 | holdScreen("Coach") |
| 831 | press("Start the review", in: app) |
| 832 | holdScreen("Experiment review") |
| 833 | scrollTour(in: app) |
| 834 | holdScreen("Experiment outcomes") |
| 835 | press("Keep it", in: app) |
| 836 | holdScreen("Experiment reviewed", for: 2.8) |
| 837 | press("Design it together", in: app) |
| 838 | scrollTour(in: app) |
| 839 | holdScreen("Coach suggestions") |
| 840 | goTo("Today", in: app) |
| 841 | } |
| 842 | |
| 843 | private func recordPlan(in app: XCUIApplication) { |
| 844 | press("Plan my day", in: app) |
| 845 | holdScreen("Plan") |
| 846 | press("New scheduled task", in: app) |
| 847 | scrollTour(in: app) |
| 848 | let repeatSwitch = app.switches["Repeat"].firstMatch |
| 849 | reveal(repeatSwitch, in: app) |
| 850 | let nestedSwitch = repeatSwitch.switches.firstMatch |
| 851 | let control = nestedSwitch.exists ? nestedSwitch : repeatSwitch |
| 852 | activate(control) |
| 853 | XCTAssertFalse(app.buttons["Daily"].exists) |
| 854 | holdScreen("One-off task editor") |
| 855 | activate(control) |
| 856 | scrollTour(in: app) |
| 857 | press("Weekly", in: app) |
| 858 | scrollTour(in: app) |
| 859 | holdScreen("Repeating task editor") |
| 860 | press("Cancel", in: app) |
| 861 | press("Plan my day with suggestions", in: app) |
| 862 | holdScreen("Plan suggestions") |
| 863 | goBack(in: app) |
| 864 | press("Browse the task library", in: app) |
| 865 | holdScreen("Task library") |
| 866 | press("Easy wins & momentum", in: app) |
| 867 | holdScreen("Task library category") |
| 868 | goBack(in: app) |
| 869 | goBack(in: app) |
| 870 | leaveTodayDetail(in: app) |
| 871 | } |
| 872 | |
| 873 | private func recordWellness(in app: XCUIApplication) { |
| 874 | goTo("Habits", in: app) |
| 875 | holdScreen("Habits Today") |
| 876 | press("Month", in: app) |
| 877 | holdScreen("Habits Month") |
| 878 | leaveTodayDetail(in: app) |
| 879 | |
| 880 | goTo("Challenges", in: app) |
| 881 | holdScreen("Challenges") |
| 882 | press("The One-Item Landing Pad", in: app) |
| 883 | holdScreen("Challenge introduction") |
| 884 | press("Get started", in: app) |
| 885 | for page in ["Challenge lesson one", "Challenge lesson two"] { |
| 886 | holdScreen(page) |
| 887 | press("Continue", in: app) |
| 888 | } |
| 889 | holdScreen("Challenge choice") |
| 890 | press("Keys or wallet", in: app) |
| 891 | press("Continue", in: app) |
| 892 | holdScreen("Challenge action") |
| 893 | scrollTour(in: app) |
| 894 | press("Start 3-minute timer", in: app) |
| 895 | holdScreen("Challenge timer") |
| 896 | press("I’m done", in: app) |
| 897 | holdScreen("Challenge completion") |
| 898 | press("Lighter", in: app) |
| 899 | holdScreen("Challenge feedback") |
| 900 | press("Back to tiny wins", in: app) |
| 901 | leaveTodayDetail(in: app) |
| 902 | |
| 903 | goTo("Cleaning & maintenance", in: app) |
| 904 | holdScreen("Cleaning") |
| 905 | press("Daily reset", in: app) |
| 906 | holdScreen("Cleaning list") |
| 907 | goBack(in: app) |
| 908 | leaveTodayDetail(in: app) |
| 909 | } |
| 910 | |
| 911 | private func recordLessons(in app: XCUIApplication) { |
| 912 | goTo("Lessons", in: app) |
| 913 | holdScreen("Lessons") |
| 914 | press("Read lesson", in: app) |
| 915 | holdScreen("Lesson opening") |
| 916 | press("Next page", in: app) |
| 917 | holdScreen("Lesson reading") |
| 918 | press("Next page", in: app) |
| 919 | holdScreen("Lesson reflection") |
| 920 | press("💬 A reply that changes my mood", in: app) |
| 921 | for page in ["Lesson reading, continued", "Lesson practice", "Lesson takeaway"] { |
| 922 | press("Next page", in: app) |
| 923 | holdScreen(page) |
| 924 | } |
| 925 | press("Complete lesson", in: app) |
| 926 | holdScreen("Lesson complete") |
| 927 | leaveTodayDetail(in: app) |
| 928 | } |
| 929 | |
| 930 | private func recordSettings(in app: XCUIApplication) { |
| 931 | goTo("Settings", in: app) |
| 932 | holdScreen("Settings") |
| 933 | reveal(app.staticTexts.matching(NSPredicate(format: "label BEGINSWITH %@", "Version ")).firstMatch, in: app) |
| 934 | holdScreen("About Glimmer") |
| 935 | reveal(app.buttons["glimmerSupportTickets"], in: app) |
| 936 | holdScreen("Ratings and support", for: 3) |
| 937 | } |
| 938 | |
| 939 | private func holdScreen(_ title: String, for seconds: TimeInterval = 1.6) { |
| 940 | XCTContext.runActivity(named: "Recording: \(title)") { _ in pause(seconds) } |
| 941 | } |
| 942 | |
| 943 | private func scrollTour(in app: XCUIApplication, down: Bool = true, nearEdge: Bool = false) { |
| 944 | #if os(macOS) |
| 945 | app.scrollViews.allElementsBoundByIndex.last?.scroll(byDeltaX: 0, deltaY: down ? -370 : 370) |
| 946 | #else |
| 947 | let scroll = app.scrollViews.allElementsBoundByIndex.last(where: \.isHittable) ?? app |
| 948 | if nearEdge { |
| 949 | // Start outside the dial's drag gesture so the page scrolls. |
| 950 | let start = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.09, dy: 0.80)) |
| 951 | let end = scroll.coordinate(withNormalizedOffset: CGVector(dx: 0.09, dy: 0.30)) |
| 952 | start.press(forDuration: 0.05, thenDragTo: end, withVelocity: .default, thenHoldForDuration: 0) |
| 953 | return |
| 954 | } |
| 955 | if down { scroll.swipeUp(velocity: .slow) } else { scroll.swipeDown(velocity: .slow) } |
| 956 | #endif |
| 957 | } |
| 958 | |
| 959 | private func reveal(_ element: XCUIElement, in app: XCUIApplication, down: Bool = true, |
| 960 | file: StaticString = #filePath, line: UInt = #line) { |
| 961 | for _ in 0..<4 where !element.isHittable { scrollTour(in: app, down: down) } |
| 962 | XCTAssertTrue(element.isHittable, "Could not bring the requested control into view", file: file, line: line) |
| 963 | } |
| 964 | |
| 965 | private func activate(_ element: XCUIElement) { |
| 966 | #if os(macOS) |
| 967 | element.click() |
| 968 | #else |
| 969 | element.tap() |
| 970 | #endif |
| 971 | } |
| 972 | |
| 973 | private func goTo(_ title: String, in app: XCUIApplication) { |
| 974 | let bar = app.tabBars.firstMatch |
| 975 | if ["Today", "Insights", "Weekly", "Coach"].contains(title), bar.exists { |
| 976 | let tab = bar.buttons[title].firstMatch |
| 977 | // When this bar minimizes, its selected tab is the only visible button. |
| 978 | if !tab.exists, let selected = bar.buttons.allElementsBoundByIndex.first(where: \.isHittable) { |
| 979 | activate(selected) |
| 980 | pause(0.4) |
| 981 | } |
| 982 | reveal(tab, in: app, down: false) |
| 983 | activate(tab) |
| 984 | } else { |
| 985 | press(title, in: app) |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | private func goBack(in app: XCUIApplication) { |
| 990 | #if os(macOS) |
| 991 | let toolbarBack = app.toolbars.buttons["Back"].firstMatch |
| 992 | if toolbarBack.isHittable { |
| 993 | toolbarBack.click() |
| 994 | return |
| 995 | } |
| 996 | #endif |
| 997 | let back = app.navigationBars.buttons.matching(NSPredicate( |
| 998 | format: "identifier == %@ OR label == %@", "_BackButton", "Back" |
| 999 | )).firstMatch |
| 1000 | if back.isHittable { |
| 1001 | activate(back) |
| 1002 | return |
| 1003 | } |
| 1004 | let bar = app.navigationBars.allElementsBoundByIndex.last { $0.buttons.firstMatch.exists } |
| 1005 | guard let bar else { |
| 1006 | XCTFail("Could not find the navigation bar's Back button") |
| 1007 | return |
| 1008 | } |
| 1009 | activate(bar.buttons.firstMatch) |
| 1010 | } |
| 1011 | |
| 1012 | private func leaveTodayDetail(in app: XCUIApplication) { |
| 1013 | if app.tabBars.firstMatch.exists { goBack(in: app) } |
| 1014 | } |
| 1015 | |
| 1016 | private func pause(_ seconds: TimeInterval) { |
| 1017 | RunLoop.current.run(until: Date().addingTimeInterval(seconds)) |
| 1018 | } |
| 1019 | |
| 1020 | /// Drags the dial's knob up to the top stop, back down to the bottom, and settles near the top. |
| 1021 | private func turnDial(_ label: String, in app: XCUIApplication) { |
| 1022 | let dial = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", label)).firstMatch |
| 1023 | XCTAssertTrue(dial.waitForExistence(timeout: 5), "Missing dial: \(label)") |
| 1024 | func point(_ x: CGFloat, _ y: CGFloat) -> XCUICoordinate { dial.coordinate(withNormalizedOffset: CGVector(dx: x, dy: y)) } |
| 1025 | let top = point(0.5, 0.12), right = point(0.86, 0.45), left = point(0.14, 0.45), high = point(0.8, 0.3) |
| 1026 | for (start, end) in [(top, right), (right, top), (top, left), (left, top), (top, high)] { |
| 1027 | #if os(macOS) |
| 1028 | start.click(forDuration: 0.15, thenDragTo: end, withVelocity: 140, thenHoldForDuration: 0.35) |
| 1029 | #else |
| 1030 | start.press(forDuration: 0.15, thenDragTo: end, withVelocity: 140, thenHoldForDuration: 0.35) |
| 1031 | #endif |
| 1032 | pause(0.5) |
| 1033 | } |
| 1034 | pause(0.8) |
| 1035 | } |
| 1036 | |
| 1037 | private func relaunch(_ app: XCUIApplication) { |
| 1038 | app.terminate() |
| 1039 | app.launch() |
| 1040 | } |
| 1041 | |
| 1042 | private func onboard(_ app: XCUIApplication, captureSetup: Bool = false, paced: Bool = false) { |
| 1043 | let options: [String?] = [ |
| 1044 | nil, "Spend less time on feeds I regret", "Short-form video", "Recharged", "Calm", |
| 1045 | "Learn & explain things", nil, "Take a walk", "Gentle & encouraging", "5 seconds, quick taps only", |
| 1046 | "Trade one short-video session for five minutes of something you care about", nil, nil, nil, |
| 1047 | ] |
| 1048 | XCTAssertTrue(app.staticTexts["A quiet place to get unstuck"].waitForExistence(timeout: 8)) |
| 1049 | for (index, option) in options.enumerated() { |
| 1050 | if paced { holdScreen("Onboarding \(index + 1) of \(options.count)") } |
| 1051 | if let option { press(option, in: app) } |
| 1052 | if captureSetup { capture(String(format: "Setup %02d", index + 1), app) } |
| 1053 | // XCUITest sometimes drops an element tap on this button (a coordinate tap, like a finger, always lands), |
| 1054 | // so confirm the next page and retry with a centre tap. |
| 1055 | let next = index + 1 < options.count ? app.staticTexts["\(index + 2) of \(options.count)"] : app.buttons["Log a moment"] |
| 1056 | press("onboardingContinue", in: app) |
| 1057 | for _ in 0..<2 where !next.waitForExistence(timeout: 3) { |
| 1058 | app.buttons["onboardingContinue"].coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap() |
| 1059 | } |
| 1060 | } |
| 1061 | XCTAssertTrue(app.buttons["Log a moment"].waitForExistence(timeout: 8)) |
| 1062 | } |
| 1063 | |
| 1064 | private func button(_ label: String, in app: XCUIApplication) -> XCUIElement { |
| 1065 | let direct = app.buttons.matching(identifier: label).firstMatch |
| 1066 | if direct.exists { return direct } |
| 1067 | let combined = app.buttons.containing(NSPredicate(format: "label BEGINSWITH %@", label)).firstMatch |
| 1068 | if combined.exists { return combined } |
| 1069 | return app.descendants(matching: .any).matching(identifier: label).firstMatch |
| 1070 | } |
| 1071 | |
| 1072 | private func press(_ label: String, in app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) { |
| 1073 | var target = button(label, in: app) |
| 1074 | // Today uses a lazy grid: off-screen destinations are created only after scrolling. |
| 1075 | for _ in 0..<4 where !target.exists { |
| 1076 | #if os(macOS) |
| 1077 | app.scrollViews.firstMatch.scroll(byDeltaX: 0, deltaY: -400) |
| 1078 | #else |
| 1079 | app.swipeUp() |
| 1080 | #endif |
| 1081 | target = button(label, in: app) |
| 1082 | } |
| 1083 | XCTAssertTrue(target.exists || target.waitForExistence(timeout: 7), "Missing control: \(label)", file: file, line: line) |
| 1084 | for _ in 0..<4 where !target.isHittable { |
| 1085 | #if os(macOS) |
| 1086 | app.scrollViews.firstMatch.scroll(byDeltaX: 0, deltaY: -400) |
| 1087 | #else |
| 1088 | app.swipeUp() |
| 1089 | #endif |
| 1090 | } |
| 1091 | #if os(macOS) |
| 1092 | target.click() |
| 1093 | #else |
| 1094 | target.tap() |
| 1095 | #endif |
| 1096 | } |
| 1097 | |
| 1098 | private func capture(_ title: String, _ app: XCUIApplication) { |
| 1099 | let attachment = XCTAttachment(screenshot: app.screenshot()) |
| 1100 | attachment.name = title |
| 1101 | attachment.lifetime = .keepAlways |
| 1102 | add(attachment) |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | private extension XCUIElement { |
| 1107 | /// Waits until the accessibility value reads as the given text. |
| 1108 | func waitForValue(_ text: String, timeout: TimeInterval = 5) -> Bool { |
| 1109 | let deadline = Date().addingTimeInterval(timeout) |
| 1110 | while value as? String != text, Date() < deadline { |
| 1111 | RunLoop.current.run(until: Date().addingTimeInterval(0.1)) |
| 1112 | } |
| 1113 | return value as? String == text |
| 1114 | } |
| 1115 | } |