Code Cleaning

This commit is contained in:
Anant Bhasin 2021-08-17 18:05:45 +00:00 committed by GitHub
parent b6ad070ce6
commit 3e029e4b7f
12 changed files with 75 additions and 73 deletions

View File

@ -1,8 +1,24 @@
const {
expect, element, by, waitFor
} = require('detox');
const { exec } = require('child_process');
const data = require('../data');
const platformTypes = require('./platformTypes');
const platformTypes = {
android: {
// Android types
alertButtonType: 'android.widget.Button',
scrollViewType: 'android.widget.ScrollView',
textInputType: 'android.widget.EditText'
},
ios: {
// iOS types
alertButtonType: '_UIAlertControllerActionView',
scrollViewType: 'UIScrollView',
textInputType: '_UIAlertControllerTextField'
}
};
async function navigateToWorkspace(server = data.server) {
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(10000);
@ -145,6 +161,29 @@ const checkServer = async(server) => {
await element(by.id('sidebar-close-drawer')).tap();
};
function runCommand(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(new Error(`exec error: ${ stderr }`));
return;
}
resolve();
});
});
}
async function prepareAndroid() {
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');
await runCommand('adb shell settings put global window_animation_scale 0.0');
await runCommand('adb shell settings put global transition_animation_scale 0.0');
await runCommand('adb shell settings put global animator_duration_scale 0.0');
}
module.exports = {
navigateToWorkspace,
navigateToLogin,
@ -160,5 +199,7 @@ module.exports = {
searchRoom,
tryTapping,
checkServer,
mockMessageWithNag
mockMessageWithNag,
platformTypes,
prepareAndroid
};

View File

@ -1,31 +0,0 @@
const { exec } = require('child_process');
const { device } = require('detox');
function runCommand(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(new Error(`exec error: ${ stderr }`));
return;
}
resolve();
});
});
}
// 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');
await runCommand('adb shell settings put global window_animation_scale 0.0');
await runCommand('adb shell settings put global transition_animation_scale 0.0');
await runCommand('adb shell settings put global animator_duration_scale 0.0');
};
exports.closeKeyboardAndroid = async() => {
await device.pressBack(); // Android-only
};

View File

@ -1,13 +0,0 @@
exports.android = {
// Android types
alertButtonType: 'android.widget.Button',
scrollViewType: 'android.widget.ScrollView',
textInputType: 'android.widget.EditText'
};
exports.ios = {
// iOS types
alertButtonType: '_UIAlertControllerActionView',
scrollViewType: 'UIScrollView',
textInputType: '_UIAlertControllerTextField'
};

View File

@ -1,9 +1,7 @@
const {
navigateToLogin, login, sleep, tapBack, mockMessage, searchRoom, logout
navigateToLogin, login, sleep, tapBack, mockMessage, searchRoom, logout, platformTypes
} = require('../../helpers/app');
const platformTypes = require('../../helpers/platformTypes');
const data = require('../../data');
const testuser = data.users.regular;

View File

@ -1,8 +1,11 @@
const { navigateToLogin, login, sleep } = require('../../helpers/app');
const {
navigateToLogin,
login,
sleep,
platformTypes
} = require('../../helpers/app');
const data = require('../../data');
const platformTypes = require('../../helpers/platformTypes');
const profileChangeUser = data.users.profileChanges;
const scrollDown = 200;

View File

@ -1,6 +1,5 @@
const { navigateToLogin, login } = require('../../helpers/app');
const { navigateToLogin, login, platformTypes } = require('../../helpers/app');
const platformTypes = require('../../helpers/platformTypes');
const data = require('../../data');

View File

@ -1,10 +1,8 @@
const data = require('../../data');
const {
navigateToLogin, login, mockMessage, tapBack, searchRoom
navigateToLogin, login, mockMessage, tapBack, searchRoom, platformTypes
} = require('../../helpers/app');
const platformTypes = require('../../helpers/platformTypes');
const testuser = data.users.regular;
const room = data.channels.detoxpublic.name;

View File

@ -1,10 +1,8 @@
const data = require('../../data');
const {
sleep, navigateToLogin, login, checkServer
sleep, navigateToLogin, login, checkServer, platformTypes
} = require('../../helpers/app');
const platformTypes = require('../../helpers/platformTypes');
describe('Delete server', () => {
let scrollViewType;
let alertButtonType;

View File

@ -1,7 +1,11 @@
const data = require('../../data');
const { tapBack, checkServer, navigateToRegister } = require('../../helpers/app');
const {
tapBack,
checkServer,
navigateToRegister,
platformTypes
} = require('../../helpers/app');
const { get, login } = require('../../helpers/data_setup');
const platformTypes = require('../../helpers/platformTypes');
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };

View File

@ -2,7 +2,7 @@ const detox = require('detox');
const adapter = require('detox/runners/mocha/adapter');
const config = require('../../package.json').detox;
const { setup } = require('../helpers/data_setup');
const { prepareAndroid } = require('../helpers/platformFunctions');
const { prepareAndroid } = require('../helpers/app');
before(async() => {
await Promise.all([setup(), detox.init(config, { launchApp: false })]);

View File

@ -1,11 +1,9 @@
const data = require('../../data');
const {
navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage
navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage, platformTypes
} = require('../../helpers/app');
const { sendMessage } = require('../../helpers/data_setup');
const platformTypes = require('../../helpers/platformTypes');
async function navigateToRoomActions(type) {
let room;
if (type === 'd') {
@ -376,11 +374,19 @@ describe('Room actions screen', () => {
const openActionSheet = async(username) => {
await waitFor(element(by.id(`room-members-view-item-${ username }`))).toExist().withTimeout(5000);
await element(by.id(`room-members-view-item-${ username }`)).tap();
await sleep(300);
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up');
let n = 0;
while (n < 3) {
// Max tries three times, in case it does not register the click
try {
await element(by.id(`room-members-view-item-${ username }`)).tap();
await waitFor(element(by.id('action-sheet'))).toExist().withTimeout(5000);
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up');
return;
} catch (e) {
n += 1;
}
}
};
const closeActionSheet = async() => {

View File

@ -1,8 +1,7 @@
const data = require('../../data');
const {
navigateToLogin, tapBack, login, searchRoom, sleep
navigateToLogin, tapBack, login, searchRoom, sleep, platformTypes
} = require('../../helpers/app');
const platformTypes = require('../../helpers/platformTypes');
async function navigateToRoom(roomName) {
await searchRoom(`${ roomName }`);