fix(alarm): localize pre-notice countdown and fix snooze dismiss
Replace hardcoded Spanish pre-notice text with computed remaining minutes using l10n template passed via MethodChannel. Fix snooze dismiss in dead-app state with canPop guard and SystemNavigator.pop fallback.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/modelos/alarma_musical.dart';
|
||||
import 'package:pluriwave/servicios/servicio_alarmas_android.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel('pluriwave/alarm_scheduler');
|
||||
late List<MethodCall> llamadas;
|
||||
|
||||
setUp(() {
|
||||
llamadas = [];
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
llamadas.add(call);
|
||||
if (call.method == 'scheduleAlarm') return true;
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
});
|
||||
|
||||
test(
|
||||
'programar includes preNoticeTemplate with {minutes} placeholder in MethodChannel call',
|
||||
() async {
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
final alarma = AlarmaMusical(
|
||||
id: 'test-alarm',
|
||||
nombre: 'Morning alarm',
|
||||
hora: 7,
|
||||
minuto: 0,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2099, 1, 1, 7, 0),
|
||||
);
|
||||
|
||||
await servicio.programar(alarma);
|
||||
|
||||
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
expect(args.containsKey('preNoticeTemplate'), isTrue,
|
||||
reason: 'preNoticeTemplate must be present in scheduleAlarm args');
|
||||
final template = args['preNoticeTemplate'] as String?;
|
||||
expect(template, isNotNull,
|
||||
reason: 'preNoticeTemplate must not be null');
|
||||
expect(template, contains('{minutes}'),
|
||||
reason: 'preNoticeTemplate must contain the {minutes} placeholder');
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'programar preNoticeTemplate uses default locale fallback when no l10n configured',
|
||||
() async {
|
||||
// ServicioAlarmasAndroid falls back to es locale when no l10n is configured
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
final alarma = AlarmaMusical(
|
||||
id: 'test-alarm-2',
|
||||
nombre: 'Alarm',
|
||||
hora: 8,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2099, 1, 2, 8, 30),
|
||||
);
|
||||
|
||||
await servicio.programar(alarma);
|
||||
|
||||
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
||||
final args = llamada.arguments as Map<Object?, Object?>;
|
||||
final template = args['preNoticeTemplate'] as String?;
|
||||
// The template must contain the literal placeholder string
|
||||
expect(template, contains('{minutes}'));
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user