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

Remove deprecated native IdlePolicyConfig #3332

Merged
merged 1 commit into from Apr 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 2 additions & 59 deletions detox/android/detox/src/full/java/com/wix/detox/Detox.java
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
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()
}