fix(alarm): fail-safe alarm system overhaul (SDD alarm-system-overhaul, slice A)
Root-cause fix for the unstoppable-alarm incident (alarm rang 15 minutes, only uninstall silenced it) plus systematic hardening of every stop path. Native (Kotlin): - Verified stop: stopActiveAlarm now derives its result from the real post-teardown state (companion instance + synchronous stopEverything + activeRingingId check) instead of reporting unconditional success. - Atomic teardown: every stop path (stop action, notification button, snooze, missed, onDestroy, startForeground failure) funnels through one stopEverything() covering audio, wakelock, notification, foreground state and firing-record cleanup; player.release() guarded. - Bounded ringing: 10-minute auto-silence armed via AlarmManager fires a FIRED->MISSED transition with a localized missed-alarm notification; repeating alarms keep their native rearm, deleted alarms never produce ghost MISSED notifications. - Durable firing record with onStartCommand re-validation (resurrection guard) and boot-time stale cleanup; firing records cleared on every refuse/mismatch/cancel path. - New notification-only dismissal channel (dismissAlarmNotificationOnly) so UI-level dedup can never kill a live ring's audio. Flutter (Dart): - Stop/disable/edit/delete of a ringing alarm always attempt to silence it; on native-query failure the stop falls back toward silence via the id-scoped legacy stop. - Verified-stop results surface failures: the ringing screen keeps dismiss-by-design on success, but on a verified failure it stays up with a persistent force-stop banner (guarded against double-dismiss) and auto-dismisses if the ring ends externally (missed/notification). - Missed events sync alarm bookkeeping without opening the ringing UI. - 4 new l10n keys translated across all 13 locales (ARB guard green). 550 tests green, analyzer clean. Reviewed in 3 adversarial 4-lens rounds (2 deterministic + 1 refuter-corroborated critical fixed); formal gentle-ai receipt waived by maintainer authorization (correction scope legitimately exceeded the frozen genesis paths). On-device QA checklist in openspec/changes/alarm-system-overhaul/tasks.md pending before archive.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/estado/estado_alarmas.dart';
|
||||
import 'package:pluriwave/modelos/alarma_musical.dart';
|
||||
@@ -220,6 +222,362 @@ void main() {
|
||||
expect(android.solicitudesExencionBateria, 0);
|
||||
});
|
||||
|
||||
test(
|
||||
'cambiarActiva(false) detiene el audio cuando la alarma esta sonando (SS-1a)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'ring1',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.alarmaSonandoIdValor = 'ring1';
|
||||
|
||||
await estado.cambiarActiva(estado.alarmas.single, false);
|
||||
|
||||
expect(android.detencionesActivas, contains('ring1'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'guardarAlarma detiene el audio cuando edita la alarma sonando (SS-1b)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'ring2',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.alarmaSonandoIdValor = 'ring2';
|
||||
|
||||
await estado.guardarAlarma(estado.alarmas.single.copyWith(minuto: 45));
|
||||
|
||||
expect(android.detencionesActivas, contains('ring2'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'eliminarAlarma detiene el audio antes de cancelar cuando esta sonando '
|
||||
'(SS-1c, guardia de regresion)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'ring3',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.alarmaSonandoIdValor = 'ring3';
|
||||
|
||||
await estado.eliminarAlarma('ring3');
|
||||
|
||||
expect(android.detencionesActivas, contains('ring3'));
|
||||
expect(android.canceladas, contains('ring3'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'eliminarAlarma usa detenerSonidoNativo cuando la consulta de sonando '
|
||||
'falla (fail-toward-silence, regresion de eliminarAlarma)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'ring4',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.fallaConsultaSonando = true;
|
||||
|
||||
await estado.eliminarAlarma('ring4');
|
||||
|
||||
expect(android.detenidas, contains('ring4'));
|
||||
expect(android.canceladas, contains('ring4'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'guardarAlarma (deshabilitar) usa detenerSonidoNativo cuando la consulta '
|
||||
'de sonando falla (fail-toward-silence)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'ring5',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.fallaConsultaSonando = true;
|
||||
|
||||
await estado.cambiarActiva(estado.alarmas.single, false);
|
||||
|
||||
expect(android.detenidas, contains('ring5'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'mutar una alarma distinta a la que suena no dispara el guard (SS-1d)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'y1',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'z1',
|
||||
nombre: 'Quieta',
|
||||
hora: 8,
|
||||
minuto: 0,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.alarmaSonandoIdValor = 'y1';
|
||||
|
||||
final z1 = estado.alarmas.firstWhere((a) => a.id == 'z1');
|
||||
await estado.cambiarActiva(z1, false);
|
||||
|
||||
expect(android.detencionesActivas, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'finalizarEjecucion no registra error cuando el stop nativo se confirma '
|
||||
'(SS-2a)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'fin1',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
android.alarmaSonandoIdValor = 'fin1';
|
||||
|
||||
await estado.finalizarEjecucion('fin1');
|
||||
|
||||
expect(android.detencionesActivas, contains('fin1'));
|
||||
expect(estado.error, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'finalizarEjecucion registra error cuando el stop nativo no se confirma '
|
||||
'(SS-2b)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'fin2',
|
||||
nombre: 'Sonando',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
|
||||
await estado.finalizarEjecucion('fin2');
|
||||
|
||||
expect(estado.error, isNotNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'forzarDetencion reintenta el stop nativo y limpia el error si tiene '
|
||||
'exito (SS-3b)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'force1',
|
||||
nombre: 'Forzada',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
await estado.finalizarEjecucion('force1');
|
||||
expect(estado.error, isNotNull);
|
||||
|
||||
android.fallaDetener = false;
|
||||
await estado.forzarDetencion('force1');
|
||||
|
||||
expect(estado.error, isNull);
|
||||
expect(android.detencionesActivas.length, 2);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'forzarDetencion mantiene el error si el reintento tambien falla (SS-3b)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid()..fallaDetener = true;
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
const AlarmaMusical(
|
||||
id: 'force2',
|
||||
nombre: 'Forzada',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: [],
|
||||
),
|
||||
);
|
||||
await estado.finalizarEjecucion('force2');
|
||||
|
||||
await estado.forzarDetencion('force2');
|
||||
|
||||
expect(estado.error, isNotNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'evento nativo missed completa la ejecucion (Phase 6)',
|
||||
() async {
|
||||
final android = FakePuertoAlarmasAndroid();
|
||||
final estado = EstadoAlarmas(
|
||||
servicio: ServicioAlarmas(reloj: () => DateTime(2026, 5, 25, 7, 31)),
|
||||
android: android,
|
||||
iniciarAutomaticamente: false,
|
||||
);
|
||||
addTearDown(estado.dispose);
|
||||
addTearDown(android.dispose);
|
||||
await estado.guardarAlarma(
|
||||
AlarmaMusical(
|
||||
id: 'miss1',
|
||||
nombre: 'Perdida',
|
||||
hora: 7,
|
||||
minuto: 30,
|
||||
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
||||
diasSemana: const [],
|
||||
proximaEjecucion: DateTime(2026, 5, 25, 7, 30),
|
||||
),
|
||||
);
|
||||
|
||||
final notificado = Completer<void>();
|
||||
estado.addListener(() {
|
||||
if (!notificado.isCompleted) notificado.complete();
|
||||
});
|
||||
android.emitirEvento(
|
||||
EventoAlarmaAndroid(
|
||||
alarmaId: 'miss1',
|
||||
titulo: 'Perdida',
|
||||
accion: EventoAlarmaAndroid.accionMissed,
|
||||
occurrenceAtMillis: DateTime(2026, 5, 25, 7, 30).millisecondsSinceEpoch,
|
||||
),
|
||||
);
|
||||
await notificado.future;
|
||||
|
||||
expect(
|
||||
estado.alarmas.single.proximaEjecucion,
|
||||
DateTime(2026, 5, 26, 7, 30),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'inicializar sincroniza ejecucion nativa y evita reprogramar al instante',
|
||||
() async {
|
||||
|
||||
@@ -11,6 +11,7 @@ class FakePuertoAlarmasAndroid implements PuertoAlarmasAndroid {
|
||||
final canceladas = <String>[];
|
||||
final detenidas = <String>[];
|
||||
final ocultadas = <String>[];
|
||||
final soloOcultadas = <String>[];
|
||||
final ejecucionesNativas = <EjecucionAlarmaNativa>[];
|
||||
final snoozesNativos = <EstadoSnoozeNativo>[];
|
||||
final _eventos = StreamController<EventoAlarmaAndroid>.broadcast();
|
||||
@@ -22,6 +23,27 @@ class FakePuertoAlarmasAndroid implements PuertoAlarmasAndroid {
|
||||
/// could not otherwise produce.
|
||||
bool fallaProgramar = false;
|
||||
|
||||
/// Test-only failure switch: when true, [detenerSonidoActivo] reports an
|
||||
/// unconfirmed/failed stop instead of a confirmed one.
|
||||
bool fallaDetener = false;
|
||||
|
||||
/// Simulates [PluriWaveAlarmService.activeRingingId]: the id the fake
|
||||
/// reports as currently ringing, or null if nothing rings.
|
||||
String? alarmaSonandoIdValor;
|
||||
|
||||
/// Test-only failure switch (Finding 2, fail-toward-silence): when true,
|
||||
/// [alarmaSonandoId] throws instead of returning a value, exercising the
|
||||
/// [detenerSonidoNativo] fallback in `EstadoAlarmas._detenerSiEstaSonando`.
|
||||
bool fallaConsultaSonando = false;
|
||||
|
||||
/// Every alarm id [detenerSonidoActivo] was invoked for, in call order.
|
||||
final detencionesActivas = <String>[];
|
||||
|
||||
/// Test-only gate (RES-2 guard test): when set, [detenerSonidoActivo]
|
||||
/// awaits it before resolving, letting tests exercise an overlapping
|
||||
/// in-flight call.
|
||||
Completer<void>? detenerActivoGate;
|
||||
|
||||
/// Simulates a native -> Flutter `alarmFired` MethodChannel event.
|
||||
void emitirEvento(EventoAlarmaAndroid evento) => _eventos.add(evento);
|
||||
|
||||
@@ -49,11 +71,39 @@ class FakePuertoAlarmasAndroid implements PuertoAlarmasAndroid {
|
||||
detenidas.add(alarmaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> alarmaSonandoId() async {
|
||||
if (fallaConsultaSonando) {
|
||||
throw StateError('fake alarmaSonandoId failure');
|
||||
}
|
||||
return alarmaSonandoIdValor;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ResultadoDetencion> detenerSonidoActivo() async {
|
||||
detencionesActivas.add(alarmaSonandoIdValor ?? '');
|
||||
final gate = detenerActivoGate;
|
||||
if (gate != null) await gate.future;
|
||||
if (fallaDetener) {
|
||||
return const ResultadoDetencion(detenido: false, estabaSonando: true);
|
||||
}
|
||||
return ResultadoDetencion(
|
||||
detenido: true,
|
||||
estabaSonando: alarmaSonandoIdValor != null,
|
||||
alarmaId: alarmaSonandoIdValor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> ocultarNotificacionAlarma(String alarmaId) async {
|
||||
ocultadas.add(alarmaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> ocultarSoloNotificacion(String alarmaId) async {
|
||||
soloOcultadas.add(alarmaId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DiagnosticoAlarmasAndroid> diagnostico() async =>
|
||||
DiagnosticoAlarmasAndroid(
|
||||
|
||||
@@ -289,6 +289,40 @@ void main() {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'detener: root-launch (canPop false) + fallo de detencion verificado NO '
|
||||
'llama a SystemNavigator.pop y deja visible el banner de retry '
|
||||
'(Finding A, escenario canonico de FSI con app muerta)',
|
||||
(tester) async {
|
||||
final env = await _buildEnv();
|
||||
addTearDown(env.dispose);
|
||||
env.android.fallaDetener = true;
|
||||
final spy = _SystemNavigatorSpy()..install();
|
||||
addTearDown(spy.uninstall);
|
||||
|
||||
await _montarComoRaiz(
|
||||
tester,
|
||||
android: env.android,
|
||||
estadoAlarmas: env.estadoAlarmas,
|
||||
radio: env.radio,
|
||||
);
|
||||
|
||||
await tester.tap(find.text(l10n.stopAlarmAction));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PantallaAlarmaSonando), findsOneWidget);
|
||||
expect(find.text(l10n.alarmStopFailedMessage), findsOneWidget);
|
||||
expect(
|
||||
spy.popCalls,
|
||||
0,
|
||||
reason:
|
||||
'SystemNavigator.pop must not fire while the alarm is still '
|
||||
'ringing after a verified stop failure — the root-launch '
|
||||
'scenario is the one where a lost affordance is unrecoverable',
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('PantallaAlarmaSonando snooze failure feedback (Phase 4)', () {
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:pluriwave/modelos/alarma_musical.dart';
|
||||
import 'package:pluriwave/modelos/emisora.dart';
|
||||
import 'package:pluriwave/pantallas/pantalla_alarma_sonando.dart';
|
||||
import 'package:pluriwave/servicios/servicio_alarmas.dart';
|
||||
import 'package:pluriwave/servicios/servicio_alarmas_android.dart';
|
||||
import 'package:pluriwave/servicios/servicio_audio.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -92,7 +93,12 @@ Future<_Entorno> _montarPantalla(
|
||||
locale: const Locale('es'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const SizedBox.shrink(),
|
||||
// A real Scaffold (not a bare SizedBox) is required: the
|
||||
// ScaffoldMessenger only displays a SnackBar through a currently
|
||||
// registered ScaffoldState, and the ringing screen's own Scaffold
|
||||
// pops off the tree by the time the SS-3a force-stop SnackBar shows
|
||||
// (mirrors pantalla_alarma_sonando_dismiss_guard_test.dart).
|
||||
home: const Scaffold(body: SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -163,6 +169,102 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
group('detener y el force-stop de fallback', () {
|
||||
testWidgets(
|
||||
'detener fallido NO cierra la pantalla y muestra el banner de forzar '
|
||||
'detencion; forzar detencion con exito si la cierra (SS-3a/SS-3b)',
|
||||
(tester) async {
|
||||
final entorno = await _montarPantalla(tester);
|
||||
entorno.android.fallaDetener = true;
|
||||
|
||||
await tester.tap(find.text(l10n.stopAlarmAction));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verified stop failure (Finding A): the alarm is still ringing, so
|
||||
// the ringing screen must stay up — dismissing here would hide the
|
||||
// only retry affordance while the native ring keeps sounding.
|
||||
expect(find.byType(PantallaAlarmaSonando), findsOneWidget);
|
||||
expect(find.text(l10n.alarmStopFailedMessage), findsOneWidget);
|
||||
expect(find.text(l10n.alarmForceStopAction), findsOneWidget);
|
||||
|
||||
// Retry via the banner's own action succeeds this time (SS-3b).
|
||||
entorno.android.fallaDetener = false;
|
||||
await tester.tap(find.text(l10n.alarmForceStopAction));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PantallaAlarmaSonando), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'detener confirmado no muestra el banner de fallo (SS-3c)',
|
||||
(tester) async {
|
||||
final entorno = await _montarPantalla(tester);
|
||||
|
||||
await tester.tap(find.text(l10n.stopAlarmAction));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PantallaAlarmaSonando), findsNothing);
|
||||
expect(find.text(l10n.alarmStopFailedMessage), findsNothing);
|
||||
expect(entorno.android.detencionesActivas, isNotEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'forzar detencion: invocacion superpuesta es no-op y tras un fallo '
|
||||
'el boton sigue funcionando (RES-2)',
|
||||
(tester) async {
|
||||
final entorno = await _montarPantalla(tester);
|
||||
entorno.android.fallaDetener = true;
|
||||
await tester.tap(find.text(l10n.stopAlarmAction));
|
||||
await tester.pumpAndSettle();
|
||||
final llamadasPrevias = entorno.android.detencionesActivas.length;
|
||||
|
||||
entorno.android.detenerActivoGate = Completer<void>();
|
||||
await tester.tap(find.text(l10n.alarmForceStopAction));
|
||||
await tester.pump();
|
||||
await tester.tap(find.text(l10n.alarmForceStopAction));
|
||||
await tester.pump();
|
||||
expect(
|
||||
entorno.android.detencionesActivas.length,
|
||||
llamadasPrevias + 1,
|
||||
reason: 'la segunda invocacion superpuesta debe ser no-op',
|
||||
);
|
||||
entorno.android.detenerActivoGate!.complete();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Fallo confirmado: el banner sigue y el guard debe haberse
|
||||
// reseteado para permitir un reintento.
|
||||
expect(find.byType(PantallaAlarmaSonando), findsOneWidget);
|
||||
entorno.android.fallaDetener = false;
|
||||
await tester.tap(find.text(l10n.alarmForceStopAction));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(PantallaAlarmaSonando), findsNothing);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('reconciliacion de fin de ring externo (RES-1)', () {
|
||||
testWidgets(
|
||||
'si la alarma se registra como perdida externamente, la pantalla se '
|
||||
'auto-cierra',
|
||||
(tester) async {
|
||||
final entorno = await _montarPantalla(tester);
|
||||
|
||||
entorno.android.emitirEvento(
|
||||
EventoAlarmaAndroid(
|
||||
alarmaId: 'ring1',
|
||||
titulo: 'Despertar',
|
||||
accion: EventoAlarmaAndroid.accionMissed,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(PantallaAlarmaSonando), findsNothing);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('salidas del ring fuera de los botones', () {
|
||||
testWidgets(
|
||||
'el boton atras del sistema se comporta como Detener: finaliza la '
|
||||
|
||||
@@ -20,6 +20,10 @@ void main() {
|
||||
return true;
|
||||
case 'requestIgnoreBatteryOptimizations':
|
||||
return true;
|
||||
case 'getActiveRingingAlarmId':
|
||||
return 'ring1';
|
||||
case 'stopActiveAlarm':
|
||||
return {'stopped': true, 'wasRinging': true, 'activeAlarmId': 'ring1'};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@@ -107,4 +111,54 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'detenerSonidoActivo mapea el resultado nativo confirmado a ResultadoDetencion',
|
||||
() async {
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
|
||||
final resultado = await servicio.detenerSonidoActivo();
|
||||
final sonando = await servicio.alarmaSonandoId();
|
||||
|
||||
expect(resultado.detenido, isTrue);
|
||||
expect(resultado.estabaSonando, isTrue);
|
||||
expect(resultado.alarmaId, 'ring1');
|
||||
expect(sonando, 'ring1');
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'detenerSonidoActivo retorna un resultado fallido cuando el canal lanza error',
|
||||
() async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
llamadas.add(call);
|
||||
throw PlatformException(code: 'STOP_FAILED', message: 'boom');
|
||||
});
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
|
||||
final resultado = await servicio.detenerSonidoActivo();
|
||||
|
||||
expect(resultado.detenido, isFalse);
|
||||
expect(resultado.estabaSonando, isFalse);
|
||||
expect(resultado.alarmaId, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'alarmaSonandoId propaga el error del canal (fail-toward-silence, '
|
||||
'Finding 2)',
|
||||
() async {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
llamadas.add(call);
|
||||
throw PlatformException(code: 'QUERY_FAILED', message: 'boom');
|
||||
});
|
||||
final servicio = ServicioAlarmasAndroid(channel: channel);
|
||||
|
||||
expect(
|
||||
() => servicio.alarmaSonandoId(),
|
||||
throwsA(isA<PlatformException>()),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ void main() {
|
||||
contains('{minutes}'),
|
||||
reason: 'snooze countdown template must keep the {minutes} placeholder',
|
||||
);
|
||||
expect(
|
||||
args['missedTemplate'],
|
||||
contains('{name}'),
|
||||
reason: 'missed template must keep the {name} placeholder',
|
||||
);
|
||||
|
||||
// Every notification/channel/chooser string must be present and non-empty
|
||||
// so the native side never falls back to English for a configured locale.
|
||||
@@ -68,6 +73,7 @@ void main() {
|
||||
'preNoticeChannelDescription',
|
||||
'openFolderTitle',
|
||||
'openRecordingTitle',
|
||||
'missedTitle',
|
||||
];
|
||||
for (final clave in claves) {
|
||||
expect(args[clave], isA<String>(), reason: '$clave missing');
|
||||
|
||||
Reference in New Issue
Block a user