Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:Countly/countly-sdk-flutter-brid…
Browse files Browse the repository at this point in the history
…ge into staging-np
  • Loading branch information
turtledreams committed Feb 20, 2024
2 parents 4332629 + 2e6aa82 commit 16d0b51
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 132 deletions.
4 changes: 3 additions & 1 deletion .pubignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
example/android/app/google-services.json
.idea/
example/android/app/google-services.json
example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ void main() {
config.apm.setAppStartTimestampOverride(1620000000000); // set app start timestamp and it should be ignored
await Countly.initWithConfig(config);

// wait for 5 seconds. Go to background and come back to foreground manually.
// TODO(turtledreams): automate this
print('Waiting for 5 seconds...');
await tester.pump(Duration(seconds: 5));
// go foreground and background
// TODO: this automation is Android only, iOS automation is not supported yet
goBackgroundAndForeground();

Countly.appLoadingFinished(); // this should be ignored

// check if there are no apm related requests in the queue
// should be 2 begin session and 1 end session (because we manually went to background and came back to foreground)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:countly_flutter_np/countly_flutter.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../utils.dart';
Expand All @@ -7,7 +8,7 @@ import '../utils.dart';
/// 2 apm requests should be sent
/// 1 for foreground and 1 for background
/// Currently this test is not automated and F/B actions should be done manually
/// TODO: automate this
/// TODO: automate this for iOS
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

Expand All @@ -16,16 +17,19 @@ void main() {
config.apm.enableForegroundBackgroundTracking();
await Countly.initWithConfig(config);

// wait for 5 seconds. go to background manually
print('Waiting for 5 seconds... Go background');
await tester.pump(Duration(seconds: 5));
// go foreground and background
// TODO: this automation is Android only, iOS automation is not supported yet
FlutterForegroundTask.minimizeApp();
print('waiting for 2 seconds, go to background');
await tester.pump(Duration(seconds: 2));

// foreground apm request should be sent
List<String> apmReqs = await getAndPrintWantedElementsWithParamFromAllQueues('apm');
expect(apmReqs.length, 1);

print('Waiting for 5 seconds... Back to foreground');
await tester.pump(Duration(seconds: 5));
FlutterForegroundTask.launchApp();
print('waiting for 2 seconds, go to foreground');
await tester.pump(Duration(seconds: 2));

// background apm request should be sent
apmReqs = await getAndPrintWantedElementsWithParamFromAllQueues('apm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void main() {
// trigger app loaded
await Countly.appLoadingFinished();

// wait for 5 seconds. go to background manually
print('Waiting for 5 seconds...');
await tester.pump(Duration(seconds: 5));
// go foreground and background
// TODO: this automation is Android only, iOS automation is not supported yet
goBackgroundAndForeground();

// check if there is 3 apm related requests in the queue
List<String> apmRequests = await getAndPrintWantedElementsWithParamFromAllQueues('apm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void main() {
// trigger app loaded
await Countly.appLoadingFinished();

// wait for 5 seconds. go to background manually
print('Waiting for 5 seconds...');
await tester.pump(Duration(seconds: 5));
// go foreground and background
// TODO: this automation is Android only, iOS automation is not supported yet
goBackgroundAndForeground();

// check if there is 3 apm related requests in the queue
List<String> apmRequests = await getAndPrintWantedElementsWithParamFromAllQueues('apm');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Test that needs manual interaction
Currently as we don't have a way to trigger app foregraound/background action with code, the following tests need manual human interaction to go F/B when waiting log is printed:
For iOS, currently as we don't have a way to trigger app foregraound action with code, the following tests need manual human interaction to go F/B when waiting log is printed:
200, 204, 207A, 207B

## Legacy call (setRecordAppStartTime)
Expand Down
27 changes: 25 additions & 2 deletions example/integration_test/utils.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:convert';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter_foreground_task/flutter_foreground_task.dart';
import 'package:flutter_test/flutter_test.dart';

const MethodChannel _channelTest = MethodChannel('countly_flutter');

// Base config options for tests
final String SERVER_URL = 'https://xxx.count.ly';
final String APP_KEY = 'YOUR_APP_KEY';
final String APP_KEY = 'YOUR_APP_KEY'; // change this for ios tests

/// Get request queue from native side (list of strings)
Future<List<String>> getRequestQueue() async {
Expand Down Expand Up @@ -108,3 +108,26 @@ Future<Map<String, dynamic>> getApmParamsFromRequest(String request) async {
Map<String, dynamic> apmParams = json.decode(queryParams['apm']![0]);
return apmParams;
}

/// Go to background and foreground
void goBackgroundAndForeground() {
FlutterForegroundTask.minimizeApp();
if (Platform.isIOS) {
printMessageMultipleTimes('will now go to background, get ready to go foreground manually', 3);
}
sleep(Duration(seconds: 2));
FlutterForegroundTask.launchApp();
if (Platform.isIOS) {
printMessageMultipleTimes('waiting for 3 seconds, now go to foreground', 3);
}
sleep(Duration(seconds: 3));
}

/// Print message x times
/// [String message] - message
/// [int times] - times
void printMessageMultipleTimes(String message, int times) {
for (int i = 0; i < times; i++) {
print(message);
}
}
10 changes: 6 additions & 4 deletions example/lib/config_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:countly_flutter_np/countly_flutter.dart';
// where you initialize the Countly SDK.
// This is just an example of how you can create a class to hold the CountlyConfig object because we used way too many methods here.
class CountlyConfiguration {
static final String SERVER_URL = 'https://xxx.count.ly'; // MANDATORY !!
static final String SERVER_URL = 'https://your.server.ly'; // MANDATORY !!
static final String APP_KEY = 'YOUR_APP_KEY'; // MANDATORY !!

// These are optional values that you can set for the Countly SDK
Expand All @@ -30,10 +30,12 @@ class CountlyConfiguration {
};

static CountlyConfig getConfig() {
CountlyConfig config = CountlyConfig(SERVER_URL, APP_KEY)..setLoggingEnabled(true);
config.apm.enableForegroundBackgroundTracking().enableManualAppLoadedTrigger().setAppStartTimestampOverride(123456789).enableAppStartTimeTracking();

return config // Enable countly internal debugging logs
if (SERVER_URL == 'https://your.server.ly' || APP_KEY == 'YOUR_APP_KEY') {
print('Please do not use default set of app key and server url');
}

return CountlyConfig(SERVER_URL, APP_KEY)..setLoggingEnabled(true) // Enable countly internal debugging logs

// Currently only logging is enabled for debugging purposes
// Below you can see most of the methods that you can use to configure the Countly SDK
Expand Down
2 changes: 1 addition & 1 deletion example/lib/page_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';

class ViewsPage extends StatelessWidget {
final List<String> viewNames = ['viewName', 'viewName1'];
final List<String> viewIDs = ['temp_id_1', 'temp_id_2'];//set initial temporary values
final List<String> viewIDs = ['temp_id_1', 'temp_id_2']; //set initial temporary values

Future<void> recordViewHome() async {
Map<String, Object> segments = {'Cats': 123, 'Moons': 9.98, 'Moose': 'Deer'};
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
flutter_foreground_task: 6.0.0+1

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
25 changes: 0 additions & 25 deletions example/test/widget_test.dart

This file was deleted.

19 changes: 0 additions & 19 deletions integration_test/foo/bar_test.dart

This file was deleted.

37 changes: 0 additions & 37 deletions integration_test/test_utility.dart

This file was deleted.

3 changes: 2 additions & 1 deletion lib/src/remote_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'experiment_information.dart';

/// REMOTE CONFIG / AB TESTING
class RCData {
Object? value; /// stores the RC value
/// stores the RC value
Object? value;
bool isCurrentUsersData;
RCData(this.value, this.isCurrentUsersData);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/user_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ abstract class UserProfile {
/// [String value] - value to add to array
Future<void> pushUnique(String key, String value);

/// Create array property, if property does not exist and remove value from array
/// You can only use it on array properties or properties that do not exist yet
/// If a custom property exists and its value is an array, then this will remove the specified value from that array.
/// You can only use it on array properties that exist.
/// [String key] - property name for array property
/// [String value] - value to remove from array
Future<void> pull(String key, String value);
Expand Down
6 changes: 1 addition & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ platforms:
ios:

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"
flutter: ">=2.0.0"

dependencies:
Expand All @@ -21,10 +21,6 @@ dependencies:

dev_dependencies:
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
integration_test:
sdk: flutter

flutter:
plugin:
Expand Down
18 changes: 0 additions & 18 deletions test/countly_flutter_test.dart

This file was deleted.

0 comments on commit 16d0b51

Please sign in to comment.