import 'package:flutter_test/flutter_test.dart'; import 'package:pluriwave/servicios/musica_local_auto.dart'; /// `FuenteMusicaLocalAuto.estadoCarpeta` promises, in its own interface doc, /// «Never throws: cualquier fallo degrada a un valor de /// [EstadoCarpetaLocal], nunca a una excepción». The refactor to the /// three-valued enum moved `await _uriPersistida()` OUTSIDE the try/catch, /// so a SharedPreferences failure escaped again — and the only caller, /// `PluriWaveAudioHandler.getChildren`'s root branch, awaits it inline, so /// the throw takes the whole browse root down and empties the car. /// /// DELIBERATE FILE SEPARATION: nothing here may call /// `SharedPreferences.setMockInitialValues`. That call swaps /// `SharedPreferencesStorePlatform.instance` for an in-memory store for the /// rest of the isolate, and an in-memory store cannot fail. Left alone, the /// default store answers a real `getAll` platform call that nothing handles /// under `flutter test`, which is exactly the failure being exercised — /// hence its own file, not a group inside `musica_local_auto_test.dart`. void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('FuenteMusicaLocalAutoImpl.estadoCarpeta — fallo de prefs', () { test('un fallo leyendo SharedPreferences degrada a noConfigurada en vez ' 'de propagar y vaciar la raíz del coche', () async { // Sin prefs inyectadas: `_resolverPrefs` cae en // `SharedPreferences.getInstance()`, que aquí lanza. final fuente = FuenteMusicaLocalAutoImpl(); await expectLater( fuente.estadoCarpeta(), completion(EstadoCarpetaLocal.noConfigurada), ); }); test('ese fallo NO se reporta como canalNoDisponible, que es la única ' 'respuesta que significa «hay carpeta pero no puedo comprobar el ' 'permiso»', () async { final fuente = FuenteMusicaLocalAutoImpl(); final estado = await fuente.estadoCarpeta(); expect( estado, isNot(EstadoCarpetaLocal.canalNoDisponible), reason: 'el fallo de prefs es una MissingPluginException igual que la ' 'del canal `pluriwave/file_actions`, así que un único try que ' 'las capturase juntas borraría la distinción de 3 valores: el ' 'árbol mostraría «Música Local» con un subárbol que explica un ' 'problema de canal inexistente', ); }); }); }