From 689567458a6d789eb03b0a3dbac046220160acb7 Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Wed, 5 Jun 2024 15:38:09 -0400 Subject: [PATCH] initial device definition test --- test/Backend/device_definition_test.dart | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/Backend/device_definition_test.dart diff --git a/test/Backend/device_definition_test.dart b/test/Backend/device_definition_test.dart new file mode 100644 index 00000000..e513b1ee --- /dev/null +++ b/test/Backend/device_definition_test.dart @@ -0,0 +1,37 @@ +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/Bluetooth/bluetooth_manager_plus.dart'; +import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; +import 'package:test/test.dart'; + +import '../testing_utils/bluetooth_test_utils.dart'; +import '../testing_utils/gear_utils.dart'; +import '../testing_utils/hive_utils.dart'; + +void main() { + setUp(() async { + flTest.TestWidgetsFlutterBinding.ensureInitialized(); + await setupHive(); + }); + tearDown(() async { + await deleteHive(); + isAnyGearConnected.value = false; + }); + group('Stateful Device event listeners', () { + test('Battery Levels', () async { + setupBTMock('MiTail', 'TestMiTail'); + ProviderContainer container = await testGearAdd('MiTail', gearMacPrefix: 'Test'); + BaseStatefulDevice baseStatefulDevice = container.read(knownDevicesProvider).values.first; + expect(baseStatefulDevice.batteryLevel.value, -1); + expect(baseStatefulDevice.batlevels.isEmpty, true); + baseStatefulDevice.batteryLevel.value = 100; + expect(baseStatefulDevice.batteryLevel.value, 100); + expect(baseStatefulDevice.batlevels.length, 1); + expect(baseStatefulDevice.batlevels.first.y, 100); + baseStatefulDevice.reset(); + expect(baseStatefulDevice.batteryLevel.value, -1); + expect(baseStatefulDevice.batlevels.isEmpty, true); + }); + }); +}