Skip to content

Commit

Permalink
add test for getting all gear
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 4, 2024
1 parent 25d3d60 commit 46e7b8f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/Backend/device_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DeviceRegistry {
}

static List<String> getAllIds() {
return allDevices.map((BaseDeviceDefinition e) => e.bleDeviceService).toList();
return allDevices.map((BaseDeviceDefinition e) => e.bleDeviceService).toSet().toList();
}
}

Expand Down
26 changes: 12 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,18 @@ Future<void> 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<Trigger>(triggerBox);
await SentryHive.openBox<FavoriteAction>(favoriteActionsBox);
Expand Down
57 changes: 43 additions & 14 deletions test/Backend/device_registry_test.dart
Original file line number Diff line number Diff line change
@@ -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<void> testGearAdd(String name) async {
final container = ProviderContainer(
overrides: [],
);
expect(container.read(knownDevicesProvider).length, 0);
expect(HiveProxy.getAll<BaseStoredDevice>('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<BaseStoredDevice>('devices').length, 1);
expect(HiveProxy.getAll<BaseStoredDevice>('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<BaseStoredDevice>('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<BaseStoredDevice>('devices').length, 1);
expect(HiveProxy.getAll<BaseStoredDevice>('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<String> allIds = DeviceRegistry.getAllIds();
String itemsAsList = allIds.toString();
expect(itemsAsList, "[3af2108b-d066-42da-a7d4-55648fa0a9b6, 927dee04-ddd4-4582-8e42-69dc9fbfae66]");
});
}

0 comments on commit 46e7b8f

Please sign in to comment.