Files
rippr/test/activity_profile_test.dart
uhryniuk 6f1bfc753a V3-01: activity type per ride
Adds Activity (motorcycle/bicycle/scooter/skateboard/running/walking/other) as
a column on Trip, and threads it through as real behaviour rather than a label:
ActivityProfile (domain/activity_profile.dart) carries a noise floor, accuracy
gate, histogram bucket width, and elevation smoothing window/threshold per
activity, consumed by sanitizeSpeedKmh, isUsableFix, computeSummary, Accumulator
and speedHistogram. The motorcycle profile reproduces the exact constants the
app shipped with before this existed, and a test asserts they never drift apart.

This is the port's first real migration: schemaVersion 1 -> 2,
m.addColumn(trips, trips.activity) with a motorcycle default so every existing
row survives unmodified. Proven with a hand-built v1 SQLite file (raw sqlite3,
not drift_dev's schema tooling) that a real database with real rides upgrades
and keeps every trip, segment and point.

No picker in front of Start: a new trip defaults to whichever activity was most
recently used, derived live from the trips table rather than duplicated into a
Config field. Editable afterwards on trip detail, which recomputes aggregates
under the new profile immediately -- a walking pace that reads as noise under a
motorcycle's floor reads as real movement once the activity is corrected, and
there's a test proving exactly that transition.

The widget-test pass for the activity-picker sheet caught a real overflow bug:
seven options overflowed a Column-based bottom sheet the same way the record
screen once did. Fixed with a scrollable ListView + isScrollControlled, same
shape as that earlier fix.

188 tests (171 -> 188): 2 migration, 5 ActivityProfile, 3 profile-threading
proofs in computeSummary, 5 repository, 2 widget. Analyze clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 14:09:11 -05:00

65 lines
2.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:rippr/src/domain/activity_profile.dart';
import 'package:rippr/src/domain/models.dart';
import 'package:rippr/src/telemetry/telemetry.dart';
/// Ported concept check for V3-01: activity type must drive real behaviour, not just a
/// label.
void main() {
test(
'the motorcycle profile reproduces the constants the app shipped with before '
'activity type existed',
() {
// ActivityProfile.motorcycle deliberately duplicates these as literals rather than
// importing them, to avoid a domain-layer dependency cycle -- this is the promised
// check that the two never drift apart silently.
expect(ActivityProfile.motorcycle.noiseFloorKmh, speedNoiseFloorKmh);
expect(ActivityProfile.motorcycle.elevationThresholdM, 3.0);
expect(ActivityProfile.motorcycle.elevationWindowSamples, 15);
expect(ActivityProfile.motorcycle.accuracyGateM, 50.0);
expect(ActivityProfile.motorcycle.histogramBucketKmh, 10);
},
);
test('forActivity covers every Activity value with no fallback surprises', () {
for (final activity in Activity.values) {
// Must not throw -- an unhandled case here would be a runtime crash on a
// brand-new trip, not a compile error, since the switch is exhaustive over the
// enum today but a future Activity value could slip through review.
expect(() => ActivityProfile.forActivity(activity), returnsNormally);
}
});
test('slower activities get a lower noise floor than a motorcycle', () {
final motorcycle = ActivityProfile.forActivity(Activity.motorcycle);
final walking = ActivityProfile.forActivity(Activity.walking);
final running = ActivityProfile.forActivity(Activity.running);
expect(walking.noiseFloorKmh, lessThan(motorcycle.noiseFloorKmh));
expect(running.noiseFloorKmh, lessThan(motorcycle.noiseFloorKmh));
expect(
walking.noiseFloorKmh,
lessThan(running.noiseFloorKmh),
reason: 'a walk is slower than a run, so real movement sits even closer to noise',
);
});
test('running and walking use a finer speed histogram than a motorcycle', () {
// 10 km/h bands are useless for an activity that rarely exceeds 10 km/h at all.
expect(ActivityProfile.forActivity(Activity.running).histogramBucketKmh, 1);
expect(ActivityProfile.forActivity(Activity.walking).histogramBucketKmh, 1);
expect(ActivityProfile.forActivity(Activity.motorcycle).histogramBucketKmh, 10);
});
test('scooter and other fall back to the safest generic profile', () {
expect(
ActivityProfile.forActivity(Activity.scooter),
same(ActivityProfile.motorcycle),
);
expect(
ActivityProfile.forActivity(Activity.other),
same(ActivityProfile.motorcycle),
);
});
}