feat(eq): restyle equalizer screen and add custom presets

Restyle the Ecualizador settings screen to the new visual language while
keeping the equalizer at 5 bands (spike-resolved, Engram id 2498 - band
count is device-reported via just_audio's AndroidEqualizer, not app-chosen;
the approved mockup's 7 sliders would silently no-op on typical hardware).

- Restyle EcualizadorWidget in place: strip its internal title + preset
  chip row (the pushed screen's header now carries the title), add a
  habilitado parameter that greys/disables every slider when EQ is off.
  Widen PresetsEcualizadorWidget additively (personalizados param) so
  custom presets can join the chip row without a second implementation.
- Add servicio_presets_personalizados.dart (new file, own SharedPreferences
  key eq_custom_presets_v1) for custom EQ preset persistence - kept out of
  servicio_ecualizador.dart, which has an empty-git-diff success criterion
  for this change. preset_ecualizador.dart is unchanged: a custom preset is
  just a PresetEcualizador with a user-supplied name.
- Extend EstadoEcualizador with presetsPersonalizados,
  guardarPresetPersonalizado (validates non-empty name),
  eliminarPresetPersonalizado. The load is a new explicit
  cargarPresetsPersonalizados(), deliberately NOT folded into
  cargarPersistido(): that method is exercised ~30 times by
  estado_ecualizador_test.dart (protected, must stay unmodified) via Fakes
  only, with no SharedPreferences awareness in that file.
- Build out the Ecualizador screen body: base-vs-per-station explainer
  banner, a "Salida activa" row surfaced on the main screen (previously
  Advanced-only), an "Emisoras con ajuste propio" drill-down sourced from
  the existing presetsPorEmisora map, and a "Guardar como preset" action.

New coverage lives in new files rather than touching the three protected
EQ test files: ecualizador_widget_test.dart (component-level, did not
exist before this commit), servicio_presets_personalizados_test.dart, and
estado_ecualizador_presets_personalizados_test.dart. servicio_ecualizador.dart,
servicio_audio.dart and the three protected EQ test files keep an empty
git diff. Full suite: 713/713 green (2 skipped, unchanged), up from 682.

size:exception - realized 1,954 changed lines (25 files, plus this docs
update) against the 400-550 forecast: lib/ + ARB alone is ~650 lines, near
the top of the forecast band by itself since this WU also had to build out
a screen body WU3a only stubbed; the rest is 4 test files (675 lines) and
11 new ARB keys regenerating 13 lib/l10n/gen files (~546 lines) - the same
pattern every prior work unit in this branch has hit. Not splittable: WU14
reuses this unit's editor component by exact runtime type and cannot begin
until this lands as a whole.
This commit is contained in:
2026-07-29 12:53:12 +02:00
parent e1732af222
commit c9fe0ad651
26 changed files with 1857 additions and 97 deletions
@@ -0,0 +1,161 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_ecualizador.dart';
import 'package:pluriwave/modelos/preset_ecualizador.dart';
import '../helpers/fakes.dart';
/// WU13 task 13.7 — `EstadoEcualizador`'s new custom-preset members
/// (`presetsPersonalizados`, `guardarPresetPersonalizado`,
/// `eliminarPresetPersonalizado`), reading/writing only through the new
/// `ServicioPresetsPersonalizados` (design ADR-5 hazard box).
///
/// **Correction found at apply time, deliberate**: this is a NEW file, not
/// an addition to `estado_ecualizador_test.dart`. That file is one of the
/// three EQ test files this change's master guard requires to pass
/// **unmodified** — it is exercised ~30 times via `cargarPersistido()`
/// using Fakes for `servicio`/`dispositivoAudio` ONLY, with no
/// SharedPreferences awareness anywhere in the file. Because of that,
/// `cargarPersistido()` itself is intentionally left untouched by this WU
/// (see `cargarPresetsPersonalizados` below) rather than folding a third,
/// always-real-by-default collaborator into a method exercised by a file
/// that must never change.
void main() {
EstadoEcualizador buildEq({FakeServicioPresetsPersonalizados? servicio}) {
return EstadoEcualizador(
audio: FakeServicioAudio(),
servicio: FakeServicioEcualizador(),
presetsPersonalizadosService:
servicio ?? FakeServicioPresetsPersonalizados(),
);
}
test('presetsPersonalizados starts empty before loading', () {
final eq = buildEq();
expect(eq.presetsPersonalizados, isEmpty);
eq.dispose();
});
test(
'cargarPresetsPersonalizados populates presetsPersonalizados from the service',
() async {
final fakeServicio = FakeServicioPresetsPersonalizados();
final preexistente = PresetEcualizador(
nombre: 'Ya guardado',
bandas: [1, 2, 3, 4, 5],
);
await fakeServicio.guardar(preexistente);
final eq = buildEq(servicio: fakeServicio);
await eq.cargarPresetsPersonalizados();
expect(eq.presetsPersonalizados, hasLength(1));
expect(eq.presetsPersonalizados.single.nombre, equals('Ya guardado'));
eq.dispose();
},
);
test(
'guardarPresetPersonalizado saves the CURRENT effective preset bands under the given name',
() async {
final eq = buildEq();
await eq.cambiarPreset(PresetEcualizador.jazz);
final guardado = await eq.guardarPresetPersonalizado('Mi preset');
expect(guardado, isTrue);
expect(eq.presetsPersonalizados, hasLength(1));
expect(eq.presetsPersonalizados.single.nombre, equals('Mi preset'));
expect(
eq.presetsPersonalizados.single.bandas,
equals(PresetEcualizador.jazz.bandas),
);
eq.dispose();
},
);
test('guardarPresetPersonalizado notifies listeners on success', () async {
final eq = buildEq();
var avisos = 0;
eq.addListener(() => avisos++);
await eq.guardarPresetPersonalizado('Preset con nombre');
expect(avisos, greaterThanOrEqualTo(1));
eq.dispose();
});
test(
'guardarPresetPersonalizado rejects an empty name: no save, returns false',
() async {
final eq = buildEq();
final guardado = await eq.guardarPresetPersonalizado('');
expect(guardado, isFalse);
expect(eq.presetsPersonalizados, isEmpty);
eq.dispose();
},
);
test(
'guardarPresetPersonalizado rejects a whitespace-only name: no save, returns false',
() async {
final eq = buildEq();
final guardado = await eq.guardarPresetPersonalizado(' ');
expect(guardado, isFalse);
expect(eq.presetsPersonalizados, isEmpty);
eq.dispose();
},
);
test(
'guardarPresetPersonalizado trims surrounding whitespace from a valid name',
() async {
final eq = buildEq();
final guardado = await eq.guardarPresetPersonalizado(' Con espacios ');
expect(guardado, isTrue);
expect(eq.presetsPersonalizados.single.nombre, equals('Con espacios'));
eq.dispose();
},
);
test(
'eliminarPresetPersonalizado removes a previously saved preset',
() async {
final eq = buildEq();
await eq.guardarPresetPersonalizado('Para borrar');
expect(eq.presetsPersonalizados, hasLength(1));
await eq.eliminarPresetPersonalizado('Para borrar');
expect(eq.presetsPersonalizados, isEmpty);
eq.dispose();
},
);
test(
'guardarPresetPersonalizado reads/writes only through the injected service '
'(never touches ServicioEcualizador)',
() async {
final fakeEcualizador = FakeServicioEcualizador();
final eq = EstadoEcualizador(
audio: FakeServicioAudio(),
servicio: fakeEcualizador,
presetsPersonalizadosService: FakeServicioPresetsPersonalizados(),
);
await eq.guardarPresetPersonalizado('Aislado');
// ServicioEcualizador's own config is completely untouched by the
// custom-preset save — it lives in a separate service (ADR-5 hazard
// box), not folded into servicio_ecualizador.dart's persistence.
expect(fakeEcualizador.config.porEmisora, isEmpty);
eq.dispose();
},
);
}
+22
View File
@@ -11,6 +11,7 @@ import 'package:pluriwave/servicios/servicio_dispositivo_audio.dart';
import 'package:pluriwave/servicios/servicio_ecualizador.dart';
import 'package:pluriwave/servicios/servicio_favoritos.dart';
import 'package:pluriwave/servicios/servicio_grabacion_radio.dart';
import 'package:pluriwave/servicios/servicio_presets_personalizados.dart';
import 'package:pluriwave/servicios/servicio_radio.dart';
class FakeServicioAudio extends ServicioAudio {
@@ -477,6 +478,27 @@ class FakeServicioEcualizador extends ServicioEcualizador {
}
}
/// In-memory fake for [ServicioPresetsPersonalizados] (WU13). Avoids any
/// real SharedPreferences I/O in state-layer tests, matching every other
/// `Fake*` service in this file.
class FakeServicioPresetsPersonalizados extends ServicioPresetsPersonalizados {
final List<PresetEcualizador> _presets = [];
@override
Future<List<PresetEcualizador>> listar() async => List.from(_presets);
@override
Future<void> guardar(PresetEcualizador preset) async {
_presets.removeWhere((p) => p.nombre == preset.nombre);
_presets.add(preset);
}
@override
Future<void> eliminar(String nombre) async {
_presets.removeWhere((p) => p.nombre == nombre);
}
}
/// A [ServicioDispositivoAudio] fake that throws on [obtenerDispositivoActual].
///
/// Used to test the graceful-failure path in [EstadoEcualizador.cargarPersistido].
@@ -5,6 +5,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/estado/estado_ecualizador.dart';
import 'package:pluriwave/estado/estado_radio.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/modelos/dispositivo_audio.dart';
import 'package:pluriwave/modelos/emisora.dart';
import 'package:pluriwave/modelos/preset_ecualizador.dart';
import 'package:pluriwave/pantallas/ajustes/pantalla_ajustes_ecualizador.dart';
import 'package:pluriwave/widgets/pluri_push_scaffold.dart';
import 'package:provider/provider.dart';
@@ -17,6 +20,12 @@ import '../../helpers/fakes_alarmas.dart';
/// a [PluriPushScaffold] and its moved controls (the enable switch) still
/// respond exactly as they did inside the old `_SeccionEcualizador`.
///
/// WU13 restyled the header away (design ADR-5 — the strip that used to
/// duplicate "Equalizer" as `EcualizadorWidget`'s own internal title is
/// gone), added the base-vs-per-station explainer, the "Salida activa"
/// row, the "Emisoras con ajuste propio" drill-down and the custom-preset
/// save flow — see the `WU13` group below.
///
/// Pre-existing project constraint (see `pantalla_ajustes_test.dart`):
/// PluriGlassSurface paints a background over ListTile's ink layer (here,
/// via SwitchListTile), which Flutter flags as a warning-level assertion,
@@ -43,17 +52,33 @@ void main() {
'${Directory.current.path}/test/fixtures/emisoras_custom_vacio.json',
);
Future<EstadoRadio> crearEstado() async {
Future<EstadoRadio> crearEstado({
Map<String, PresetEcualizador>? porEmisora,
FakeServicioDispositivoAudio? dispositivoAudio,
bool eqMultiDeviceEnabled = false,
List<Emisora> favoritosIniciales = const [],
}) async {
final favoritos = FakeServicioFavoritos();
for (final emisora in favoritosIniciales) {
await favoritos.agregar(emisora);
}
final estado = EstadoRadio(
audio: FakeServicioAudio(),
favoritos: FakeServicioFavoritos(),
favoritos: favoritos,
radio: FakeServicioRadio(),
servicioEcualizador: FakeServicioEcualizador(),
servicioEcualizador: FakeServicioEcualizador(
porEmisora: porEmisora,
eqMultiDeviceEnabled: eqMultiDeviceEnabled,
),
servicioGrabacion: FakeServicioGrabacionRadioInactiva(),
dispositivoAudio: dispositivoAudio,
resolverArchivoCustom: archivoCustomVacio,
iniciarAutomaticamente: false,
);
await estado.ecualizador.cargarPersistido();
if (favoritosIniciales.isNotEmpty) {
await estado.cargarFavoritos();
}
return estado;
}
@@ -82,10 +107,11 @@ void main() {
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
// "Equalizer" also appears inside EcualizadorWidget's own pre-existing
// internal header, which WU3a does not touch (ecualizador_widget.dart's
// header strip is WU13's job per design ADR-5) — so we assert on the
// AppBar's title specifically rather than a bare text match.
// WU13 stripped EcualizadorWidget's own internal "Equalizer" title +
// preset Chip row (design ADR-5) — the pushed screen's AppBar is now
// the ONLY place this title renders. Still asserting on the AppBar
// specifically (not a bare text match) keeps this test meaningful even
// if a future WU reintroduces a second on-screen occurrence.
expect(find.byType(PluriPushScaffold), findsOneWidget);
final appBar = tester.widget<AppBar>(find.byType(AppBar));
expect((appBar.title as Text).data, equals('Equalizer'));
@@ -107,4 +133,242 @@ void main() {
expect(estado.ecualizador.activo, equals(!before));
});
group('WU13 — restyle, custom presets, salida activa, drill-down', () {
testWidgets('exactly 5 sliders render on the Ecualizador screen', (
tester,
) async {
// Spec `eq-custom-presets` "Five-Band Equalizer (Regression Guard)":
// GIVEN the user opens the Ecualizador screen THEN exactly 5 sliders
// render — asserted here at the SCREEN level (task 13.1's own GIVEN),
// in addition to the component-level guard in
// `ecualizador_widget_test.dart`.
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
expect(find.byType(Slider), findsNWidgets(5));
});
testWidgets('base-vs-per-station explainer banner is visible', (
tester,
) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
expect(find.byKey(const Key('eq-base-explainer-banner')), findsOneWidget);
});
testWidgets(
'Salida activa row is visible and shows a default label when no device is tracked',
(tester) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
expect(find.byKey(const Key('eq-active-output-row')), findsOneWidget);
expect(find.text('Active output'), findsOneWidget);
expect(
find.descendant(
of: find.byKey(const Key('eq-active-output-row')),
matching: find.text("This device's speaker"),
),
findsOneWidget,
);
},
);
testWidgets('Salida activa row updates on a simulated device change', (
tester,
) async {
_suppressListTileInkAssertion();
final dispositivoAudio = FakeServicioDispositivoAudio();
final estado = await crearEstado(
dispositivoAudio: dispositivoAudio,
eqMultiDeviceEnabled: true,
);
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
dispositivoAudio.emitirDispositivo(
const DispositivoAudio(
id: 'bt_a2dp:AA:BB:CC:DD:EE:FF',
tipo: TipoDispositivo.bluetoothA2dp,
nombre: 'Auriculares BT',
),
);
await tester.pumpAndSettle();
expect(
find.descendant(
of: find.byKey(const Key('eq-active-output-row')),
matching: find.text('Auriculares BT'),
),
findsOneWidget,
);
});
testWidgets(
'Emisoras con ajuste propio drill-down lists exactly the overridden stations',
(tester) async {
_suppressListTileInkAssertion();
const favorita = Emisora(
uuid: 'uuid-favorita',
nombre: 'Radio Favorita',
url: 'https://example.com/favorita',
);
final estado = await crearEstado(
porEmisora: {
'uuid-favorita': PresetEcualizador.rock,
'uuid-no-favorita': PresetEcualizador.jazz,
},
favoritosIniciales: const [favorita],
);
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
expect(find.byKey(const Key('eq-stations-own-eq-row')), findsOneWidget);
expect(
tester
.widget<Text>(find.byKey(const Key('eq-stations-own-eq-count')))
.data,
equals('2'),
);
await tester.tap(find.byKey(const Key('eq-stations-own-eq-row')));
await tester.pumpAndSettle();
// The favorite station resolves to its display name; the other
// uuid (never seen among favorites) falls back to the raw uuid —
// same fallback chain `nombreVisible` already uses for devices.
expect(find.text('Radio Favorita'), findsOneWidget);
expect(find.text('uuid-no-favorita'), findsOneWidget);
},
);
testWidgets(
'drill-down shows an empty state when no station has its own EQ',
(tester) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('eq-stations-own-eq-row')));
await tester.pumpAndSettle();
expect(find.text('No stations have their own EQ yet.'), findsOneWidget);
},
);
testWidgets(
'Guardar como preset persists the current bands; the preset appears in the chip row',
(tester) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
await tester.ensureVisible(
find.byKey(const Key('eq-save-preset-action')),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('eq-save-preset-action')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('eq-save-preset-name-field')),
'Mi preset',
);
await tester.tap(
find.byKey(const Key('eq-save-preset-confirm-button')),
);
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
expect(find.text('Mi preset'), findsOneWidget);
expect(
estado.ecualizador.presetsPersonalizados.map((p) => p.nombre),
contains('Mi preset'),
);
},
);
testWidgets(
'Guardar como preset with an empty name shows a validation message and persists nothing',
(tester) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
await tester.ensureVisible(
find.byKey(const Key('eq-save-preset-action')),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('eq-save-preset-action')));
await tester.pumpAndSettle();
await tester.tap(
find.byKey(const Key('eq-save-preset-confirm-button')),
);
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.text('Enter a name for the preset.'), findsOneWidget);
expect(estado.ecualizador.presetsPersonalizados, isEmpty);
},
);
testWidgets(
'Guardar como preset with a whitespace-only name shows the same validation message',
(tester) async {
_suppressListTileInkAssertion();
final estado = await crearEstado();
addTearDown(estado.dispose);
await tester.pumpWidget(buildScreen(estado));
await tester.pumpAndSettle();
await tester.ensureVisible(
find.byKey(const Key('eq-save-preset-action')),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('eq-save-preset-action')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('eq-save-preset-name-field')),
' ',
);
await tester.tap(
find.byKey(const Key('eq-save-preset-confirm-button')),
);
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
expect(estado.ecualizador.presetsPersonalizados, isEmpty);
},
);
});
}
@@ -0,0 +1,126 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/modelos/preset_ecualizador.dart';
import 'package:pluriwave/servicios/servicio_presets_personalizados.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// WU13 task 13.2 — persistence for user-named custom EQ presets.
///
/// Design ADR-5 hazard box: this lives in its OWN file and OWN
/// SharedPreferences key (`eq_custom_presets_v1`), deliberately separate
/// from `ServicioEcualizador` — that file has an empty-`git diff` success
/// criterion for this change, so persistence for custom presets must never
/// be added there.
void main() {
setUp(() {
SharedPreferences.setMockInitialValues({});
});
test('listar returns an empty list when nothing was saved yet', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
expect(await servicio.listar(), isEmpty);
});
test('guardar then listar round-trips a named custom preset', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
// Not `const`: PresetEcualizador's constructor asserts `bandas.length
// == 5`, and `List.length` is not constant-foldable in an assert here
// (same const-eval limitation the branch already hit for
// `DateTime(...)` fixtures in WU9) — the model's own static presets
// (e.g. `PresetEcualizador.flat`) are declared `final`, not `const`,
// for the same reason.
final preset = PresetEcualizador(
nombre: 'Mi preset',
bandas: [1.0, -2.0, 3.0, -4.0, 5.0],
);
await servicio.guardar(preset);
final guardados = await servicio.listar();
expect(guardados, hasLength(1));
expect(guardados.single, equals(preset));
});
test('guardar persists under its OWN SharedPreferences key', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
final preset = PresetEcualizador(nombre: 'Otro', bandas: [0, 0, 0, 0, 0]);
await servicio.guardar(preset);
expect(prefs.getString('eq_custom_presets_v1'), isNotNull);
});
test('guardar with a repeated name replaces the previous entry', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
final v1 = PresetEcualizador(nombre: 'Mismo', bandas: [1, 1, 1, 1, 1]);
final v2 = PresetEcualizador(nombre: 'Mismo', bandas: [2, 2, 2, 2, 2]);
await servicio.guardar(v1);
await servicio.guardar(v2);
final guardados = await servicio.listar();
expect(guardados, hasLength(1));
expect(guardados.single.bandas, equals(v2.bandas));
});
test('guardar preserves insertion order across multiple presets', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
final primero = PresetEcualizador(
nombre: 'Primero',
bandas: [0, 0, 0, 0, 0],
);
final segundo = PresetEcualizador(
nombre: 'Segundo',
bandas: [0, 0, 0, 0, 0],
);
await servicio.guardar(primero);
await servicio.guardar(segundo);
final guardados = await servicio.listar();
expect(guardados.map((p) => p.nombre).toList(), ['Primero', 'Segundo']);
});
test('eliminar removes the named preset only', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
final conservar = PresetEcualizador(
nombre: 'Conservar',
bandas: [0, 0, 0, 0, 0],
);
final borrar = PresetEcualizador(nombre: 'Borrar', bandas: [0, 0, 0, 0, 0]);
await servicio.guardar(conservar);
await servicio.guardar(borrar);
await servicio.eliminar('Borrar');
final guardados = await servicio.listar();
expect(guardados, hasLength(1));
expect(guardados.single.nombre, equals('Conservar'));
});
test('eliminar on an unknown name is a safe no-op', () async {
final prefs = await SharedPreferences.getInstance();
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
await servicio.eliminar('no existe');
expect(await servicio.listar(), isEmpty);
});
test(
'a corrupt top-level payload degrades to an empty list, never throws',
() async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('eq_custom_presets_v1', 'not valid json{{{');
final servicio = ServicioPresetsPersonalizados(prefs: prefs);
await expectLater(servicio.listar(), completion(isEmpty));
},
);
}
+95
View File
@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pluriwave/l10n/gen/app_localizations.dart';
import 'package:pluriwave/modelos/preset_ecualizador.dart';
import 'package:pluriwave/widgets/ecualizador_widget.dart';
/// WU13 task 13.1 — first-class regression guard (design ADR-5, spec
/// `eq-custom-presets` "Five-Band Equalizer"): the equalizer widget must
/// always render exactly 5 vertical sliders. Band count is device-reported
/// via `just_audio`'s `AndroidEqualizer` (spike, Engram id 2498), not
/// app-chosen — any future change rendering 7 sliders is rejected on sight.
///
/// **Correction found at apply time**: `tasks.md`'s WU13 Verify command
/// names this file as if it already existed ("Modified tests:
/// ecualizador_widget_test.dart"). No such file existed before this commit
/// (`ecualizador_widget.dart` had zero test coverage) — created new instead.
void main() {
Widget buildWidget({
PresetEcualizador? preset,
bool habilitado = true,
void Function(PresetEcualizador)? onCambio,
}) {
return MaterialApp(
locale: const Locale('en'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: EcualizadorWidget(
preset: preset ?? PresetEcualizador.flat,
habilitado: habilitado,
onCambio: onCambio ?? (_) {},
),
),
);
}
testWidgets('renders exactly 5 vertical sliders, one per band', (
tester,
) async {
await tester.pumpWidget(buildWidget());
expect(find.byType(Slider), findsNWidgets(5));
});
testWidgets('renders exactly 5 sliders regardless of the preset selected', (
tester,
) async {
// Regression guard restated: a future change proposing 7 sliders (the
// rejected mockup band count) must fail this test regardless of which
// fixed preset is active.
await tester.pumpWidget(buildWidget(preset: PresetEcualizador.jazz));
expect(find.byType(Slider), findsNWidgets(5));
});
testWidgets('dragging a slider reports the updated band back via onCambio', (
tester,
) async {
PresetEcualizador? reportado;
await tester.pumpWidget(buildWidget(onCambio: (p) => reportado = p));
final slider = tester.widget<Slider>(find.byType(Slider).first);
slider.onChanged?.call(6.0);
await tester.pump();
expect(reportado, isNotNull);
expect(reportado!.bandas.length, 5);
expect(reportado!.bandas.first, 6.0);
});
testWidgets(
'habilitado: false disables every slider (greyed, non-interactive)',
(tester) async {
await tester.pumpWidget(buildWidget(habilitado: false));
final sliders = tester.widgetList<Slider>(find.byType(Slider));
expect(sliders, hasLength(5));
for (final slider in sliders) {
expect(slider.onChanged, isNull);
}
},
);
testWidgets('habilitado: true (default) keeps every slider interactive', (
tester,
) async {
await tester.pumpWidget(buildWidget());
final sliders = tester.widgetList<Slider>(find.byType(Slider));
expect(sliders, hasLength(5));
for (final slider in sliders) {
expect(slider.onChanged, isNotNull);
}
});
}