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:
@@ -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));
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user