-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor step retrieval logic and update device_info_plus dependency;…
… add unit tests for health data retrieval
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:health/health.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
group('Health Plugin Tests', () { | ||
late Health health; | ||
|
||
setUp(() { | ||
health = Health(); | ||
}); | ||
|
||
test('getHealthDataFromTypes returns results within the correct date range', () async { | ||
final startTime = DateTime(2023, 1, 1); | ||
final endTime = DateTime(2024, 1, 1); | ||
final types = [HealthDataType.WORKOUT]; | ||
|
||
final healthData = await health.getHealthDataFromTypes( | ||
types: types, | ||
startTime: startTime, | ||
endTime: endTime, | ||
); | ||
|
||
for (var dataPoint in healthData) { | ||
|
||
// print the values time | ||
print('dateFrom: ${dataPoint.dateFrom} - required: $startTime'); | ||
print('dateTo: ${dataPoint.dateTo} - required: $endTime'); | ||
expect(dataPoint.dateFrom.isAfter(startTime) || dataPoint.dateFrom.isAtSameMomentAs(startTime), isTrue); | ||
expect(dataPoint.dateTo.isBefore(endTime) || dataPoint.dateTo.isAtSameMomentAs(endTime), isTrue); | ||
} | ||
}); | ||
|
||
test('getHealthDataFromTypes returns no results outside the specified date range', () async { | ||
final startTime = DateTime(2023, 1, 1); | ||
final endTime = DateTime(2024, 1, 1); | ||
final types = [HealthDataType.WORKOUT]; | ||
|
||
final healthData = await health.getHealthDataFromTypes( | ||
types: types, | ||
startTime: startTime, | ||
endTime: endTime, | ||
); | ||
|
||
for (var dataPoint in healthData) { | ||
expect(dataPoint.dateFrom.isBefore(startTime), isFalse); | ||
expect(dataPoint.dateTo.isAfter(endTime), isFalse); | ||
} | ||
}); | ||
}); | ||
} |