Machine-based exercises now carry ordered name/value comfort settings (seat height, back-rest position, ...) on both ExerciseDocument and, as a plan-time snapshot, WorkoutLogDocument — the optional array doubles as the machine flag. Editable from the exercise editor's new Machine section and from the workout row's settings sheet, whose mid-workout edits write back to the originating split (workout saved first, so seed clone-on-edit repointing can't clobber the log edit). Schema tightening rides the same rev: splits bump to v2 (weight-reminder fields and the unused exercise category removed), workouts to v3 (the derived `completed` flag removed; status is the single source). Starter seeds regenerated at v2 with unchanged ULIDs; SwiftData cache schema bumped to rebuild. SCHEMA.md documents the shapes. Claude-Session: https://claude.ai/code/session_01LEoff8bXGBS83tK1c55Mf7
63 lines
2.4 KiB
Swift
63 lines
2.4 KiB
Swift
import Foundation
|
|
import Testing
|
|
import IndieSync
|
|
@testable import Workouts
|
|
|
|
/// Pins the plan-time snapshot (`WorkoutLogDocument(planFrom:order:date:)`) — the
|
|
/// single helper every "start workout" / "add exercise" path funnels through. The
|
|
/// machine comfort settings must ride along with the other plan fields, and the
|
|
/// nil-vs-empty distinction (not-a-machine vs machine-with-nothing-recorded) must
|
|
/// be preserved exactly.
|
|
struct WorkoutLogSnapshotTests {
|
|
private static let ts = Date(timeIntervalSince1970: 1_700_000_000)
|
|
|
|
@Test func snapshotCopiesMachineSettingsAndPlanFields() {
|
|
let exercise = ExerciseDocument(
|
|
id: ULID.make(), name: "Leg Press", order: 2, sets: 4, reps: 10,
|
|
weight: 140, loadType: 1, durationSeconds: 0,
|
|
machineSettings: [
|
|
MachineSetting(name: "Seat Height", value: "4"),
|
|
MachineSetting(name: "Back Rest Incline", value: "45°")
|
|
]
|
|
)
|
|
|
|
let log = WorkoutLogDocument(planFrom: exercise, order: 5, date: Self.ts)
|
|
|
|
#expect(log.machineSettings == exercise.machineSettings)
|
|
#expect(log.exerciseName == "Leg Press")
|
|
#expect(log.order == 5) // the passed order, not the exercise's
|
|
#expect(log.sets == 4)
|
|
#expect(log.reps == 10)
|
|
#expect(log.weight == 140)
|
|
#expect(log.loadType == 1)
|
|
#expect(log.durationSeconds == 0)
|
|
#expect(log.date == Self.ts)
|
|
#expect(log.currentStateIndex == 0)
|
|
#expect(log.status == WorkoutStatus.notStarted.rawValue)
|
|
}
|
|
|
|
@Test func snapshotPreservesNilForNonMachineExercise() {
|
|
let exercise = ExerciseDocument(
|
|
id: ULID.make(), name: "Plank", order: 0, sets: 3, reps: 0,
|
|
weight: 0, loadType: 2, durationSeconds: 45
|
|
)
|
|
|
|
let log = WorkoutLogDocument(planFrom: exercise, order: 0, date: Self.ts)
|
|
|
|
#expect(log.machineSettings == nil)
|
|
}
|
|
|
|
@Test func snapshotPreservesEmptyMachineSettings() {
|
|
// Empty ≠ nil: a machine exercise with nothing recorded yet must stay empty,
|
|
// not collapse to "not a machine exercise".
|
|
let exercise = ExerciseDocument(
|
|
id: ULID.make(), name: "Chest Press", order: 0, sets: 4, reps: 10,
|
|
weight: 40, loadType: 1, durationSeconds: 0, machineSettings: []
|
|
)
|
|
|
|
let log = WorkoutLogDocument(planFrom: exercise, order: 0, date: Self.ts)
|
|
|
|
#expect(log.machineSettings == [])
|
|
}
|
|
}
|