Skip to content

Commit

Permalink
chore: detox configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed Feb 12, 2024
1 parent d0144f7 commit 546b4a9
Show file tree
Hide file tree
Showing 13 changed files with 595 additions and 23 deletions.
53 changes: 53 additions & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
$0: "jest",
config: "e2e/detox/jest.config.js",
},
jest: {
setupTimeout: 120000,
},
},
apps: {
"ios.debug": {
type: "ios.app",
binaryPath: "ios/build/Build/Products/Debug-iphonesimulator/Blink.app",
build:
"xcodebuild -workspace ios/GaloyApp.xcworkspace -scheme GaloyApp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
},
"android.debug": {
type: "android.apk",
binaryPath: "android/app/build/outputs/apk/debug/app-universal-debug.apk",
testBinaryPath:
"android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
build:
"cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug",
reversePorts: [8081],
},
},
devices: {
simulator: {
type: "ios.simulator",
device: {
type: "iPhone SE (3rd generation)",
},
},
emulator: {
type: "android.emulator",
device: {
avdName: "Pixel_API_29_AOSP",
},
},
},
configurations: {
"ios.sim.debug": {
device: "simulator",
app: "ios.debug",
},
"android.emu.debug": {
device: "emulator",
app: "android.debug",
},
},
}
6 changes: 6 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 681
versionName "2.2.225"
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

// https://github.com/react-native-community/discussions-and-proposals/issues/602
Expand Down Expand Up @@ -120,6 +122,7 @@ android {
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
}
}

Expand Down Expand Up @@ -157,6 +160,9 @@ dependencies {
} else {
implementation jscFlavor
}

androidTestImplementation('com.wix:detox:+')
implementation 'androidx.appcompat:appcompat:1.1.0'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Expand Down
29 changes: 29 additions & 0 deletions android/app/src/androidTest/java/com/galoyapp/DetoxTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.galoyapp; // (1)

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 // (2)
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 = (BuildConfig.DEBUG ? 180 : 60);

Detox.runTests(mActivityRule, detoxConfig);
}
}
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
android:roundIcon="@mipmap/ic_launcher"
android:allowBackup="false"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/BootTheme"> <!-- Replace @style/AppTheme with @style/BootTheme -->
<activity
android:name=".MainActivity"
Expand Down
7 changes: 7 additions & 0 deletions android/app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -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>
11 changes: 11 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@ buildscript {

classpath 'com.google.gms:google-services:4.3.15' // firebase
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}

allprojects {
repositories {
google()
mavenCentral()
maven {
url "$rootDir/../node_modules/detox/Detox-android"
}
}
}
71 changes: 71 additions & 0 deletions e2e/detox/01-phone-flow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { expect } from "detox"

import { timeout, otp, ALICE_PHONE } from "./utils/config"

import { i18nObject } from "../../app/i18n/i18n-util"
import { loadLocale } from "../../app/i18n/i18n-util.sync"

const tap = async (match: Detox.NativeMatcher) => {
const el = element(match)
await waitFor(el).toBeVisible().withTimeout(timeout)
await el.tap()
}

describe("Login with Phone Flow", () => {
loadLocale("en")
const LL = i18nObject("en")

beforeAll(async () => {
await device.launchApp()
})

it("set environment", async () => {
const buildBtn = element(by.id("logo-button"))
// Wait for 2 mins because metro bundler might not finish sync
await waitFor(buildBtn).toBeVisible().withTimeout(1200000)
await buildBtn.multiTap(3)

const logoutBtn = element(by.id("logout button"))
await expect(logoutBtn).toBeVisible()

const envBtn = element(by.id("Local Button"))
const developerScreenSV = by.id("developer-screen-scroll-view")

await waitFor(envBtn)
.toBeVisible()
.whileElement(developerScreenSV)
.scroll(400, "down", NaN, 0.85)
await envBtn.tap()

const saveChangesBtn = element(by.id("Save Changes"))
await saveChangesBtn.tap()

const stagingInstanceText = element(by.text(`Galoy Instance: Local`))
await waitFor(stagingInstanceText).toBeVisible().withTimeout(10000)

await tap(by.id("Back"))
})

it("login as an user", async () => {
await tap(by.id(LL.GetStartedScreen.createAccount()))

const telephoneInput = element(by.id("telephoneNumber"))
await waitFor(telephoneInput).toBeVisible().withTimeout(timeout)
await telephoneInput.clearText()
await telephoneInput.typeText(ALICE_PHONE)
await tap(by.id(LL.PhoneLoginInitiateScreen.sms()))

const otpInput = element(by.id("oneTimeCode"))
try {
await waitFor(otpInput).toBeVisible().withTimeout(timeout)
await otpInput.clearText()
await otpInput.typeText(otp)
} catch {
/* empty because sometimes the page just moves to the next page coz 000000 is default */
}

await waitFor(element(by.text(LL.HomeScreen.myAccounts())))
.toBeVisible()
.withTimeout(timeout)
})
})
13 changes: 13 additions & 0 deletions e2e/detox/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
preset: "ts-jest",
rootDir: "..",
testMatch: ["<rootDir>/detox/**/*.test.ts"],
testTimeout: 120000,
maxWorkers: 1,
globalSetup: "detox/runners/jest/globalSetup",
globalTeardown: "detox/runners/jest/globalTeardown",
reporters: ["detox/runners/jest/reporter"],
testEnvironment: "detox/runners/jest/testEnvironment",
verbose: true,
}
14 changes: 14 additions & 0 deletions e2e/detox/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { config } from "dotenv"
import path from "path"

config({ path: path.join(__dirname, "../../../dev/.env") })

if (!process.env.ALICE_PHONE || !process.env.BOB_PHONE) {
throw new Error("Development environment environment configuration is incorrect")
}

export const timeout = 3000
export const otp = process.env.GALOY_STAGING_GLOBAL_OTP || "000000"

export const ALICE_PHONE = process.env.ALICE_PHONE
export const BOB_PHONE = process.env.BOB_PHONE
12 changes: 10 additions & 2 deletions ios/GaloyApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,11 @@
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
};
Expand Down Expand Up @@ -623,7 +627,11 @@
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "$(inherited)";
OTHER_CPLUSPLUSFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ SPEC CHECKSUMS:
AppCheckCore: 4687c03428947d5b26a6bf9bb5566b39f5473bf1
boost: 57d2868c099736d80fcd648bf211b4431e51a558
BVLinearGradient: 880f91a7854faff2df62518f0281afb1c60d49a3
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: 5fbbff1d7734827299274638deb8ba3024f6c597
FBReactNativeSpec: 638095fe8a01506634d77b260ef8a322019ac671
Firebase: 414ad272f8d02dfbf12662a9d43f4bba9bec2a06
Expand All @@ -972,7 +972,7 @@ SPEC CHECKSUMS:
FirebaseSessions: e5f4caa188dc8bc6142abc974355be75b042215e
FirebaseSharedSwift: f34eeb7d3ea87a34497629b6ca41657beadef76a
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 035f1e36e53b355cf70f6434d161b36e7d21fecd
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
GoogleAppMeasurement: 70ce9aa438cff1cfb31ea3e660bcc67734cb716e
GoogleDataTransport: 57c22343ab29bc686febbf7cbb13bad167c2d8fe
GoogleUtilities: 0759d1a57ebb953965c2dfe0ba4c82e95ccc2e34
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"android:buildDebug": "yarn android:prepareAssets && ./android/gradlew -b ./android/build.gradle assembleDebug -Dorg.gradle.jvmargs='-Xmx4g -XX:MaxPermSize=512m'",
"ios:prepareAssets": "react-native bundle --entry-file index.js --bundle-output ./ios/main.jsbundle --assets-dest ./ios/ --platform ios --dev false",
"bundle-visualizer": "yarn run react-native-bundle-visualizer",
"splash": "yarn react-native generate-bootsplash --background-color \"#000\" --logo-width 300 app/assets/logo/app-logo-dark.svg"
"splash": "yarn react-native generate-bootsplash --background-color \"#000\" --logo-width 300 app/assets/logo/app-logo-dark.svg",
"e2e:build": "detox build --configuration",
"e2e:test": "detox test --configuration"
},
"dependencies": {
"@apollo/client": "3.9.0-alpha.5",
Expand Down Expand Up @@ -211,6 +213,8 @@
"browserstack-local": "^1.5.1",
"cross-fetch": "^3.1.6",
"csv-parse": "^5.3.5",
"detox": "^20.18.1",
"dotenv": "^16.4.2",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
Loading

0 comments on commit 546b4a9

Please sign in to comment.