-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from JordyHers-org/chore/110-add-more-tests-t…
…hat-were-not-completed Chore/110 add more tests that were not completed
- Loading branch information
Showing
5 changed files
with
77 additions
and
20 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
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,13 +1,59 @@ | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../helpers/test_helpers.mocks.dart'; | ||
import 'package:parental_control/services/app_usage_local_service.dart'; | ||
|
||
void main() { | ||
late MockAppUsage mockAppUsage; | ||
setUp(() { | ||
mockAppUsage = MockAppUsage(); | ||
}); | ||
test('App Usage Local', () { | ||
expect(mockAppUsage, isInstanceOf<MockAppUsage>()); | ||
group('AppUsage Tests', () { | ||
const channel = MethodChannel('app_usage.methodChannel'); | ||
|
||
setUp(() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
}); | ||
|
||
test('getAppUsage returns a list of AppUsageInfo for Android', () async { | ||
//Arrange | ||
final startDate = DateTime(2023, 6, 10, 10, 0, 0); | ||
final endDate = DateTime(2023, 6, 10, 11, 0, 0); | ||
final fakeUsage = { | ||
'com.tiktok.app1': [3600.0], | ||
'com.messenger.app1': [1800.0], | ||
}; | ||
|
||
TestDefaultBinaryMessengerBinding.instance?.defaultBinaryMessenger | ||
.setMockMethodCallHandler(channel, (MethodCall methodCall) async { | ||
if (methodCall.method == 'getUsage') { | ||
return fakeUsage; | ||
} | ||
return null; | ||
}); | ||
|
||
//Act | ||
final result = | ||
await AppUsage.getAppUsage(startDate, endDate, useMock: true); | ||
|
||
//Assert | ||
expect(result.length, equals(2)); | ||
expect(result[0].packageName, equals('com.tiktok.app1')); | ||
expect(result[0].usage, equals(const Duration(hours: 1))); | ||
expect(result[0].startDate, equals(startDate)); | ||
expect(result[0].endDate, equals(endDate)); | ||
|
||
expect(result[1].packageName, equals('com.messenger.app1')); | ||
expect(result[1].usage, equals(const Duration(minutes: 30))); | ||
expect(result[1].startDate, equals(startDate)); | ||
expect(result[1].endDate, equals(endDate)); | ||
}); | ||
|
||
test('getAppUsage throws an exception for non-Android platforms', () async { | ||
//Arrange | ||
final startDate = DateTime(2023, 6, 10, 10, 0, 0); | ||
final endDate = DateTime(2023, 6, 10, 11, 0, 0); | ||
|
||
//Act | ||
final result = AppUsage.getAppUsage(startDate, endDate, useMock: false); | ||
|
||
//Assert | ||
expect(result, throwsA(isA<AppUsageException>())); | ||
}); | ||
}); | ||
} |