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
@@ -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);
},
);
});
}