diff --git a/lib/Backend/device_registry.dart b/lib/Backend/device_registry.dart index 3b75efa7..e73af7df 100644 --- a/lib/Backend/device_registry.dart +++ b/lib/Backend/device_registry.dart @@ -79,7 +79,7 @@ class DeviceRegistry { } static List getAllIds() { - return allDevices.map((BaseDeviceDefinition e) => e.bleDeviceService).toList(); + return allDevices.map((BaseDeviceDefinition e) => e.bleDeviceService).toSet().toList(); } } diff --git a/lib/main.dart b/lib/main.dart index 09eab65b..14515e09 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -135,20 +135,18 @@ Future initHive() async { final Directory appDir = await getApplicationSupportDirectory(); SentryHive ..init(appDir.path) - ..registerAdapter(BaseStoredDeviceAdapter()) - ..registerAdapter(MoveListAdapter()) - ..registerAdapter(MoveAdapter()) - ..registerAdapter(BaseActionAdapter()) - ..registerAdapter(TriggerAdapter()) - ..registerAdapter(TriggerActionAdapter()) - ..registerAdapter(ActionCategoryAdapter()) - ..registerAdapter(DeviceTypeAdapter()) - ..registerAdapter(MoveTypeAdapter()) - ..registerAdapter(EasingTypeAdapter()) - ..registerAdapter( - AudioActionAdapter(), - ) - ..registerAdapter(FavoriteActionAdapter()); + ..registerAdapter(BaseStoredDeviceAdapter(), override: true) + ..registerAdapter(MoveListAdapter(), override: true) + ..registerAdapter(MoveAdapter(), override: true) + ..registerAdapter(BaseActionAdapter(), override: true) + ..registerAdapter(TriggerAdapter(), override: true) + ..registerAdapter(TriggerActionAdapter(), override: true) + ..registerAdapter(ActionCategoryAdapter(), override: true) + ..registerAdapter(DeviceTypeAdapter(), override: true) + ..registerAdapter(MoveTypeAdapter(), override: true) + ..registerAdapter(EasingTypeAdapter(), override: true) + ..registerAdapter(AudioActionAdapter(), override: true) + ..registerAdapter(FavoriteActionAdapter(), override: true); await SentryHive.openBox(settings); // Do not set type here await SentryHive.openBox(triggerBox); await SentryHive.openBox(favoriteActionsBox); diff --git a/test/Backend/device_registry_test.dart b/test/Backend/device_registry_test.dart index 3575c9a8..cf7ce792 100644 --- a/test/Backend/device_registry_test.dart +++ b/test/Backend/device_registry_test.dart @@ -1,32 +1,61 @@ +import 'dart:async'; + import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart' as flTest; import 'package:tail_app/Backend/Bluetooth/bluetooth_manager.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Backend/LoggingWrappers.dart'; +import 'package:tail_app/Backend/device_registry.dart'; import 'package:test/test.dart'; import '../testing_utils/gear_utils.dart'; import '../testing_utils/hive_utils.dart'; +Future testGearAdd(String name) async { + final container = ProviderContainer( + overrides: [], + ); + expect(container.read(knownDevicesProvider).length, 0); + expect(HiveProxy.getAll('devices').length, 0); + BaseStatefulDevice baseStatefulDevice = await createAndStoreGear(name, container); + expect(baseStatefulDevice.baseDeviceDefinition.btName, name); + expect(container.read(knownDevicesProvider).length, 1); + expect(container.read(knownDevicesProvider).values.first, baseStatefulDevice); + expect(HiveProxy.getAll('devices').length, 1); + expect(HiveProxy.getAll('devices').first, baseStatefulDevice.baseStoredDevice); +} + void main() { - setUpAll(() async { + setUp(() async { flTest.TestWidgetsFlutterBinding.ensureInitialized(); await setupHive(); }); - tearDownAll(() async { + tearDown(() async { await deleteHive(); }); - test('Test storing gear to ref', () async { - final container = ProviderContainer( - overrides: [], - ); - expect(container.read(knownDevicesProvider).length, 0); - expect(HiveProxy.getAll('devices').length, 0); - BaseStatefulDevice baseStatefulDevice = await createAndStoreGear('MiTail', container); - expect(baseStatefulDevice.baseDeviceDefinition.btName, 'MiTail'); - expect(container.read(knownDevicesProvider).length, 1); - expect(container.read(knownDevicesProvider).values.first, baseStatefulDevice); - expect(HiveProxy.getAll('devices').length, 1); - expect(HiveProxy.getAll('devices').first, baseStatefulDevice.baseStoredDevice); + group('Test creating gear', () { + test('Test storing MiTail to ref', () async { + await testGearAdd('MiTail'); + }); + test('Test storing (!)Tail1 to ref', () async { + await testGearAdd('(!)Tail1'); + }); + test('Test storing minitail to ref', () async { + await testGearAdd('minitail'); + }); + test('Test storing flutter to ref', () async { + await testGearAdd('flutter'); + }); + test('Test storing EG2 to ref', () async { + await testGearAdd('EG2'); + }); + test('Test storing EarGear to ref', () async { + await testGearAdd('EarGear'); + }); + }); + test('Get all service IDs', () { + List allIds = DeviceRegistry.getAllIds(); + String itemsAsList = allIds.toString(); + expect(itemsAsList, "[3af2108b-d066-42da-a7d4-55648fa0a9b6, 927dee04-ddd4-4582-8e42-69dc9fbfae66]"); }); }