76 lines
2.3 KiB
Dart
76 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/estado/estado_navegacion.dart';
|
|
|
|
/// Design ADR-8: EstadoNavegacionRaiz is the single source of truth for
|
|
/// which of the 5 root tabs is active. Switching roots never pushes a
|
|
/// route — this is a plain ChangeNotifier update.
|
|
void main() {
|
|
group('RaizPluriWave', () {
|
|
test('declaration order is the tab order (0-indexed)', () {
|
|
expect(RaizPluriWave.escuchar.index, 0);
|
|
expect(RaizPluriWave.buscar.index, 1);
|
|
expect(RaizPluriWave.favoritos.index, 2);
|
|
expect(RaizPluriWave.alarmas.index, 3);
|
|
expect(RaizPluriWave.ajustes.index, 4);
|
|
expect(RaizPluriWave.values.length, 5);
|
|
});
|
|
});
|
|
|
|
group('EstadoNavegacionRaiz', () {
|
|
test('starts on escuchar', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
expect(estado.actual, RaizPluriWave.escuchar);
|
|
expect(estado.indice, 0);
|
|
});
|
|
|
|
test('irA transitions to the requested root', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
|
|
estado.irA(RaizPluriWave.favoritos);
|
|
|
|
expect(estado.actual, RaizPluriWave.favoritos);
|
|
});
|
|
|
|
test('indice mirrors the enum declaration order after a transition', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
|
|
estado.irA(RaizPluriWave.alarmas);
|
|
|
|
expect(estado.indice, RaizPluriWave.alarmas.index);
|
|
expect(estado.indice, 3);
|
|
});
|
|
|
|
test('irA notifies listeners on a real transition', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
var notifyCount = 0;
|
|
estado.addListener(() => notifyCount++);
|
|
|
|
estado.irA(RaizPluriWave.buscar);
|
|
|
|
expect(notifyCount, 1);
|
|
});
|
|
|
|
test('irA no-ops and does not notify when already on that root', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
var notifyCount = 0;
|
|
estado.addListener(() => notifyCount++);
|
|
|
|
estado.irA(RaizPluriWave.escuchar); // already the starting root
|
|
|
|
expect(notifyCount, 0);
|
|
expect(estado.actual, RaizPluriWave.escuchar);
|
|
});
|
|
|
|
test('a repeated irA to the same non-initial root only notifies once', () {
|
|
final estado = EstadoNavegacionRaiz();
|
|
estado.irA(RaizPluriWave.ajustes);
|
|
var notifyCount = 0;
|
|
estado.addListener(() => notifyCount++);
|
|
|
|
estado.irA(RaizPluriWave.ajustes);
|
|
|
|
expect(notifyCount, 0);
|
|
});
|
|
});
|
|
}
|