Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

iOS UI test: reminder and nudge are pending with iOS

Duarte Santos29f29f5f1176
diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml
index 744f7eca6..5f2cc8f91 100644
--- a/.github/workflows/ios.yml
+++ b/.github/workflows/ios.yml
@@ -85,7 +85,9 @@ jobs:
retention-days: 7
# A walk through the app in the simulator (ios/App/AppUITests): a rest that ends while the app
- # is in the background must arrive as a notification, a sheet must stay above the keyboard.
+ # is in the background must arrive as a notification, a sheet must stay above the keyboard, and
+ # the training reminder and missed-day nudge must be pending with iOS once switched on (read
+ # through the -OpenGymUITestPending probe in MainViewController.swift).
# The exercise media are left out of this build; the screenshots show placeholders.
ui-tests:
runs-on: macos-26
diff --git a/frontend/ios/App/App/MainViewController.swift b/frontend/ios/App/App/MainViewController.swift
index 6969c56e4..73f64d46a 100644
--- a/frontend/ios/App/App/MainViewController.swift
+++ b/frontend/ios/App/App/MainViewController.swift
@@ -1,5 +1,6 @@
import Capacitor
import UIKit
+import UserNotifications
/**
* The app's own bridge view controller (Main.storyboard). Since Capacitor 6 the bridge only loads
@@ -10,5 +11,51 @@ class MainViewController: CAPBridgeViewController {
override open func capacitorDidLoad() {
bridge?.registerPluginInstance(PrintPlugin())
bridge?.registerPluginInstance(RestAlertPlugin())
+ // After loadView has finished: the view is the web view only once it has.
+ if ProcessInfo.processInfo.arguments.contains(MainViewController.pendingProbeArgument) {
+ DispatchQueue.main.async { [weak self] in self?.showPendingProbe() }
+ }
+ }
+
+ /**
+ * For the UI tests only (ios/App/AppUITests): launched with this argument, the app shows the
+ * ids of the local notifications iOS holds for it, as a tiny label a test can read. A UI test
+ * runs in its own process and cannot ask UNUserNotificationCenter about another app, and this
+ * is what iOS really has pending, not what the page meant to schedule. Never shown otherwise:
+ * nothing but XCUIApplication.launchArguments passes the argument.
+ */
+ static let pendingProbeArgument = "-OpenGymUITestPending"
+
+ private func showPendingProbe() {
+ // On the window, not inside the web view: what a WKWebView holds is its page as far as
+ // accessibility goes, and a label among its subviews may never reach the test.
+ guard let host = view.window else {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in self?.showPendingProbe() }
+ return
+ }
+ let label = UILabel()
+ label.accessibilityIdentifier = "og-pending-notifications"
+ label.font = .systemFont(ofSize: 8)
+ label.textColor = .systemGray
+ label.numberOfLines = 1
+ label.isUserInteractionEnabled = false
+ label.text = "pending:"
+ label.translatesAutoresizingMaskIntoConstraints = false
+ host.addSubview(label)
+ NSLayoutConstraint.activate([
+ label.leadingAnchor.constraint(equalTo: host.leadingAnchor, constant: 2),
+ label.bottomAnchor.constraint(equalTo: host.bottomAnchor, constant: -2),
+ ])
+ Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak label] _ in
+ UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
+ let ids = requests.map { $0.identifier }.sorted().joined(separator: ",")
+ DispatchQueue.main.async {
+ guard let label = label else { return }
+ label.text = "pending:" + ids
+ label.accessibilityLabel = "pending:" + ids
+ label.superview?.bringSubviewToFront(label)
+ }
+ }
+ }
}
}
diff --git a/frontend/ios/App/AppUITests/OpenGymUITests.swift b/frontend/ios/App/AppUITests/OpenGymUITests.swift
index 9bb150f00..ce185658a 100644
--- a/frontend/ios/App/AppUITests/OpenGymUITests.swift
+++ b/frontend/ios/App/AppUITests/OpenGymUITests.swift
@@ -3,7 +3,8 @@ import XCTest
/**
* Walks the iPhone app the way someone new does and checks what only a real phone shows: that the
* end of a rest still arrives as a notification once the app has left the screen (RestAlertPlugin),
- * and that a sheet with a text field stays above the keyboard. Run by .github/workflows/ios.yml,
+ * that a sheet with a text field stays above the keyboard, and that the training reminder and the
+ * missed-day nudge are really pending with iOS once switched on. Run by .github/workflows/ios.yml,
* which adds this target to the project for the run only (ios/ci/add-ui-tests.rb). The run's
* build carries no exercise media, so the screenshots it keeps show placeholders.
*/
@@ -33,7 +34,8 @@ final class OpenGymUITests: XCTestCase {
/**
* "Use on this device", until home shows. On a slow simulator the first tap can land while the
- * page is still starting and go nowhere.
+ * page is still starting and go nowhere. The first-start notifications step comes right after
+ * the choice (views/PermissionSteps.jsx): it is allowed here, and so is the system's question.
*/
private func chooseLocal() {
if app.buttons["Log"].waitForExistence(timeout: 45) { return } // chosen in an earlier test
@@ -41,11 +43,30 @@ final class OpenGymUITests: XCTestCase {
XCTAssertTrue(local.waitForExistence(timeout: 60), "the onboarding choice did not show up")
for _ in 0..<5 {
if local.exists { local.tap() }
+ passPermissionStep()
if app.buttons["Log"].waitForExistence(timeout: 8) { return }
}
XCTFail("home never showed after the onboarding choice")
}
+ /** The notifications step, if it shows: Allow, then the system's own Allow. */
+ private func passPermissionStep() {
+ let step = app.staticTexts["Never miss the end of a rest"]
+ guard step.waitForExistence(timeout: 6) else { return }
+ shot("0-permission-step")
+ let allow = app.buttons["Allow"]
+ if allow.exists { allow.tap() }
+ allowSystemAlert(within: 10)
+ }
+
+ private func allowSystemAlert(within seconds: Int) {
+ let allow = springboard.alerts.buttons["Allow"]
+ for _ in 0..<seconds {
+ if allow.exists { allow.tap(); return }
+ sleep(1)
+ }
+ }
+
// XCTest runs a class's tests in name order: the keyboard check wants a plain home screen, and
// this one leaves a workout running.
func test2RestEndsWithANotificationInTheBackground() {
@@ -87,6 +108,74 @@ final class OpenGymUITests: XCTestCase {
XCTAssertTrue(arrived, "the end of the rest never arrived as a notification")
}
+ /**
+ * The training reminder and the missed-day nudge reach iOS as pending local notifications:
+ * a workout logged today (finished here, or the one test2 left running), the reminder and
+ * the nudge switched on, and then iOS itself is asked what it holds for the app. The app
+ * shows that only when launched with -OpenGymUITestPending (MainViewController.swift).
+ * Reminder ids are 1000-1059 (one per planned day in 60), nudge ids 2000-2006
+ * (lib/mobile.js); with a three-day plan and a workout today the week ahead always has both.
+ */
+ func test3ReminderAndNudgeArePendingNotifications() {
+ app.launchArguments = ["-OpenGymUITestPending"]
+ app.launch()
+ let finish = app.buttons["Finish"]
+ let resume = app.buttons["Resume"]
+ let home = app.buttons["Log"]
+ let local = app.buttons["Use on this device"]
+ var landed = false
+ for _ in 0..<60 {
+ if finish.exists || resume.exists || home.exists || local.exists { landed = true; break }
+ sleep(1)
+ }
+ XCTAssertTrue(landed, "the app never showed a screen")
+ if local.exists { chooseLocal() }
+ if !finish.exists && resume.exists { resume.tap() }
+ if !finish.waitForExistence(timeout: 5) {
+ // Nothing running (test2 failed early or ran alone): start one the way test2 does.
+ XCTAssertTrue(home.waitForExistence(timeout: 30), "home did not show")
+ if app.buttons["Load starter plan"].waitForExistence(timeout: 5) {
+ tap(app.buttons["Load starter plan"], "Load starter plan")
+ tap(button(startingWith: "Full Body"), "the Full Body plan")
+ }
+ tap(app.buttons["Choose a different workout"], "Choose a different workout")
+ tap(app.staticTexts["Full Body A"], "Full Body A")
+ tap(app.switches["Set 1 done"], "Set 1 done")
+ allowSystemAlert(within: 5)
+ }
+ tap(finish, "Finish")
+ tap(button(startingWith: "Finish and save"), "Finish and save")
+ tap(app.buttons["Nice!"], "Nice! (the summary)", timeout: 20)
+ shot("6-finished")
+
+ tap(button(startingWith: "Settings"), "Settings")
+ tap(button(startingWith: "Reminders"), "Reminders")
+ let reminder = app.switches["Workout day reminder"]
+ XCTAssertTrue(reminder.waitForExistence(timeout: 15), "no reminder switch")
+ if (reminder.value as? String) != "1" { reminder.tap() }
+ allowSystemAlert(within: 3)
+ let nudge = app.switches["Nudge me when I skip a planned workout"]
+ XCTAssertTrue(nudge.waitForExistence(timeout: 15), "no nudge switch")
+ if (nudge.value as? String) != "1" { nudge.tap() }
+ shot("7-reminders-on")
+
+ // The store reschedules on its next save; poll what iOS holds until both kinds are there.
+ let probe = app.staticTexts["og-pending-notifications"]
+ XCTAssertTrue(probe.waitForExistence(timeout: 20), "the pending-notifications probe is missing")
+ var ids: [Int] = []
+ for _ in 0..<45 {
+ ids = probe.label.replacingOccurrences(of: "pending:", with: "").split(separator: ",").compactMap { Int($0) }
+ if ids.contains(where: { (1000...1059).contains($0) }) && ids.contains(where: { (2000...2006).contains($0) }) { break }
+ sleep(1)
+ }
+ let pending = XCTAttachment(string: probe.label)
+ pending.name = "pending notifications"
+ pending.lifetime = .keepAlways
+ add(pending)
+ XCTAssertTrue(ids.contains(where: { (1000...1059).contains($0) }), "no training reminder pending: \(probe.label)")
+ XCTAssertTrue(ids.contains(where: { (2000...2006).contains($0) }), "no missed-day nudge pending: \(probe.label)")
+ }
+
func test1WeighInSheetStaysAboveTheKeyboard() {
app.launch()
chooseLocal()
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 490c22675..c9712a192 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -1094,7 +1094,7 @@ function MobileReminderCard({ S, update, toast }) {
<Section title={t('Notifications')}
footer={S.reminder?.on ? t('Reminds you at this time on days that have a routine planned.') + nudgeNote(S) : null}>
<Row icon="calendar" iconTint="var(--orange)" title={t('Workout day reminder')}>
- <Switch checked={!!S.reminder?.on} onChange={toggle} />
+ <Switch checked={!!S.reminder?.on} onChange={toggle} aria-label={t('Workout day reminder')} />
</Row>
{S.reminder?.on && (
<Row icon="clock" iconTint="var(--purple)" title={t('Reminder time')}>
@@ -1113,7 +1113,7 @@ function NudgeRows({ S, setReminder }) {
const r = S.reminder || {}
return <>
<Row icon="bell" iconTint="var(--red)" title={t('Nudge me when I skip a planned workout')}>
- <Switch checked={!!r.nudge} onChange={() => setReminder({ nudge: !r.nudge })} />
+ <Switch checked={!!r.nudge} onChange={() => setReminder({ nudge: !r.nudge })} aria-label={t('Nudge me when I skip a planned workout')} />
</Row>
{r.nudge && (
<SelectRow icon="chat" iconTint="var(--blue)" title={t('Nudge tone')}
diff --git a/frontend/src/views/Settings.nudge.test.jsx b/frontend/src/views/Settings.nudge.test.jsx
index 8cf0b3be1..dffb88207 100644
--- a/frontend/src/views/Settings.nudge.test.jsx
+++ b/frontend/src/views/Settings.nudge.test.jsx
@@ -128,6 +128,13 @@ describe.each([['self-hosted (web push)', false], ['mobile (native)', true]])('S
expect(toneRow()).toBeFalsy()
})
+ // The iPhone UI test (ios/App/AppUITests) finds these switches by name; so does VoiceOver.
+ it('names its switch, so it can be found without reading the row around it', async () => {
+ await mount()
+ expect(nudgeRow().querySelector('[role=switch]').getAttribute('aria-label')).toBe('Nudge me when I skip a planned workout')
+ if (mobile) expect(host.querySelector('[role=switch][aria-label="Workout day reminder"]')).toBeTruthy()
+ })
+
it('is not offered while the reminder is off', async () => {
mocks.S.reminder = { on: false, time: '08:00', nudge: true }
await mount()