Restructure into a three-tab app with Progress, goals, and Meditation
The UX redesign's first landing (spec in UX-REDESIGN.md): ContentView becomes a Today / Progress / Settings TabView, "Routine" replaces "Split" in every user-facing string and view name (code-level types keep their names), and workout starting moves to shared WorkoutStarter / StartedWorkoutNavigator plumbing. - New Progress tab: weekly goal streaks, workout trends, per-exercise weight progression, achievements, and the full history list (WorkoutLogsView -> WorkoutHistoryView). - Goals: stable categories workouts roll up to, managed from Settings. - New Meditation exercise + starter routine; timed sits record to Apple Health as Mind & Body sessions. Claude-Session: https://claude.ai/code/session_012qw2itfzKyEJ1HpsFt8Ex4
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import IndieSync
|
||||
import SwiftData
|
||||
import Testing
|
||||
@testable import Workouts
|
||||
@@ -20,19 +21,70 @@ struct SyncEngineTests {
|
||||
|
||||
@MainActor
|
||||
private func makeEngine() throws -> SyncEngine {
|
||||
let schema = Schema([Split.self, Exercise.self, Workout.self, WorkoutLog.self])
|
||||
let schema = Schema([Routine.self, Exercise.self, Workout.self, WorkoutLog.self])
|
||||
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: true, cloudKitDatabase: .none)
|
||||
return SyncEngine(container: try ModelContainer(for: schema, configurations: [config]))
|
||||
let backlogURL = FileManager.default.temporaryDirectory
|
||||
.appending(path: "SyncEngineTests-\(UUID().uuidString).json")
|
||||
return SyncEngine(container: try ModelContainer(for: schema, configurations: [config]),
|
||||
backlogURL: backlogURL)
|
||||
}
|
||||
|
||||
/// With no clone-on-edit fork recorded, `currentSplitID` is the identity — a view
|
||||
/// holding a split id resolves to that same id. This pins the redirect-follow loop's
|
||||
/// A minimal workout document with one log, both carrying the given statuses.
|
||||
private func makeWorkout(id: String, status: WorkoutStatus, logStatus: WorkoutStatus) -> WorkoutDocument {
|
||||
let now = Date()
|
||||
var log = WorkoutLogDocument(planFrom: ExerciseDocument(
|
||||
id: ULID.make(), name: "Seated Row", order: 0, sets: 3, reps: 10,
|
||||
weight: 90, loadType: LoadType.weight.rawValue, durationSeconds: 0), order: 0, date: now)
|
||||
log.status = logStatus.rawValue
|
||||
return WorkoutDocument(
|
||||
schemaVersion: WorkoutDocument.currentSchemaVersion, id: id,
|
||||
routineID: nil, routineName: "Upper Body", start: now, end: nil,
|
||||
status: status.rawValue, createdAt: now, updatedAt: now, logs: [log])
|
||||
}
|
||||
|
||||
/// Locks `onWorkoutBecameActive`'s trigger table: it fires exactly once, on a
|
||||
/// phone-side `.notStarted` → `.inProgress` transition — not on draft creation,
|
||||
/// not on a repeat in-progress save, not for a watch-originated update, and not
|
||||
/// when an old workout is edited from `.completed` back to `.inProgress`.
|
||||
@MainActor
|
||||
@Test func becameActiveFiresOnlyOnLocalNotStartedToInProgress() async throws {
|
||||
let engine = try makeEngine()
|
||||
var fired: [String] = []
|
||||
engine.onWorkoutBecameActive = { fired.append($0.id) }
|
||||
|
||||
// Draft creation: notStarted → no fire.
|
||||
let id = ULID.make()
|
||||
await engine.save(workout: makeWorkout(id: id, status: .notStarted, logStatus: .notStarted))
|
||||
#expect(fired.isEmpty)
|
||||
|
||||
// First exercise starts: notStarted → inProgress fires once.
|
||||
await engine.save(workout: makeWorkout(id: id, status: .inProgress, logStatus: .inProgress))
|
||||
#expect(fired == [id])
|
||||
|
||||
// Re-saving an already-active run doesn't re-fire.
|
||||
await engine.save(workout: makeWorkout(id: id, status: .inProgress, logStatus: .inProgress))
|
||||
#expect(fired == [id])
|
||||
|
||||
// A watch-originated start never fires — the watch already owns a session.
|
||||
let watchID = ULID.make()
|
||||
await engine.ingestFromWatch(makeWorkout(id: watchID, status: .inProgress, logStatus: .inProgress))
|
||||
#expect(fired == [id])
|
||||
|
||||
// Editing a finished workout back to in-progress isn't a fresh start.
|
||||
let oldID = ULID.make()
|
||||
await engine.save(workout: makeWorkout(id: oldID, status: .completed, logStatus: .completed))
|
||||
await engine.save(workout: makeWorkout(id: oldID, status: .inProgress, logStatus: .inProgress))
|
||||
#expect(fired == [id])
|
||||
}
|
||||
|
||||
/// With no clone-on-edit fork recorded, `currentRoutineID` is the identity — a view
|
||||
/// holding a routine id resolves to that same id. This pins the redirect-follow loop's
|
||||
/// base case and its termination (no redirect → return input, no infinite loop).
|
||||
@MainActor
|
||||
@Test func currentSplitIDIsIdentityWithoutRedirects() throws {
|
||||
@Test func currentRoutineIDIsIdentityWithoutRedirects() throws {
|
||||
let engine = try makeEngine()
|
||||
#expect(engine.currentSplitID(for: "01SEEDABCDEFGHJKMNPQRSTVWX") == "01SEEDABCDEFGHJKMNPQRSTVWX")
|
||||
#expect(engine.currentSplitID(for: "") == "")
|
||||
#expect(engine.currentRoutineID(for: "01SEEDABCDEFGHJKMNPQRSTVWX") == "01SEEDABCDEFGHJKMNPQRSTVWX")
|
||||
#expect(engine.currentRoutineID(for: "") == "")
|
||||
}
|
||||
|
||||
/// A freshly constructed engine is in the `.checking` state until `connect()` runs,
|
||||
|
||||
Reference in New Issue
Block a user