From f69b82dae96774d3d1b972ab880ccc74cb426684 Mon Sep 17 00:00:00 2001
From: Anant Bhasin <38764067+aKn1ghtOut@users.noreply.github.com>
Date: Thu, 2 Dec 2021 18:49:15 +0530
Subject: [PATCH] Tests: Make Detox work on Android (#3051)
---
.../__snapshots__/Storyshots.test.js.snap | 3 +
android/app/build.gradle | 18 +++
.../chat/rocket/reactnative/DetoxTest.java | 32 ++++
.../e2e/res/xml/network_security_config.xml | 10 ++
android/build.gradle | 4 +
app/containers/ActionSheet/ActionSheet.tsx | 6 +-
app/containers/Button/index.tsx | 1 +
app/containers/message/Content.tsx | 6 +-
app/definition/ITeam.js | 2 +-
app/views/DirectoryView/Options.tsx | 8 +-
app/views/RoomActionsView/index.js | 1 -
app/views/SidebarView/SidebarItem.tsx | 2 +-
e2e/helpers/app.js | 103 +++++++++---
e2e/tests/assorted/01-e2eencryption.spec.js | 69 +++++---
e2e/tests/assorted/02-broadcast.spec.js | 6 +-
e2e/tests/assorted/03-profile.spec.js | 17 +-
e2e/tests/assorted/04-setting.spec.js | 10 +-
e2e/tests/assorted/05-joinpublicroom.spec.js | 38 ++---
e2e/tests/assorted/06-status.spec.js | 3 +-
e2e/tests/assorted/07-changeserver.spec.js | 7 +-
.../assorted/08-joinprotectedroom.spec.js | 22 ++-
.../assorted/09-joinfromdirectory.spec.js | 12 +-
e2e/tests/assorted/10-deleteserver.spec.js | 12 +-
e2e/tests/assorted/11-deeplinking.spec.js | 43 ++---
e2e/tests/assorted/12-i18n.spec.js | 10 +-
e2e/tests/assorted/13-display-pref.spec.js | 8 +-
e2e/tests/init.js | 2 +
e2e/tests/onboarding/01-onboarding.spec.js | 23 +--
.../onboarding/03-forgotpassword.spec.js | 9 +-
e2e/tests/onboarding/04-createuser.spec.js | 13 +-
e2e/tests/onboarding/05-login.spec.js | 9 +-
e2e/tests/onboarding/06-roomslist.spec.js | 4 +-
.../onboarding/07-server-history.spec.js | 4 +-
e2e/tests/room/01-createroom.spec.js | 31 +++-
e2e/tests/room/02-room.spec.js | 150 +++++++++++-------
e2e/tests/room/03-roomactions.spec.js | 147 ++++++++---------
e2e/tests/room/04-discussion.spec.js | 15 +-
e2e/tests/room/05-threads.spec.js | 86 +++++-----
e2e/tests/room/06-createdmgroup.spec.js | 6 +-
e2e/tests/room/07-markasunread.spec.js | 10 +-
e2e/tests/room/08-roominfo.spec.js | 103 +++++-------
e2e/tests/room/09-jumptomessage.spec.js | 145 ++++++++++-------
e2e/tests/team/01-createteam.spec.js | 23 ++-
e2e/tests/team/02-team.spec.js | 62 ++++++--
e2e/tests/team/03-moveconvert.spec.js | 37 +++--
package.json | 12 ++
46 files changed, 837 insertions(+), 507 deletions(-)
create mode 100644 android/app/src/androidTest/java/chat/rocket/reactnative/DetoxTest.java
create mode 100644 android/app/src/e2e/res/xml/network_security_config.xml
diff --git a/__tests__/__snapshots__/Storyshots.test.js.snap b/__tests__/__snapshots__/Storyshots.test.js.snap
index 62fa05a8..f85a69dd 100644
--- a/__tests__/__snapshots__/Storyshots.test.js.snap
+++ b/__tests__/__snapshots__/Storyshots.test.js.snap
@@ -1419,6 +1419,7 @@ Array [
@@ -294,6 +310,8 @@ dependencies {
implementation "com.tencent:mmkv-static:1.2.1"
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation "com.squareup.okhttp3:okhttp-urlconnection:4.9.0"
+ androidTestImplementation('com.wix:detox:+') { transitive = true }
+ androidTestImplementation 'junit:junit:4.12'
}
// Run this once to be able to run the application with BUCK
diff --git a/android/app/src/androidTest/java/chat/rocket/reactnative/DetoxTest.java b/android/app/src/androidTest/java/chat/rocket/reactnative/DetoxTest.java
new file mode 100644
index 00000000..1ab897cd
--- /dev/null
+++ b/android/app/src/androidTest/java/chat/rocket/reactnative/DetoxTest.java
@@ -0,0 +1,32 @@
+// Replace "com.example" here and below with your app's package name from the top of MainActivity.java
+package chat.rocket.reactnative;
+
+import com.wix.detox.Detox;
+import com.wix.detox.config.DetoxConfig;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.LargeTest;
+import androidx.test.rule.ActivityTestRule;
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class DetoxTest {
+ @Rule
+ // Replace 'MainActivity' with the value of android:name entry in
+ // in AndroidManifest.xml
+ public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
+
+ @Test
+ public void runDetoxTests() {
+ DetoxConfig detoxConfig = new DetoxConfig();
+ detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
+ detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
+ detoxConfig.rnContextLoadTimeoutSec = (chat.rocket.reactnative.BuildConfig.DEBUG ? 180 : 60);
+
+ Detox.runTests(mActivityRule, detoxConfig);
+ }
+}
diff --git a/android/app/src/e2e/res/xml/network_security_config.xml b/android/app/src/e2e/res/xml/network_security_config.xml
new file mode 100644
index 00000000..95aaf3c1
--- /dev/null
+++ b/android/app/src/e2e/res/xml/network_security_config.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/android/build.gradle b/android/build.gradle
index 31650a07..626e7564 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -53,6 +53,10 @@ allprojects {
url("$rootDir/../node_modules/jsc-android/dist")
}
+ maven {
+ url "$rootDir/../node_modules/detox/Detox-android"
+ }
+
maven {
url jitsi_url
}
diff --git a/app/containers/ActionSheet/ActionSheet.tsx b/app/containers/ActionSheet/ActionSheet.tsx
index 35e69c70..11414150 100644
--- a/app/containers/ActionSheet/ActionSheet.tsx
+++ b/app/containers/ActionSheet/ActionSheet.tsx
@@ -124,7 +124,11 @@ const ActionSheet = React.memo(
const renderFooter = () =>
data?.hasCancel ? (
-