-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First test which mocks hive and riverpod
also made add/remove methods async for stored devices
- Loading branch information
Showing
6 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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:test/test.dart'; | ||
|
||
import '../testing_utils/gear_utils.dart'; | ||
import '../testing_utils/hive_utils.dart'; | ||
|
||
void main() { | ||
setUpAll(() async { | ||
flTest.TestWidgetsFlutterBinding.ensureInitialized(); | ||
await setupHive(); | ||
}); | ||
tearDownAll(() 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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
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:tail_app/Backend/device_registry.dart'; | ||
|
||
Future<BaseStatefulDevice> createAndStoreGear(String gearBtName, ProviderContainer ref) async { | ||
BaseDeviceDefinition baseDeviceDefinition = DeviceRegistry.getByName(gearBtName)!; | ||
BaseStoredDevice baseStoredDevice; | ||
BaseStatefulDevice statefulDevice; | ||
baseStoredDevice = BaseStoredDevice(baseDeviceDefinition.uuid, "DEV${baseDeviceDefinition.deviceType.name}", baseDeviceDefinition.deviceType.color(ref: ref).value); | ||
baseStoredDevice.name = getNameFromBTName(baseDeviceDefinition.btName); | ||
statefulDevice = BaseStatefulDevice(baseDeviceDefinition, baseStoredDevice); | ||
statefulDevice.deviceConnectionState.value = ConnectivityState.connected; | ||
isAnyGearConnected.value = true; | ||
if (!ref.read(knownDevicesProvider).containsKey(baseStoredDevice.btMACAddress)) { | ||
await ref.read(knownDevicesProvider.notifier).add(statefulDevice); | ||
} | ||
return statefulDevice; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
import 'package:sentry_hive/sentry_hive.dart'; | ||
import 'package:tail_app/main.dart'; | ||
|
||
Future<void> deleteHive() async { | ||
await SentryHive.deleteFromDisk(); | ||
} | ||
|
||
class FakePathProviderPlatform extends Fake with MockPlatformInterfaceMixin implements PathProviderPlatform { | ||
@override | ||
Future<String?> getTemporaryPath() async { | ||
return 'test/temp/'; | ||
} | ||
|
||
@override | ||
Future<String?> getApplicationSupportPath() async { | ||
return 'test/support/'; | ||
} | ||
|
||
@override | ||
Future<String?> getLibraryPath() async { | ||
return 'test/library/'; | ||
} | ||
|
||
@override | ||
Future<String?> getApplicationDocumentsPath() async { | ||
return 'test/application/'; | ||
} | ||
|
||
@override | ||
Future<String?> getExternalStoragePath() async { | ||
return 'test/external/'; | ||
} | ||
|
||
@override | ||
Future<List<String>?> getExternalCachePaths() async { | ||
return <String>['test/externalCache/']; | ||
} | ||
|
||
@override | ||
Future<List<String>?> getExternalStoragePaths({ | ||
StorageDirectory? type, | ||
}) async { | ||
return <String>['test/external/']; | ||
} | ||
|
||
@override | ||
Future<String?> getDownloadsPath() async { | ||
return 'test/downloads/'; | ||
} | ||
} | ||
|
||
Future<void> setupHive() async { | ||
PathProviderPlatform.instance = FakePathProviderPlatform(); | ||
await initHive(); | ||
} |