Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

implement e2e detox testing

ammarahm-edfc3ae69edb5e
diff --git a/apps/mobile/.detoxrc.json b/apps/mobile/.detoxrc.json
new file mode 100644
index 000000000..b28b04a6c
--- /dev/null
+++ b/apps/mobile/.detoxrc.json
@@ -0,0 +1,22 @@
+{
+ "testRunner": "jest",
+ "runnerConfig": "e2e/config.json",
+ "configurations": {
+ "ios": {
+ "type": "ios.simulator",
+ "binaryPath": "SPECIFY_PATH_TO_YOUR_APP_BINARY",
+ "device": {
+ "type": "iPhone 11"
+ }
+ },
+ "android.emu.debug": {
+ "binaryPath": "android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk",
+ "testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
+ "build": "cd android && ./gradlew app:assembleDebug app:assembleAndroidTest -DtestBuildType=debug && cd ..",
+ "type": "android.attached",
+ "device":{
+ "avdName":"LMG710ULM3d3678f0"
+ }
+ }
+ }
+}
diff --git a/apps/mobile/android/app/src/androidTest/java/com/streetwriters/notesnook/DetoxTest.java b/apps/mobile/android/app/src/androidTest/java/com/streetwriters/notesnook/DetoxTest.java
new file mode 100644
index 000000000..204e62dc6
--- /dev/null
+++ b/apps/mobile/android/app/src/androidTest/java/com/streetwriters/notesnook/DetoxTest.java
@@ -0,0 +1,31 @@
+package com.streetwriters.notesnook;
+
+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
+ // <activity> in AndroidManifest.xml
+ public ActivityTestRule<MainActivity> 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 = (com.streetwriters.notesnook.BuildConfig.DEBUG ? 180 : 60);
+
+ Detox.runTests(mActivityRule, detoxConfig);
+ }
+}
\ No newline at end of file
diff --git a/apps/mobile/android/app/src/main/AndroidManifest.xml b/apps/mobile/android/app/src/main/AndroidManifest.xml
index 01a6fb481..6d9cfcf2c 100644
--- a/apps/mobile/android/app/src/main/AndroidManifest.xml
+++ b/apps/mobile/android/app/src/main/AndroidManifest.xml
@@ -12,6 +12,7 @@
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:requestLegacyExternalStorage="true"
+ android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
diff --git a/apps/mobile/android/app/src/main/java/com/notesnook/MainActivity.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.java
similarity index 100%
rename from apps/mobile/android/app/src/main/java/com/notesnook/MainActivity.java
rename to apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainActivity.java
diff --git a/apps/mobile/android/app/src/main/java/com/notesnook/MainApplication.java b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
similarity index 95%
rename from apps/mobile/android/app/src/main/java/com/notesnook/MainApplication.java
rename to apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
index 96c67682d..6d9440455 100644
--- a/apps/mobile/android/app/src/main/java/com/notesnook/MainApplication.java
+++ b/apps/mobile/android/app/src/main/java/com/streetwriters/notesnook/MainApplication.java
@@ -10,8 +10,9 @@ import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
+import androidx.multidex.MultiDexApplication;
-public class MainApplication extends Application implements ReactApplication {
+public class MainApplication extends MultiDexApplication implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
diff --git a/apps/mobile/android/app/src/main/res/xml/network_security_config.xml b/apps/mobile/android/app/src/main/res/xml/network_security_config.xml
new file mode 100644
index 000000000..c7755e76f
--- /dev/null
+++ b/apps/mobile/android/app/src/main/res/xml/network_security_config.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<network-security-config>
+ <domain-config cleartextTrafficPermitted="true">
+ <domain includeSubdomains="true">10.0.2.2</domain>
+ <domain includeSubdomains="true">localhost</domain>
+ </domain-config>
+</network-security-config>
\ No newline at end of file
diff --git a/apps/mobile/e2e/config.json b/apps/mobile/e2e/config.json
new file mode 100644
index 000000000..5467a9303
--- /dev/null
+++ b/apps/mobile/e2e/config.json
@@ -0,0 +1,8 @@
+{
+ "testEnvironment": "./environment",
+ "testRunner": "jest-circus/runner",
+ "testTimeout": 120000,
+ "testRegex": "\\.e2e\\.js$",
+ "reporters": ["detox/runners/jest/streamlineReporter"],
+ "verbose": true
+}
diff --git a/apps/mobile/e2e/environment.js b/apps/mobile/e2e/environment.js
new file mode 100644
index 000000000..ad46bec5f
--- /dev/null
+++ b/apps/mobile/e2e/environment.js
@@ -0,0 +1,23 @@
+const {
+ DetoxCircusEnvironment,
+ SpecReporter,
+ WorkerAssignReporter,
+} = require('detox/runners/jest-circus');
+
+class CustomDetoxEnvironment extends DetoxCircusEnvironment {
+ constructor(config) {
+ super(config);
+
+ // Can be safely removed, if you are content with the default value (=300000ms)
+ this.initTimeout = 300000;
+
+ // This takes care of generating status logs on a per-spec basis. By default, Jest only reports at file-level.
+ // This is strictly optional.
+ this.registerListeners({
+ SpecReporter,
+ WorkerAssignReporter,
+ });
+ }
+}
+
+module.exports = CustomDetoxEnvironment;
diff --git a/apps/mobile/e2e/firstTest.e2e.js b/apps/mobile/e2e/firstTest.e2e.js
new file mode 100644
index 000000000..93cfacba9
--- /dev/null
+++ b/apps/mobile/e2e/firstTest.e2e.js
@@ -0,0 +1,10 @@
+
+ it('app loaded', async () => {
+ await expect(element(by.id('mobile_main_view'))).toBeVisible();
+ })
+
+ it('open_editor', async () => {
+ await expect(element(by.id('mobile_main_view'))).toBeVisible();
+ })
+
+