Cleaned up code. Implemented proper abstraction

This commit is contained in:
Anant Bhasin 2021-06-28 02:17:57 +05:30
parent eb8fb69639
commit 0465f0ae87
38 changed files with 73 additions and 125 deletions

View File

@ -1,52 +0,0 @@
name: Android Detox
on: [pull_request]
jobs:
build-android-experimental-play-debug:
runs-on: macos-latest
timeout-minutes: 240
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Node
uses: actions/setup-node@v1
- name: Install JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Download Android Emulator Image
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Nexus 5X" -k 'system-images;android-29;google_apis;x86'
$ANDROID_HOME/emulator/emulator -list-avds
- name: Install node_modules
run: |
yarn --frozen-lockfile --network-timeout 100000
- name: Build for detox
run: |
yarn detox build e2e/tests --configuration android.experimental.play.emu.debug
yarn start &
- name: Android Emulator
timeout-minutes: 10
continue-on-error: true
run: |
echo "Starting emulator"
nohup $ANDROID_HOME/emulator/emulator -avd emu -no-audio -no-snapshot -no-window &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
$ANDROID_HOME/platform-tools/adb devices
echo "Emulator started"
- name: Android Detox
run: yarn detox test e2e/tests --configuration android.experimental.play.emu.debug

View File

@ -177,7 +177,6 @@ android {
release {
minifyEnabled enableProguardInReleaseBuilds
setProguardFiles([getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'])
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
signingConfig signingConfigs.release
if (!isFoss) {
firebaseCrashlytics {
@ -206,6 +205,10 @@ android {
dimension = "app"
buildConfigField "boolean", "IS_OFFICIAL", "false"
}
e2e {
dimension = "app"
buildConfigField "boolean", "IS_OFFICIAL", "true"
}
foss {
dimension = "type"
buildConfigField "boolean", "FDROID_BUILD", "true"
@ -233,6 +236,16 @@ android {
java.srcDirs = ['src/main/java', 'src/play/java']
manifest.srcFile 'src/play/AndroidManifest.xml'
}
e2ePlayDebug {
java.srcDirs = ['src/main/java', 'src/play/java']
res.srcDirs = ['src/official/res']
manifest.srcFile 'src/play/AndroidManifest.xml'
}
e2ePlayRelease {
java.srcDirs = ['src/main/java', 'src/play/java']
res.srcDirs = ['src/official/res']
manifest.srcFile 'src/play/AndroidManifest.xml'
}
}
applicationVariants.all { variant ->

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
<certificates src="user"
tools:ignore="AcceptsUserCertificates" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>

View File

@ -7,8 +7,4 @@
tools:ignore="AcceptsUserCertificates" />
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>

View File

@ -34,9 +34,4 @@ APPLICATION_ID=chat.rocket.reactnative
# App properties
VERSIONCODE=999999999
BugsnagAPIKey=""
KEYSTORE=release.keystore
KEY_PASSWORD=password
KEY_ALIAS=rocketchat_test_keystore
KEYSTORE_PASSWORD=password
BugsnagAPIKey=""

View File

@ -17,7 +17,10 @@ function runCommand(command) {
});
}
// The Spell Checker and the autofill service introduce additional flakiness, and appear over other elements.
// So, we disable them before running the tests.
exports.prepareAndroid = async () => {
if(device.getPlatform() !== 'android') return;
await runCommand('adb shell settings put secure spell_checker_enabled 0');
await runCommand('adb shell settings put secure autofill_service null');
}
@ -31,7 +34,7 @@ exports.launchWithLanguage = async (language, countryCode="US", launchArgs=defau
{
await runCommand('adb root');
await runCommand(`adb shell "setprop persist.sys.locale ${language}-${countryCode}; setprop ctl.restart zygote"`);
await sleep(5000);
await sleep(20000);
await device.launchApp(launchArgs);
}
else

View File

@ -51,7 +51,7 @@ describe('E2E Encryption', () => {
before(async () => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
({ alertButtonType, scrollViewType } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(testuser.username, testuser.password);

View File

@ -13,7 +13,7 @@ const otheruser = data.users.alternate
describe('Broadcast room', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(testuser.username, testuser.password);
});

View File

@ -24,7 +24,7 @@ describe('Profile screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
({ textInputType, scrollViewType } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(profileChangeUser.username, profileChangeUser.password);

View File

@ -14,7 +14,7 @@ describe('Settings screen', () => {
let alertButtonType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
({ alertButtonType } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(testuser.username, testuser.password);

View File

@ -25,7 +25,7 @@ describe('Join public room', () => {
let scrollViewType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
({ scrollViewType } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(testuser.username, testuser.password);
@ -166,7 +166,7 @@ describe('Join public room', () => {
await expect(element(by.text('Yes, leave it!'))).toBeVisible();
await element(by.text('Yes, leave it!')).tap();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);
await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeNotVisible().withTimeout(60000);
// await waitFor(element(by.id(`rooms-list-view-item-${ room }`))).toBeNotVisible().withTimeout(60000);
});
});
});

View File

@ -14,7 +14,7 @@ async function waitForToast() {
describe('Status screen', () => {
before(async () => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(testuser.username, testuser.password);

View File

@ -15,7 +15,7 @@ const reopenAndCheckServer = async(server) => {
describe('Change server', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);

View File

@ -23,7 +23,7 @@ async function openJoinCode() {
describe('Join protected room', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(testuser.username, testuser.password);
await navigateToRoom();

View File

@ -19,7 +19,7 @@ async function navigateToRoom(search) {
describe('Join room from directory', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(testuser.username, testuser.password);
});

View File

@ -11,7 +11,7 @@ describe('Delete server', () => {
let scrollViewType, alertButtonType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
({ alertButtonType, scrollViewType } = platformTypes[device.getPlatform()]);
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);

View File

@ -35,7 +35,7 @@ describe('Deep linking', () => {
delete: true,
url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=123${amp}token=abc`),
});
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await waitFor(element(by.text('You\'ve been logged out by the server. Please log in again.'))).toExist().withTimeout(10000); // TODO: we need to improve this message
});

View File

@ -27,7 +27,7 @@ describe('i18n', () => {
...defaultLaunchArgs,
delete: true
});
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(20000);
await expect(element(by.id('join-workspace').and(by.label('Join a workspace')))).toBeVisible();
await expect(element(by.id('create-workspace-button').and(by.label('Create a new workspace')))).toBeVisible();

View File

@ -7,7 +7,7 @@ const { prepareAndroid } = require('../../helpers/platformFunctions');
describe('Onboarding', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(20000);
});

View File

@ -9,7 +9,7 @@ describe('Legal screen', () => {
describe('From Login', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
});

View File

@ -8,7 +8,7 @@ const { prepareAndroid } = require('../../helpers/platformFunctions');
describe('Forgot password screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await element(by.id('login-view-forgot-password')).tap();
await waitFor(element(by.id('forgot-password-view'))).toExist().withTimeout(2000);

View File

@ -8,7 +8,7 @@ const data = require('../../data');
describe('Create user screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToRegister();
});

View File

@ -8,7 +8,7 @@ const data = require('../../data');
describe('Login screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
});

View File

@ -9,7 +9,7 @@ describe('Rooms list screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password)
});

View File

@ -8,7 +8,7 @@ const data = require('../../data');
describe('Server history', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
});
describe('Usage', () => {

View File

@ -10,7 +10,7 @@ const { prepareAndroid } = require('../../helpers/platformFunctions');
describe('Create room screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
});

View File

@ -16,7 +16,7 @@ describe('Room screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await navigateToRoom(mainRoom);

View File

@ -42,7 +42,7 @@ describe('Room actions screen', () => {
let alertButtonType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
({ alertButtonType } = platformTypes[device.getPlatform()]);

View File

@ -19,7 +19,7 @@ describe('Discussion', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
({ scrollViewType } = platformTypes[device.getPlatform()]);

View File

@ -7,7 +7,7 @@ const { prepareAndroid } = require('../../helpers/platformFunctions');
async function navigateToRoom(roomName) {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await searchRoom(`${ roomName }`);

View File

@ -10,7 +10,7 @@ const { prepareAndroid } = require('../../helpers/platformFunctions');
describe('Group DM', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
});

View File

@ -17,7 +17,7 @@ describe('Mark as unread', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await navigateToRoom(user);

View File

@ -35,7 +35,7 @@ describe('Room info screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
});

View File

@ -34,7 +34,7 @@ async function waitForLoading() {
describe('Room', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.adminUser, data.adminPassword);
});

View File

@ -10,7 +10,7 @@ const teamName = `team-${ data.random }`;
describe('Create team screen', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
});

View File

@ -45,7 +45,7 @@ describe('Team', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
await navigateToRoom(team);

View File

@ -39,7 +39,7 @@ async function navigateToRoomActions(room) {
describe('Move/Convert Team', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
if(device.getPlatform() == 'android') await prepareAndroid();
await prepareAndroid();
await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password);
});

View File

@ -17,10 +17,8 @@
"generate-source-maps-ios": "react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios-release.bundle --sourcemap-output ios-release.bundle.map",
"generate-source-maps-android": "bugsnag-sourcemaps",
"postinstall": "patch-package && jetify",
"detoxAD": "detox build -c android.experimental.play.dev.debug && detox test -c android.experimental.play.dev.debug",
"detoxAR": "detox build -c android.experimental.play.dev.release && detox test -c android.experimental.play.dev.release",
"detoxADEmu": "detox build -c android.experimental.play.emu.debug && detox test -c android.experimental.play.emu.debug",
"detoxAREmu": "detox build -c android.experimental.play.emu.release && detox test -c android.experimental.play.emu.release"
"e2e:android-debug": "detox build -c and.emu.debug && detox test -c and.emu.debug",
"e2e:android-release": "detox build -c and.emu.release && detox test -c and.emu.release"
},
"husky": {
"hooks": {
@ -192,13 +190,6 @@
"detox": {
"runner-config": "e2e/.mocharc.json",
"specs": "e2e/tests",
"apps": {
"android.experimental.play.debug": {
"type": "android.apk",
"binaryPath": "android/app/build/outputs/apk/experimentalPlay/debug/app-Experimental-Play-debug.apk",
"build": "cd android && ./gradlew assembleExperimentalPlayDebug assembleExperimentalPlayAndroidTest -DtestBuildType=debug && cd .."
}
},
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Rocket.Chat Experimental.app",
@ -230,29 +221,17 @@
}
}
},
"android.experimental.play.emu.debug": {
"and.emu.debug": {
"device": "Pixel_API_28_AOSP",
"type": "android.emulator",
"binaryPath": "android/app/build/outputs/apk/experimentalPlay/debug/app-experimental-play-debug.apk",
"build": "cd android && ./gradlew app:assembleExperimentalPlayDebug app:assembleExperimentalPlayDebugAndroidTest -DtestBuildType=debug && cd .."
"binaryPath": "android/app/build/outputs/apk/e2ePlay/debug/app-e2e-play-debug.apk",
"build": "cd android && ./gradlew app:assembleE2ePlayDebug app:assembleE2ePlayDebugAndroidTest -DtestBuildType=debug && cd .."
},
"android.experimental.play.emu.release": {
"and.emu.release": {
"device": "Pixel_API_28_AOSP",
"type": "android.emulator",
"binaryPath": "android/app/build/outputs/apk/experimentalPlay/release/app-experimental-play-release.apk",
"build": "cd android && ./gradlew app:assembleExperimentalPlayRelease app:assembleExperimentalPlayReleaseAndroidTest -DtestBuildType=release && cd .."
},
"android.experimental.play.dev.debug": {
"device": "CVH7N15C14003503",
"type": "android.attached",
"binaryPath": "android/app/build/outputs/apk/experimentalPlay/debug/app-experimental-play-debug.apk",
"build": "cd android && ./gradlew app:assembleExperimentalPlayDebug app:assembleExperimentalPlayDebugAndroidTest -DtestBuildType=debug && cd .."
},
"android.experimental.play.dev.release": {
"device": "CVH7N15C14003503",
"type": "android.attached",
"binaryPath": "android/app/build/outputs/apk/experimentalPlay/release/app-experimental-play-release.apk",
"build": "cd android && ./gradlew app:assembleExperimentalPlayRelease app:assembleExperimentalPlayReleaseAndroidTest -DtestBuildType=release && cd .."
"binaryPath": "android/app/build/outputs/apk/e2ePlay/release/app-e2e-play-release.apk",
"build": "cd android && ./gradlew app:assembleE2ePlayRelease app:assembleE2ePlayReleaseAndroidTest -DtestBuildType=release && cd .."
}
}
}