|
| 1 | +import 'dart:async'; |
| 2 | + |
1 | 3 | import 'package:flutter_test/flutter_test.dart'; |
2 | 4 | import 'package:on_time_front/presentation/app/bloc/auth/auth_bloc.dart'; |
| 5 | +import 'package:on_time_front/presentation/app/bloc/schedule/schedule_bloc.dart'; |
3 | 6 | import 'package:on_time_front/presentation/app/cubit/alarm_gate_cubit.dart'; |
4 | 7 | import 'package:on_time_front/presentation/app/cubit/notification_gate_cubit.dart'; |
5 | 8 | import 'package:on_time_front/presentation/shared/router/go_router.dart'; |
6 | 9 |
|
7 | 10 | void main() { |
| 11 | + test( |
| 12 | + 'router refresh listenable ignores schedule progress but refreshes for route gates', |
| 13 | + () async { |
| 14 | + final scheduleController = StreamController<ScheduleState>.broadcast(); |
| 15 | + final authController = StreamController<AuthState>.broadcast(); |
| 16 | + final notificationGateController = |
| 17 | + StreamController<NotificationGateState>.broadcast(); |
| 18 | + final alarmGateController = StreamController<AlarmGateState>.broadcast(); |
| 19 | + final listenable = appRouterRefreshListenable( |
| 20 | + authStream: authController.stream, |
| 21 | + notificationGateStream: notificationGateController.stream, |
| 22 | + alarmGateStream: alarmGateController.stream, |
| 23 | + ); |
| 24 | + addTearDown(() async { |
| 25 | + listenable.dispose(); |
| 26 | + await scheduleController.close(); |
| 27 | + await authController.close(); |
| 28 | + await notificationGateController.close(); |
| 29 | + await alarmGateController.close(); |
| 30 | + }); |
| 31 | + |
| 32 | + var refreshCount = 0; |
| 33 | + listenable.addListener(() => refreshCount++); |
| 34 | + |
| 35 | + scheduleController.add(const ScheduleState.initial()); |
| 36 | + await pumpEventQueue(); |
| 37 | + |
| 38 | + expect(refreshCount, 0); |
| 39 | + |
| 40 | + authController.add(const AuthState.loading()); |
| 41 | + notificationGateController.add(const NotificationGateState.required()); |
| 42 | + alarmGateController.add(const AlarmGateState.required()); |
| 43 | + await pumpEventQueue(); |
| 44 | + |
| 45 | + expect(refreshCount, 3); |
| 46 | + }, |
| 47 | + ); |
| 48 | + |
8 | 49 | test( |
9 | 50 | 'authenticated user goes directly to notification prompt while alarm gate is unresolved', |
10 | 51 | () { |
|
0 commit comments