feat(alarmas): rewrite alarm editor with inline time widget

Replace the native showTimePicker dialog in the alarm editor sheet with
a giant inline HH:MM editor (drag/tap to adjust, wraps at 23:59-00:00).
Weekday circles now render unconditionally (disabled outside weekly
mode) instead of being gated behind an `if`.

The date field, fallback-station picker, and sound dropdown are not
dropped: per resolution 3 they move into a collapsed "Advanced" section
so the mockup's weekday-circles-only layout does not lose capability.
Volume/fade-in sliders get a cosmetic type-scale restyle only.

size:exception: 993 changed lines (891+/102-) against the 500-650
forecast - lib/ production code alone is 429 lines, within band; new
test files and 13 regenerated l10n/gen files account for the rest, the
same pattern every prior work unit in this branch has hit.
This commit is contained in:
2026-07-29 11:43:15 +02:00
parent 332c2192cd
commit a2121d84bd
22 changed files with 935 additions and 115 deletions
@@ -242,6 +242,15 @@ void main() {
(tester) async {
await _abrirEditor(tester);
// WU10 correction: the fallback-station field moved into the
// collapsed "Advanced" section (native-alarms delta — Alarm Editor
// Preserves Date, Fallback Station, and Sound Fields). It must be
// expanded first — a collapsed `ExpansionTile` does not build its
// children, so `find.byKey` would otherwise find nothing.
await tester.ensureVisible(find.text(l10n.alarmAdvancedSectionTitle));
await tester.tap(find.text(l10n.alarmAdvancedSectionTitle));
await tester.pumpAndSettle();
await tester.ensureVisible(
find.byKey(const ValueKey('alarm-fallback-station-field')),
);
@@ -1,7 +1,19 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:pluriwave/estado/estado_alarmas.dart';
import 'package:pluriwave/estado/estado_radio.dart';
import 'package:pluriwave/l10n/formato_fechas.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/modelos/alarma_musical.dart';
import 'package:pluriwave/pantallas/pantalla_alarmas.dart';
import 'package:pluriwave/servicios/servicio_alarmas.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../helpers/fakes.dart';
import '../helpers/fakes_alarmas.dart';
/// S5-R4: short dates must follow the active locale, not a hardcoded
/// DD/MM/YYYY pattern.
@@ -24,4 +36,181 @@ void main() {
DateFormat.yMd('es').format(fecha),
);
});
group('WU10 — la seccion Avanzada del editor conserva fecha, respaldo y '
'sonido', () {
final l10n = lookupAppLocalizations(const Locale('es'));
setUp(() {
SharedPreferences.setMockInitialValues({});
});
Future<EstadoAlarmas> abrirEditorNuevo(WidgetTester tester) async {
tester.view.physicalSize = const Size(1440, 3200);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final favoritos = FakeServicioFavoritos();
await favoritos.agregar(emisoraDemo(uuid: 'gamma', nombre: 'Gamma FM'));
final radio = EstadoRadio(
audio: FakeServicioAudio(),
favoritos: favoritos,
radio: FakeServicioRadio(),
servicioEcualizador: FakeServicioEcualizador(),
servicioGrabacion: FakeServicioGrabacionRadioInactiva(),
iniciarAutomaticamente: false,
);
addTearDown(radio.dispose);
await radio.cargarFavoritos();
final android = FakePuertoAlarmasAndroid();
final estadoAlarmas = EstadoAlarmas(
servicio: ServicioAlarmas(reloj: DateTime.now),
android: android,
iniciarAutomaticamente: false,
);
addTearDown(estadoAlarmas.dispose);
addTearDown(android.dispose);
await tester.pumpWidget(
MultiProvider(
providers: [
ChangeNotifierProvider<EstadoRadio>.value(value: radio),
ChangeNotifierProvider<EstadoAlarmas>.value(value: estadoAlarmas),
],
child: MaterialApp(
locale: const Locale('es'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: const Scaffold(body: PantallaAlarmas()),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.text(l10n.createAlarmAction));
await tester.pumpAndSettle();
return estadoAlarmas;
}
Future<void> expandirAvanzado(WidgetTester tester) async {
await tester.ensureVisible(find.text(l10n.alarmAdvancedSectionTitle));
await tester.tap(find.text(l10n.alarmAdvancedSectionTitle));
await tester.pumpAndSettle();
}
testWidgets(
'los circulos de dia de la semana son siempre visibles, incluso '
'cuando el tipo es Una vez (por defecto en una alarma nueva)',
(tester) async {
await abrirEditorNuevo(tester);
expect(find.text(l10n.weekdayShortMonday), findsOneWidget);
expect(find.text(l10n.weekdayShortSunday), findsOneWidget);
},
);
testWidgets(
'permite crear una alarma de fecha unica desde la seccion Avanzada '
'(colapsada por defecto)',
(tester) async {
final estadoAlarmas = await abrirEditorNuevo(tester);
// A brand-new alarm already defaults to "one time" — the date field
// is reachable as soon as Advanced is expanded, no mode switch
// needed first.
await expandirAvanzado(tester);
await tester.ensureVisible(find.text(l10n.dateField));
await tester.tap(find.text(l10n.dateField));
await tester.pumpAndSettle();
final okLabel =
MaterialLocalizations.of(
tester.element(find.text(l10n.dateField)),
).okButtonLabel;
await tester.tap(find.text(okLabel));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text(l10n.saveAlarmAction));
await tester.tap(find.text(l10n.saveAlarmAction));
await tester.pumpAndSettle();
final alarma = estadoAlarmas.alarmas.single;
expect(alarma.tipoProgramacion, TipoProgramacionAlarma.unica);
expect(alarma.fechaUnica, isNotNull);
expect(alarma.diasSemana, isEmpty);
},
);
testWidgets(
'el selector de emisora de respaldo sigue alcanzable desde Avanzado '
'y persiste (S2-R9)',
(tester) async {
final estadoAlarmas = await abrirEditorNuevo(tester);
await expandirAvanzado(tester);
await tester.ensureVisible(
find.byKey(const ValueKey('alarm-fallback-station-field')),
);
await tester.tap(
find.byKey(const ValueKey('alarm-fallback-station-field')),
);
await tester.pumpAndSettle();
// Scoped to the just-opened picker sheet's list: the primary
// station field auto-selects the sole registered favorite too
// (`EstadoRadio.emisoraPreferida` falls back to the first
// favorite), so an unscoped `find.text('Gamma FM')` would match
// twice — once there, once in this sheet.
final lista = find.byType(ListView).last;
expect(
find.descendant(of: lista, matching: find.text('Gamma FM')),
findsOneWidget,
);
await tester.tap(
find.descendant(of: lista, matching: find.text('Gamma FM')),
);
await tester.pumpAndSettle();
await tester.ensureVisible(find.text(l10n.saveAlarmAction));
await tester.tap(find.text(l10n.saveAlarmAction));
await tester.pumpAndSettle();
final alarma = estadoAlarmas.alarmas.single;
expect(alarma.emisoraFallback?.nombre, 'Gamma FM');
},
);
testWidgets(
'el dropdown de sonido interno sigue alcanzable desde Avanzado y '
'persiste',
(tester) async {
final estadoAlarmas = await abrirEditorNuevo(tester);
await expandirAvanzado(tester);
await tester.ensureVisible(
find.byType(DropdownButtonFormField<SonidoInternoAlarma>),
);
await tester.tap(
find.byType(DropdownButtonFormField<SonidoInternoAlarma>),
);
await tester.pumpAndSettle();
await tester.tap(find.text(l10n.soundSoftBell).last);
await tester.pumpAndSettle();
await tester.ensureVisible(find.text(l10n.saveAlarmAction));
await tester.tap(find.text(l10n.saveAlarmAction));
await tester.pumpAndSettle();
final alarma = estadoAlarmas.alarmas.single;
expect(alarma.sonidoInterno, SonidoInternoAlarma.campanaSuave);
},
);
});
}
+168
View File
@@ -0,0 +1,168 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/widgets/editor_hora_inline.dart';
/// WU10: standalone tests for the inline HH:MM editor, independent of
/// `_EditorAlarmaSheet` (the sheet only wires `value`/`onChanged`).
Future<void> _montar(
WidgetTester tester, {
required TimeOfDay inicial,
ValueChanged<TimeOfDay>? onChanged,
}) async {
var valor = inicial;
await tester.pumpWidget(
MaterialApp(
locale: const Locale('es'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: StatefulBuilder(
builder: (context, setState) {
return EditorHoraInline(
value: valor,
onChanged: (nuevo) {
setState(() => valor = nuevo);
onChanged?.call(nuevo);
},
);
},
),
),
),
);
}
const _keyHora = ValueKey('editor-hora-inline-hora');
const _keyMinuto = ValueKey('editor-hora-inline-minuto');
void main() {
testWidgets('muestra la hora inicial formateada HH:MM', (tester) async {
await _montar(tester, inicial: const TimeOfDay(hour: 7, minute: 5));
expect(find.text('07'), findsOneWidget);
expect(find.text('05'), findsOneWidget);
expect(find.text(':'), findsOneWidget);
});
testWidgets('tocar el segmento de hora incrementa solo la hora', (
tester,
) async {
TimeOfDay? recibido;
await _montar(
tester,
inicial: const TimeOfDay(hour: 10, minute: 30),
onChanged: (nuevo) => recibido = nuevo,
);
await tester.tap(find.byKey(_keyHora));
await tester.pump();
expect(recibido, const TimeOfDay(hour: 11, minute: 30));
expect(find.text('11'), findsOneWidget);
expect(find.text('30'), findsOneWidget);
});
testWidgets('tocar el segmento de minuto incrementa solo el minuto', (
tester,
) async {
TimeOfDay? recibido;
await _montar(
tester,
inicial: const TimeOfDay(hour: 10, minute: 30),
onChanged: (nuevo) => recibido = nuevo,
);
await tester.tap(find.byKey(_keyMinuto));
await tester.pump();
expect(recibido, const TimeOfDay(hour: 10, minute: 31));
});
testWidgets(
'incrementar el minuto en 23:59 envuelve a 00:00 (hora y minuto)',
(tester) async {
TimeOfDay? recibido;
await _montar(
tester,
inicial: const TimeOfDay(hour: 23, minute: 59),
onChanged: (nuevo) => recibido = nuevo,
);
await tester.tap(find.byKey(_keyMinuto));
await tester.pump();
expect(recibido, const TimeOfDay(hour: 0, minute: 0));
},
);
testWidgets('incrementar la hora en 23 envuelve a 0 sin tocar el minuto', (
tester,
) async {
TimeOfDay? recibido;
await _montar(
tester,
inicial: const TimeOfDay(hour: 23, minute: 45),
onChanged: (nuevo) => recibido = nuevo,
);
await tester.tap(find.byKey(_keyHora));
await tester.pump();
expect(recibido, const TimeOfDay(hour: 0, minute: 45));
});
testWidgets(
'arrastrar hacia arriba en el minuto lo incrementa; hacia abajo lo '
'decrementa',
(tester) async {
TimeOfDay? recibido;
await _montar(
tester,
inicial: const TimeOfDay(hour: 10, minute: 30),
onChanged: (nuevo) => recibido = nuevo,
);
await tester.drag(find.byKey(_keyMinuto), const Offset(0, -96));
await tester.pump();
expect(recibido, isNotNull);
expect(recibido!.hour, 10);
expect(recibido!.minute, greaterThan(30));
final minutoTrasSubir = recibido!.minute;
await tester.drag(find.byKey(_keyMinuto), Offset(0, 96));
await tester.pump();
expect(recibido!.minute, lessThan(minutoTrasSubir));
},
);
testWidgets('expone acciones de accesibilidad de incrementar/decrementar con '
'etiqueta y valor', (tester) async {
final semantics = tester.ensureSemantics();
final l10n = await AppLocalizations.delegate.load(const Locale('es'));
await _montar(tester, inicial: const TimeOfDay(hour: 6, minute: 8));
expect(
tester.getSemantics(find.byKey(_keyHora)),
matchesSemantics(
label: l10n.alarmInlineHourLabel,
value: '06',
hasIncreaseAction: true,
hasDecreaseAction: true,
hasTapAction: true,
),
);
expect(
tester.getSemantics(find.byKey(_keyMinuto)),
matchesSemantics(
label: l10n.alarmInlineMinuteLabel,
value: '08',
hasIncreaseAction: true,
hasDecreaseAction: true,
hasTapAction: true,
),
);
semantics.dispose();
});
}