wake-alarm/phone_app/test/session_screen_bypass_test.dart
Krzysztof kuhy Rudnicki 65df7f6682 Name a bypass's session re-ring for its cause
A bypass during a live morning session restarted the ring natively, and
the session recorded that re-ring as deadline:<leg> (C7, 2026-11-22).
Bypass.record now stamps the cause (dated) when nothing was ringing; the
session takes it on its tick or on the dismiss and records bypass:<cause>.
A bypass during a deadline re-ring stamps nothing: one sound, one re-ring.

Also a debug-only sync backend: a probe build with WAKE_SYNC_EMULATOR
syncs to the PC's RTDB emulator instead of prod and the GitHub mirror,
with scripts/emu_published.py reading it back for _fallback --published.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:53:26 +01:00

68 lines
2.4 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/session_store.dart';
import 'package:wake_alarm_sync/services/session_tag_settings.dart';
/// A bypass during a live session restarts the ring natively; the session
/// screen finds it sounding and must name the re-ring for the bypass, not
/// for the leg's deadline (C7's emulator run recorded `deadline:bathroomIn`).
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final now = DateTime(2026, 9, 17, 8, 4);
String? bypassCause;
late List<String> calls;
setUp(() async {
calls = <String>[];
bypassCause = null;
SharedPreferences.setMockInitialValues(<String, Object>{});
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel(AlarmScheduler.channelName),
(call) async {
calls.add(call.method);
if (call.method == 'hasNfc') return true;
if (call.method == 'isRinging') return true;
if (call.method == 'takeBypassReRing') return bypassCause;
return null;
},
);
await SessionTagSettings.replaceAll(<String>['bath', 'ward', 'desk'], '');
});
Future<String?> ringReasonAfterOneTick(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
routes: <String, WidgetBuilder>{
'/': (_) =>
SessionScreen(clock: () => now, publish: () async => 'pushed'),
'/ring': (_) => const Scaffold(body: Text('RING')),
},
),
);
await tester.pump();
await tester.pump();
await tester.pump(kSessionTick);
await tester.pumpAndSettle();
expect(find.text('RING'), findsOneWidget);
return (await SessionStore().loadCurrent())!.pendingReRingReason;
}
testWidgets('a ring a bypass started is named for the bypass', (
tester,
) async {
bypassCause = 'suspended';
expect(await ringReasonAfterOneTick(tester), 'bypass:suspended');
expect(calls, contains('takeBypassReRing'));
});
testWidgets('a ring nothing stamped is the deadline', (tester) async {
expect(await ringReasonAfterOneTick(tester), 'deadline:bathroomIn');
});
}