PantallaAlarmaSonando no longer owns any audio orchestration (fallback player, dB ramp, native handoff confirm, media-volume override/restore): it only calls EstadoAlarmas.finalizarEjecucion/posponerAlarma from Stop/Snooze/back, keeping the single-exit guard, PopScope back=Stop and dismiss semantics intact. The status line now reads directly from the alarm's static config (station name or a neutral label) instead of a live playback/handoff state. PuertoAlarmasAndroid drops confirmarAudioFlutter, forzarVolumenMediaParaAlarma and restaurarVolumenMedia, and app.dart no longer pre-starts a station before pushing the ring screen. This is the Dart half of moving to a single native ring-audio owner (WU1 of 2); the Kotlin service rebuild lands next and keeps this intermediate state shippable with no double audio.
111 lines
3.4 KiB
Dart
111 lines
3.4 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/modelos/alarma_musical.dart';
|
|
import 'package:pluriwave/modelos/emisora.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);
|
|
switch (call.method) {
|
|
case 'scheduleAlarm':
|
|
return true;
|
|
case 'requestIgnoreBatteryOptimizations':
|
|
return true;
|
|
}
|
|
return null;
|
|
});
|
|
});
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(channel, null);
|
|
});
|
|
|
|
test(
|
|
'programar incluye emisora de respaldo y fade en el payload nativo',
|
|
() async {
|
|
final servicio = ServicioAlarmasAndroid(channel: channel);
|
|
final alarma = AlarmaMusical(
|
|
id: 'a1',
|
|
nombre: 'Con respaldo',
|
|
hora: 7,
|
|
minuto: 30,
|
|
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
|
diasSemana: const [],
|
|
proximaEjecucion: DateTime(2099, 1, 1, 7, 30),
|
|
emisora: const Emisora(
|
|
uuid: 'uuid-principal',
|
|
nombre: 'Principal FM',
|
|
url: 'https://principal.example/stream',
|
|
),
|
|
emisoraFallback: const Emisora(
|
|
uuid: 'uuid-respaldo',
|
|
nombre: 'Respaldo FM',
|
|
url: 'https://respaldo.example/stream',
|
|
),
|
|
fadeInSegundos: 12,
|
|
);
|
|
|
|
await servicio.programar(alarma);
|
|
|
|
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
|
final args = llamada.arguments as Map<Object?, Object?>;
|
|
expect(args['fallbackStationName'], 'Respaldo FM');
|
|
expect(args['fallbackStationUrl'], 'https://respaldo.example/stream');
|
|
expect(args['fadeInSegundos'], 12);
|
|
expect(args['fallbackSound'], SonidoInternoAlarma.amanecer.name);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'programar sin emisora de respaldo envia campos de respaldo nulos',
|
|
() async {
|
|
final servicio = ServicioAlarmasAndroid(channel: channel);
|
|
final alarma = AlarmaMusical(
|
|
id: 'a2',
|
|
nombre: 'Sin respaldo',
|
|
hora: 8,
|
|
minuto: 0,
|
|
tipoProgramacion: TipoProgramacionAlarma.diaria,
|
|
diasSemana: const [],
|
|
proximaEjecucion: DateTime(2099, 1, 1, 8, 0),
|
|
);
|
|
|
|
await servicio.programar(alarma);
|
|
|
|
final llamada = llamadas.singleWhere((c) => c.method == 'scheduleAlarm');
|
|
final args = llamada.arguments as Map<Object?, Object?>;
|
|
expect(args.containsKey('fallbackStationName'), isTrue);
|
|
expect(args['fallbackStationName'], isNull);
|
|
expect(args.containsKey('fallbackStationUrl'), isTrue);
|
|
expect(args['fallbackStationUrl'], isNull);
|
|
expect(args['fadeInSegundos'], 0);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'solicitarExencionBateria invoca requestIgnoreBatteryOptimizations',
|
|
() async {
|
|
final servicio = ServicioAlarmasAndroid(channel: channel);
|
|
|
|
final abierto = await servicio.solicitarExencionBateria();
|
|
|
|
expect(abierto, isTrue);
|
|
expect(
|
|
llamadas.map((c) => c.method),
|
|
contains('requestIgnoreBatteryOptimizations'),
|
|
);
|
|
},
|
|
);
|
|
|
|
}
|