Dart half of bt-device-identity. EstadoEcualizador now caches each device's platform-reported name in memory so the settings screen shows the device's own Bluetooth name instead of its raw id when no custom rename exists, and skips auto-creating preset entries for the composite-placeholder sentinel. Enabling multi-device EQ triggers the Bluetooth permission request through the new channel contract. A flag-guarded one-time migration purges only entries keyed by the exact literal placeholder id from the three per-device preference maps, since those collided entries cannot be attributed to a device. Work unit 2/2 of bt-device-identity (Dart state + migration).
95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pluriwave/modelos/dispositivo_audio.dart';
|
|
|
|
import '../helpers/fakes.dart';
|
|
|
|
void main() {
|
|
group('ServicioDispositivoAudio (abstract contract)', () {
|
|
late FakeServicioDispositivoAudio fake;
|
|
|
|
setUp(() {
|
|
fake = FakeServicioDispositivoAudio();
|
|
});
|
|
|
|
tearDown(() async {
|
|
await fake.dispose();
|
|
});
|
|
|
|
test('dispositivoActual is null initially', () {
|
|
expect(fake.dispositivoActual, isNull);
|
|
});
|
|
|
|
test(
|
|
'obtenerDispositivoActual returns current device after emit',
|
|
() async {
|
|
const device = DispositivoAudio(
|
|
id: 'builtin_speaker',
|
|
tipo: TipoDispositivo.altavozInterno,
|
|
nombre: 'Speaker',
|
|
);
|
|
fake.emitirDispositivo(device);
|
|
|
|
final result = await fake.obtenerDispositivoActual();
|
|
expect(result, equals(device));
|
|
},
|
|
);
|
|
|
|
test('onDispositivoCambiado stream emits when device changes', () async {
|
|
const deviceA = DispositivoAudio(
|
|
id: 'builtin_speaker',
|
|
tipo: TipoDispositivo.altavozInterno,
|
|
nombre: 'Speaker',
|
|
);
|
|
const deviceB = DispositivoAudio(
|
|
id: 'bt_a2dp:AA:BB:CC:DD:EE:FF',
|
|
tipo: TipoDispositivo.bluetoothA2dp,
|
|
nombre: 'BT Headphones',
|
|
);
|
|
|
|
final received = <DispositivoAudio>[];
|
|
final sub = fake.onDispositivoCambiado.listen(received.add);
|
|
|
|
fake.emitirDispositivo(deviceA);
|
|
fake.emitirDispositivo(deviceB);
|
|
|
|
await Future<void>.delayed(Duration.zero);
|
|
await sub.cancel();
|
|
|
|
expect(received, equals([deviceA, deviceB]));
|
|
});
|
|
|
|
test('dispositivoActual tracks last emitted device', () {
|
|
const device = DispositivoAudio(
|
|
id: 'wired_headset',
|
|
tipo: TipoDispositivo.auricularesCable,
|
|
nombre: 'Wired Headset',
|
|
);
|
|
fake.emitirDispositivo(device);
|
|
expect(fake.dispositivoActual, equals(device));
|
|
});
|
|
|
|
test(
|
|
'onDispositivoCambiado is a broadcast stream (multiple listeners)',
|
|
() {
|
|
expect(fake.onDispositivoCambiado.isBroadcast, isTrue);
|
|
},
|
|
);
|
|
|
|
test('dispose closes the stream without error', () async {
|
|
await expectLater(fake.dispose(), completes);
|
|
});
|
|
|
|
// bt-device-identity Task 2.5: interface-completeness — every concrete
|
|
// ServicioDispositivoAudio must implement solicitarPermisoBluetooth.
|
|
test(
|
|
'solicitarPermisoBluetooth increments the call counter and returns '
|
|
'the configured value',
|
|
() async {
|
|
final granted = await fake.solicitarPermisoBluetooth();
|
|
expect(granted, isTrue);
|
|
expect(fake.solicitarPermisoBluetoothCalls, equals(1));
|
|
},
|
|
);
|
|
});
|
|
}
|