test(alarmas): anchor the vacation pill test on a relative future range
The test hardcoded 4-18 August 2026, which was in the future when it was written and is now in the past. The pill only renders for the active or next range, so the assertion started failing purely because the calendar moved on — the production code was never wrong. Anchor the range on next month (days 4-18, so it never straddles a month boundary) and assert against rangoFechasCorto, the same pure formatter the widget uses, so the test checks that the pill is rendered rather than restating the formatter's own output.
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.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/modelos/emisora.dart';
|
||||
@@ -137,16 +138,29 @@ void main() {
|
||||
) async {
|
||||
final estado = crearEstado();
|
||||
addTearDown(estado.dispose);
|
||||
// The pill only renders for the ACTIVE or NEXT range
|
||||
// (`EstadoAlarmas.vacacionesProximas` keeps `inicioDia.isAfter(hoy)`), so
|
||||
// the range has to be in the future RELATIVE TO THE RUN. Hardcoded
|
||||
// calendar dates silently rot into the past and turn this into a
|
||||
// date-dependent failure; anchor on next month instead, days 4-18 so the
|
||||
// range never straddles a month boundary and the label stays "d–d MON".
|
||||
final ahora = DateTime.now();
|
||||
final mesSiguiente = DateTime(ahora.year, ahora.month + 1);
|
||||
final inicio = DateTime(mesSiguiente.year, mesSiguiente.month, 4);
|
||||
final fin = DateTime(mesSiguiente.year, mesSiguiente.month, 18);
|
||||
await estado.crearRangoVacaciones(
|
||||
estado.servicio.crearRangoVacaciones(
|
||||
inicio: DateTime(2026, 8, 4),
|
||||
fin: DateTime(2026, 8, 18),
|
||||
inicio: inicio,
|
||||
fin: fin,
|
||||
nombre: 'Summer',
|
||||
),
|
||||
);
|
||||
await montar(tester, estadoAlarmas: estado);
|
||||
|
||||
expect(find.text('4–18 AUG'), findsOneWidget);
|
||||
// Assert against the same pure formatter the widget uses, so this stays
|
||||
// a check that the pill IS rendered in the right shape rather than a
|
||||
// duplicate of the formatter's own logic.
|
||||
expect(find.text(rangoFechasCorto('en', inicio, fin)), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user