mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-26 03:47:13 +01:00
Cover gap deload launch, seed and edge rows
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
218e84e04a
commit
c4dc30502b
@ -160,6 +160,9 @@ extension StorageServiceGapDeload on StorageService {
|
|||||||
where: 'name = ?',
|
where: 'name = ?',
|
||||||
whereArgs: [state.name],
|
whereArgs: [state.name],
|
||||||
);
|
);
|
||||||
|
// Only a concurrent delete between the read and this write lands here;
|
||||||
|
// no test can interleave one inside the transaction.
|
||||||
|
// coverage:ignore-start
|
||||||
if (rows != 1) {
|
if (rows != 1) {
|
||||||
log(
|
log(
|
||||||
'StorageService: ${state.name} vanished from exercise_state during '
|
'StorageService: ${state.name} vanished from exercise_state during '
|
||||||
@ -168,6 +171,7 @@ extension StorageServiceGapDeload on StorageService {
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// coverage:ignore-end
|
||||||
await txn.insert('progression_events', {
|
await txn.insert('progression_events', {
|
||||||
'at': at.toIso8601String(),
|
'at': at.toIso8601String(),
|
||||||
'exercise': state.name,
|
'exercise': state.name,
|
||||||
|
|||||||
@ -0,0 +1,78 @@
|
|||||||
|
// The gap deload end to end on launch: home cuts the lift before it reads
|
||||||
|
// the targets, and the auto-opened workout shows the old weight struck
|
||||||
|
// through next to the new one.
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:material_ui/material_ui.dart';
|
||||||
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||||
|
import 'package:workout_app/models/workout_plan.dart';
|
||||||
|
import 'package:workout_app/screens/home_screen.dart';
|
||||||
|
import 'package:workout_app/screens/workout_screen.dart';
|
||||||
|
import 'package:workout_app/services/storage_service.dart';
|
||||||
|
import 'package:workout_app/ui/theme.dart';
|
||||||
|
|
||||||
|
import '../fake_audio_platform.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUpAll(() {
|
||||||
|
sqfliteFfiInit();
|
||||||
|
databaseFactory = databaseFactoryFfi;
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
StorageService.resetForTesting();
|
||||||
|
await StorageService.init();
|
||||||
|
installFakeAudioPlatform();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('an 8-day gap opens the workout one step lighter', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final lift = workoutA.first.name;
|
||||||
|
final end = DateTime.now().subtract(const Duration(days: 8));
|
||||||
|
await tester.runAsync(() async {
|
||||||
|
final svc = StorageService.instance;
|
||||||
|
await svc.setExerciseWeight(lift, 25);
|
||||||
|
await svc.saveSession(
|
||||||
|
date: end.toIso8601String().substring(0, 10),
|
||||||
|
// B last, so the next workout is A and holds the lift.
|
||||||
|
workoutType: 'B',
|
||||||
|
durationSeconds: 3600,
|
||||||
|
succeeded: true,
|
||||||
|
json: jsonEncode({
|
||||||
|
'end_time': end.toIso8601String(),
|
||||||
|
'exercises': [
|
||||||
|
{'name': lift, 'targetWeight': 25, 'targetReps': 5},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await tester.runAsync(() async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: buildAppTheme(),
|
||||||
|
home: HomeScreen(configuredProbe: () async => false),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||||
|
await tester.pump(); // fire the post-frame auto-open
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||||
|
});
|
||||||
|
await tester.pump();
|
||||||
|
// The workout's own load (targets, then the deload marks) on the real
|
||||||
|
// loop too.
|
||||||
|
await tester.runAsync(
|
||||||
|
() => Future<void>.delayed(const Duration(milliseconds: 500)),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
|
||||||
|
expect(find.byType(WorkoutScreen), findsOneWidget);
|
||||||
|
final s = await tester.runAsync(
|
||||||
|
() => StorageService.instance.getExerciseState(lift),
|
||||||
|
);
|
||||||
|
expect(s!.weight, 22.5);
|
||||||
|
expect(find.byIcon(Icons.arrow_downward), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -167,4 +167,14 @@ void main() {
|
|||||||
await tapReal(tester, iconLabeled('Wipe sandbox data'));
|
await tapReal(tester, iconLabeled('Wipe sandbox data'));
|
||||||
expect(Sandbox.runReplayFactor, Sandbox.defaultReplayFactor);
|
expect(Sandbox.runReplayFactor, Sandbox.defaultReplayFactor);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('seed gap cases backdates sessions and says so', (tester) async {
|
||||||
|
await pump(tester);
|
||||||
|
await tapReal(tester, iconLabeled('Seed gap deload cases'));
|
||||||
|
expect(iconLabelContaining('Seeded backdated'), findsOneWidget);
|
||||||
|
final next = await tester.runAsync(
|
||||||
|
StorageService.instance.getNextWorkoutType,
|
||||||
|
);
|
||||||
|
expect(next, 'A');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,67 @@
|
|||||||
|
// Gap deload inputs the happy-path tests never produce: a history row with
|
||||||
|
// no readable time, and a stored stamp that is not a date.
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||||
|
import 'package:workout_app/models/workout_plan.dart';
|
||||||
|
import 'package:workout_app/services/storage_service.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUpAll(() {
|
||||||
|
sqfliteFfiInit();
|
||||||
|
databaseFactory = databaseFactoryFfi;
|
||||||
|
});
|
||||||
|
|
||||||
|
final lift = workoutA.first.name;
|
||||||
|
|
||||||
|
test('a row with no readable time counts toward no gap', () async {
|
||||||
|
StorageService.resetForTesting();
|
||||||
|
await StorageService.init();
|
||||||
|
final svc = StorageService.instance;
|
||||||
|
await svc.saveSession(
|
||||||
|
date: 'not a date',
|
||||||
|
workoutType: 'A',
|
||||||
|
durationSeconds: 1,
|
||||||
|
succeeded: true,
|
||||||
|
json: jsonEncode({
|
||||||
|
'exercises': [
|
||||||
|
{'name': lift},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect((await svc.sessionMarks())[lift], isNull);
|
||||||
|
expect(await svc.applyGapDeloads(now: DateTime(2026, 11, 20)), isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an unreadable stamp reads as never deloaded', () async {
|
||||||
|
final dir = await Directory.systemTemp.createTemp('gap_stamp');
|
||||||
|
addTearDown(() => dir.delete(recursive: true));
|
||||||
|
final path = p.join(dir.path, 'w.db');
|
||||||
|
StorageService.resetForTesting(dbPath: path);
|
||||||
|
await StorageService.init();
|
||||||
|
final svc = StorageService.instance;
|
||||||
|
await svc.setExerciseWeight(lift, 25);
|
||||||
|
// A second connection to the same file: the service exposes no raw
|
||||||
|
// write, and a sync pull always parses the stamp first.
|
||||||
|
final raw = await databaseFactoryFfi.openDatabase(path);
|
||||||
|
await raw.update(
|
||||||
|
'exercise_state',
|
||||||
|
{'last_deloaded_at': 'garbage'},
|
||||||
|
where: 'name = ?',
|
||||||
|
whereArgs: [lift],
|
||||||
|
);
|
||||||
|
await raw.close();
|
||||||
|
expect((await svc.getExerciseState(lift))!.lastDeloadedAt, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the sandbox seed defaults to the real clock', () async {
|
||||||
|
StorageService.resetForTesting();
|
||||||
|
await StorageService.init();
|
||||||
|
final svc = StorageService.instance;
|
||||||
|
await svc.seedGapScenarios();
|
||||||
|
expect(await svc.applyGapDeloads(), isNotEmpty);
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user