mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-20 14:32:23 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (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,free-days-interop) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Flutter 3.50 deprecates package:flutter/material.dart, so the app moves to material_ui 1.11.0 together with sync_settings_ui 0.8.0 and github_device_auth 0.5.0 (crdt_sync 0.13.1 rides along). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
82 lines
3.1 KiB
Dart
82 lines
3.1 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:wake_alarm_sync/screens/session_screen.dart';
|
|
import 'package:wake_alarm_sync/services/alarm_scheduler.dart';
|
|
import 'package:wake_alarm_sync/services/morning_session.dart';
|
|
import 'package:wake_alarm_sync/services/session_rules.dart';
|
|
import 'package:wake_alarm_sync/services/session_store.dart';
|
|
import 'package:wake_alarm_sync/services/session_tag_settings.dart';
|
|
|
|
/// The session screen reached cold by the launcher redirect, not by a ring.
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
late List<MethodCall> calls;
|
|
final now = DateTime(2026, 9, 17, 8, 40);
|
|
|
|
setUp(() async {
|
|
calls = <MethodCall>[];
|
|
SharedPreferences.setMockInitialValues(<String, Object>{});
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(
|
|
const MethodChannel(AlarmScheduler.channelName),
|
|
(call) async {
|
|
calls.add(call);
|
|
return call.method == 'hasNfc' ? true : null;
|
|
},
|
|
);
|
|
await SessionTagSettings.replaceAll(<String>['bath', 'ward', 'desk'], '');
|
|
});
|
|
|
|
Future<void> pumpCold(WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: SessionScreen(clock: () => now, publish: () async => 'ok'),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
testWidgets('resumes the persisted session at its live leg', (tester) async {
|
|
final at = now.subtract(const Duration(minutes: 4));
|
|
final session =
|
|
SessionRules.start(
|
|
now: now.subtract(const Duration(minutes: 5)),
|
|
tags: await SessionTagSettings.load(),
|
|
nfcAvailable: true,
|
|
)
|
|
..enterCheckIn(72, 3, at)
|
|
..onTag(SessionTagSlot.bathroom, at);
|
|
await SessionStore().save(session);
|
|
await pumpCold(tester);
|
|
expect(find.text('72.0'), findsOneWidget);
|
|
expect(find.text('3/5'), findsOneWidget);
|
|
expect(find.textContaining('04:00'), findsOneWidget);
|
|
final notice = calls.lastWhere((c) => c.method == 'updateSessionNotice');
|
|
expect((notice.arguments as Map<Object?, Object?>)['label'], '🚿 2/4');
|
|
expect(calls.map((c) => c.method), isNot(contains('closeRingScreen')));
|
|
});
|
|
|
|
testWidgets('with today already finished it clears the record and closes', (
|
|
tester,
|
|
) async {
|
|
final done = SessionRules.start(
|
|
now: now.subtract(const Duration(minutes: 30)),
|
|
tags: const SessionTagSettings(),
|
|
nfcAvailable: false,
|
|
)..enterCheckIn(72, 3, now.subtract(const Duration(minutes: 29)));
|
|
expect(done.outcome, SessionOutcome.completed);
|
|
await SessionStore().archive(done);
|
|
await pumpCold(tester);
|
|
final methods = calls.map((c) => c.method).toList();
|
|
expect(methods, contains('finishSession'));
|
|
expect(methods.last, 'closeRingScreen');
|
|
expect(methods, isNot(contains('updateSessionNotice')));
|
|
expect(await SessionStore().loadCurrent(), isNull);
|
|
expect((await SessionStore().history()).length, 1);
|
|
});
|
|
}
|