Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/110 add more tests that were not completed #111

Merged
merged 6 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#--------------------------------------------------------------------------
#
# The make file is used to quickly run commands to help unify
# our workflow and avoid typing longer methods. Please add here useful
# our workflow and avoid typing longer commands. Please add here useful
# commands and do not forget to write a comment to explain how this command
# works and what it does. Update Readme File if necessary.
#
Expand All @@ -14,7 +14,7 @@ revert:

# Cleans the project
clean:
flutter clean && flutter pub get
fvm flutter clean && fvm flutter pub get

# Deploy will make sure fastlane release is triggered
deploy:
Expand All @@ -23,9 +23,17 @@ deploy:
# This command will clean, delete .dart_tool and generate
# classes.
generate:
flutter packages pub run build_runner build --delete-conflicting-outputs
fvm flutter packages pub run build_runner build --delete-conflicting-outputs

#This command runs fastlane
release:
fastlane release

dev:
git checkout dev

master:
git chechout master

ready:
fvm flutter analyze && fvm flutter test
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ The application has for sole purpose to track and record the data from the child
device and send it to parents. The application does not violate the `privacy policies`
settled for user, and doesn't collect data for third parties companies.


- App Icons 📱
- App Usage Metrics 📈
#### 🚀 V2.0.0

##### Planned Features:
- App Icons 📱
- App Usage Metrics 📈
- Setting page (Update Profile) 🚹
- Contact Us page📩
- Dark Mode 🌘
Expand All @@ -23,8 +25,7 @@ settled for user, and doesn't collect data for third parties companies.
- Marker image (Child's Picture) on Map 🗺
- Email follow up for weekly report 📨
- Location Tracking 📍
- Notification 🔔

- Notification 🔔


## Screenshot
Expand Down
7 changes: 4 additions & 3 deletions lib/services/app_usage_local_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class AppUsage {

static Future<List<AppUsageInfo>> getAppUsage(
DateTime startDate,
DateTime endDate,
) async {
if (Platform.isAndroid) {
DateTime endDate, {
required bool useMock,
}) async {
if (Platform.isAndroid || useMock) {
/// Convert dates to ms since epoch
var end = endDate.millisecondsSinceEpoch;
var start = startDate.millisecondsSinceEpoch;
Expand Down
3 changes: 2 additions & 1 deletion lib/services/app_usage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class AppUsageService implements AppService {
try {
var endDate = DateTime.now();
var startDate = endDate.subtract(Duration(hours: 1));
var infoList = await AppUsage.getAppUsage(startDate, endDate);
var infoList =
await AppUsage.getAppUsage(startDate, endDate, useMock: false);
_info = infoList;
} on AppUsageException catch (exception) {
debugPrint(exception.toString());
Expand Down
62 changes: 54 additions & 8 deletions test/services/app_usage_local_service_test.dart
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>()));
});
});
}
Loading