Centralize every native-side user-facing string in a single
AlarmNotificationStrings store written by Flutter via a new
setNotificationStrings MethodChannel whenever the app locale changes,
and read at notification/channel build time (with English fallbacks)
even when the engine is dead. This replaces the hardcoded Spanish text
in the ringing notification ("Alarma PluriWave", "Posponer", "Detener"),
the pre-notice notification ("Posponer", "Omitir esta vez"), both
notification channels (names + descriptions) and the file-action
choosers ("Abrir carpeta", "Abrir grabación").
The per-alarm preNoticeTemplate/snoozeCountdown template+label args are
dropped from scheduleAlarm and the persisted spec and folded into the
shared store, so a locale change now also relocalizes already-scheduled
alarms. Channels are re-created on each use so their name/description
refresh after a language switch.
Adds alarmRingingNotificationTitle, alarmFire/PreNoticeChannelName,
alarmFire/PreNoticeChannelDescription and openFolder/openRecording
chooser keys across all 13 locales (reusing snoozeAction, stopAlarmAction,
skipNextAction, snoozeAgainAction). Rewrites the template test around
setNotificationStrings. Kotlin is static-reviewed only; no Android build
environment available here.
103 lines
3.3 KiB
Dart
103 lines
3.3 KiB
Dart
import 'dart:ui' show Locale;
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/l10n/gen/app_localizations.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(
|
|
'configurarLocalizaciones pushes localized notification strings with {minutes} templates',
|
|
() async {
|
|
final servicio = ServicioAlarmasAndroid(channel: channel);
|
|
final l10n = lookupAppLocalizations(const Locale('es'));
|
|
|
|
servicio.configurarLocalizaciones(l10n);
|
|
// configurarLocalizaciones fires setNotificationStrings as unawaited; let
|
|
// the microtask/event queue drain so the MethodChannel call is recorded.
|
|
await Future<void>.delayed(Duration.zero);
|
|
|
|
final llamada = llamadas.singleWhere(
|
|
(c) => c.method == 'setNotificationStrings',
|
|
);
|
|
final args = llamada.arguments as Map<Object?, Object?>;
|
|
|
|
expect(
|
|
args['preNoticeTemplate'],
|
|
contains('{minutes}'),
|
|
reason: 'pre-notice template must keep the {minutes} placeholder',
|
|
);
|
|
expect(
|
|
args['snoozeCountdownTemplate'],
|
|
contains('{minutes}'),
|
|
reason: 'snooze countdown template must keep the {minutes} 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.
|
|
const claves = [
|
|
'ringTitle',
|
|
'snoozeLabel',
|
|
'stopLabel',
|
|
'skipLabel',
|
|
'snoozeAgainLabel',
|
|
'fireChannelName',
|
|
'fireChannelDescription',
|
|
'preNoticeChannelName',
|
|
'preNoticeChannelDescription',
|
|
'openFolderTitle',
|
|
'openRecordingTitle',
|
|
];
|
|
for (final clave in claves) {
|
|
expect(args[clave], isA<String>(), reason: '$clave missing');
|
|
expect(
|
|
(args[clave] as String).isNotEmpty,
|
|
isTrue,
|
|
reason: '$clave is empty',
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
test('scheduleAlarm no longer carries notification string templates', () async {
|
|
final servicio = ServicioAlarmasAndroid(channel: channel);
|
|
final alarma = AlarmaMusical(
|
|
id: 'no-template',
|
|
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?>;
|
|
expect(args.containsKey('preNoticeTemplate'), isFalse);
|
|
expect(args.containsKey('snoozeCountdownTemplate'), isFalse);
|
|
});
|
|
}
|