Skip to content

Commit

Permalink
feat(android): remove deprecated native IdlePolicyConfig (#3332)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
d4vidi authored and noomorph committed Apr 27, 2022
1 parent bdfe167 commit 914f115
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 62 deletions.
61 changes: 2 additions & 59 deletions detox/android/detox/src/full/java/com/wix/detox/Detox.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import com.wix.detox.config.DetoxConfig;
import com.wix.detox.espresso.UiControllerSpy;

import java.util.concurrent.TimeUnit;

import androidx.annotation.NonNull;
import androidx.test.espresso.IdlingPolicies;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

Expand Down Expand Up @@ -77,28 +74,6 @@ public final class Detox {
private static final LaunchIntentsFactory sIntentsFactory = new LaunchIntentsFactory();
private static ActivityTestRule sActivityTestRule;

/**
* Specification of values to use for Espresso's {@link IdlingPolicies} timeouts.
* <br/>Overrides Espresso's defaults as they tend to be too short (e.g. when running a heavy-load app
* on suboptimal CI machines).
*
* @deprecated Use {@link com.wix.detox.config.DetoxConfig}.
*/
@Deprecated
public static class DetoxIdlePolicyConfig {
/** Directly binds to {@link IdlingPolicies#setMasterPolicyTimeout(long, TimeUnit)}. Applied in seconds. */
public Integer masterTimeoutSec = 120;
/** Directly binds to {@link IdlingPolicies#setIdlingResourceTimeout(long, TimeUnit)}. Applied in seconds. */
public Integer idleResourceTimeoutSec = 60;

private com.wix.detox.config.DetoxIdlePolicyConfig toNewConfig() {
com.wix.detox.config.DetoxIdlePolicyConfig newConfig = new com.wix.detox.config.DetoxIdlePolicyConfig();
newConfig.masterTimeoutSec = masterTimeoutSec;
newConfig.idleResourceTimeoutSec = idleResourceTimeoutSec;
return newConfig;
}
}

private Detox() {
}

Expand Down Expand Up @@ -128,20 +103,6 @@ public static void runTests(ActivityTestRule activityTestRule, DetoxConfig detox
runTests(activityTestRule, getAppContext(), detoxConfig);
}

/**
* Same as the default {@link #runTests(ActivityTestRule)} method, but allows for the explicit specification of
* a custom idle-policy configuration. Note: review {@link DetoxIdlePolicyConfig} for defaults.
*
* @param idlePolicyConfig The custom idle-policy configuration to pass in; Will be applied into Espresso via
* the {@link IdlingPolicies} API.
*
* @deprecated Use {@link #runTests(ActivityTestRule, DetoxConfig)}
*/
@Deprecated
public static void runTests(ActivityTestRule activityTestRule, DetoxIdlePolicyConfig idlePolicyConfig) {
runTests(activityTestRule, getAppContext(), idlePolicyConfig);
}

/**
* <p>
* Use this method only if you have a React Native application and it
Expand All @@ -161,24 +122,6 @@ public static void runTests(ActivityTestRule activityTestRule, @NonNull final Co
runTests(activityTestRule, context, new DetoxConfig());
}

/**
* Same as {@link #runTests(ActivityTestRule, Context)}, but allows for the explicit specification of
* a custom idle-policy configuration. Note: review {@link DetoxIdlePolicyConfig} for defaults.
*
*
* @param idlePolicyConfig The custom idle-policy configuration to pass in; Will be applied into Espresso via
* the {@link IdlingPolicies} API.
*
* @deprecated Use {@link #runTests(ActivityTestRule, Context, DetoxConfig)}
*/
@Deprecated
public static void runTests(ActivityTestRule activityTestRule, @NonNull final Context context, DetoxIdlePolicyConfig idlePolicyConfig) {
DetoxConfig config = new DetoxConfig();
config.idlePolicyConfig = idlePolicyConfig.toNewConfig();

runTests(activityTestRule, context, config);
}

/**
* Same as {@link #runTests(ActivityTestRule, Context)}, but allows for the explicit specification of
* various configurations. Note: review {@link DetoxConfig} for defaults.
Expand Down Expand Up @@ -214,7 +157,7 @@ public static void startActivityFromUrl(String url) {
}

public static void startActivityFromNotification(String dataFilePath) {
Bundle notificationData = new NotificationDataParser(dataFilePath).parseNotificationData();
Bundle notificationData = new NotificationDataParser(dataFilePath).toBundle();
Intent intent = sIntentsFactory.intentWithNotificationData(getAppContext(), notificationData, false);
launchActivitySync(intent);
}
Expand All @@ -225,7 +168,7 @@ private static Intent extractInitialIntent() {
if (sLaunchArgs.hasUrlOverride()) {
intent = sIntentsFactory.intentWithUrl(sLaunchArgs.getUrlOverride(), true);
} else if (sLaunchArgs.hasNotificationPath()) {
Bundle notificationData = new NotificationDataParser(sLaunchArgs.getNotificationPath()).parseNotificationData();
Bundle notificationData = new NotificationDataParser(sLaunchArgs.getNotificationPath()).toBundle();
intent = sIntentsFactory.intentWithNotificationData(getAppContext(), notificationData, true);
} else {
intent = sIntentsFactory.cleanIntent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import com.wix.detox.common.TextFileReader
import org.json.JSONObject

internal class NotificationDataParser(private val notificationPath: String) {
fun parseNotificationData(): Bundle {
val rawData = readNotificationData()
fun toBundle(): Bundle {
val rawData = readNotificationFromFile()
val json = JSONObject(rawData)
val payload = json.getJSONObject("payload")
return JsonConverter(payload).toBundle()
}

private fun readNotificationData()
private fun readNotificationFromFile()
= TextFileReader(notificationPath).read()
}

0 comments on commit 914f115

Please sign in to comment.