2021-12-02 13:19:15 +00:00
|
|
|
const { exec } = require('child_process');
|
2018-05-23 13:39:18 +00:00
|
|
|
const data = require('../data');
|
|
|
|
|
2021-12-02 13:19:15 +00:00
|
|
|
const platformTypes = {
|
|
|
|
android: {
|
|
|
|
// Android types
|
|
|
|
alertButtonType: 'android.widget.Button',
|
|
|
|
scrollViewType: 'android.widget.ScrollView',
|
|
|
|
textInputType: 'android.widget.EditText',
|
|
|
|
textMatcher: 'text'
|
|
|
|
},
|
|
|
|
ios: {
|
|
|
|
// iOS types
|
|
|
|
alertButtonType: '_UIAlertControllerActionView',
|
|
|
|
scrollViewType: 'UIScrollView',
|
|
|
|
textInputType: '_UIAlertControllerTextField',
|
|
|
|
textMatcher: 'label'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise(res => setTimeout(res, ms));
|
|
|
|
}
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
async function navigateToWorkspace(server = data.server) {
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('new-server-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by.id('new-server-view-input')).replaceText(`${server}`);
|
|
|
|
await element(by.id('new-server-view-input')).tapReturnKey();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('workspace-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
2020-05-20 16:33:40 +00:00
|
|
|
await expect(element(by.id('workspace-view'))).toBeVisible();
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
async function navigateToLogin(server) {
|
2021-07-02 17:39:39 +00:00
|
|
|
await navigateToWorkspace(server);
|
2020-05-20 16:33:40 +00:00
|
|
|
await element(by.id('workspace-view-login')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('login-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await expect(element(by.id('login-view'))).toBeVisible();
|
2020-05-20 16:33:40 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
async function navigateToRegister(server) {
|
2021-07-02 17:39:39 +00:00
|
|
|
await navigateToWorkspace(server);
|
2020-05-20 16:33:40 +00:00
|
|
|
await element(by.id('workspace-view-register')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('register-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 16:28:34 +00:00
|
|
|
async function login(username, password) {
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('login-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('login-view-email')).replaceText(username);
|
|
|
|
await element(by.id('login-view-password')).replaceText(password);
|
|
|
|
await element(by.id('login-view-submit')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(30000);
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function logout() {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { scrollViewType, textMatcher } = platformTypes[deviceType];
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('rooms-list-view-sidebar')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('sidebar-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
|
|
|
await waitFor(element(by.id('sidebar-settings')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('sidebar-settings')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('settings-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by.type(scrollViewType)).atIndex(1).scrollTo('bottom');
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('settings-logout')).tap();
|
|
|
|
const logoutAlertMessage = 'You will be logged out of this application.';
|
2021-12-02 13:19:15 +00:00
|
|
|
await waitFor(element(by[textMatcher](logoutAlertMessage)).atIndex(0))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(10000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await expect(element(by[textMatcher](logoutAlertMessage)).atIndex(0)).toExist();
|
|
|
|
await element(by[textMatcher]('Logout')).atIndex(0).tap();
|
2021-09-23 14:17:53 +00:00
|
|
|
await waitFor(element(by.id('new-server-view')))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
2021-09-23 14:17:53 +00:00
|
|
|
await expect(element(by.id('new-server-view'))).toBeVisible();
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 14:31:43 +00:00
|
|
|
async function mockMessage(message, isThread = false) {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
2021-07-02 17:39:39 +00:00
|
|
|
const input = isThread ? 'messagebox-input-thread' : 'messagebox-input';
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by.id(input)).replaceText(`${data.random}${message}`);
|
|
|
|
await sleep(300);
|
2021-04-19 14:31:43 +00:00
|
|
|
await element(by.id('messagebox-send-message')).tap();
|
2021-12-02 13:19:15 +00:00
|
|
|
await waitFor(element(by[textMatcher](`${data.random}${message}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(60000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by[textMatcher](`${data.random}${message}`))
|
2021-09-13 20:41:05 +00:00
|
|
|
.atIndex(0)
|
|
|
|
.tap();
|
2021-07-02 17:39:39 +00:00
|
|
|
}
|
2020-05-20 16:33:40 +00:00
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
async function starMessage(message) {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
2021-09-13 20:41:05 +00:00
|
|
|
const messageLabel = `${data.random}${message}`;
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by[textMatcher](messageLabel)).atIndex(0).longPress();
|
2021-07-02 17:39:39 +00:00
|
|
|
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', 'fast', 0.5);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by[textMatcher]('Star')).atIndex(0).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('action-sheet')))
|
|
|
|
.not.toExist()
|
|
|
|
.withTimeout(5000);
|
2021-07-02 17:39:39 +00:00
|
|
|
}
|
2020-07-22 16:32:21 +00:00
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
async function pinMessage(message) {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
2021-09-13 20:41:05 +00:00
|
|
|
const messageLabel = `${data.random}${message}`;
|
2021-12-02 13:19:15 +00:00
|
|
|
await waitFor(element(by[textMatcher](messageLabel)).atIndex(0)).toExist();
|
|
|
|
await element(by[textMatcher](messageLabel)).atIndex(0).longPress();
|
2021-07-02 17:39:39 +00:00
|
|
|
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', 'fast', 0.5);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by[textMatcher]('Pin')).atIndex(0).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('action-sheet')))
|
|
|
|
.not.toExist()
|
|
|
|
.withTimeout(5000);
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
async function dismissReviewNag() {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
|
|
|
await waitFor(element(by[textMatcher]('Are you enjoying this app?')))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(60000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await element(by[textMatcher]('No')).atIndex(0).tap(); // Tap `no` on ask for review alert
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
async function tapBack() {
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('header-back')).atIndex(0).tap();
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
async function searchRoom(room) {
|
2021-12-02 13:19:15 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(30000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('rooms-list-view-search')).tap();
|
2020-07-06 20:56:28 +00:00
|
|
|
await expect(element(by.id('rooms-list-view-search-input'))).toExist();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view-search-input')))
|
|
|
|
.toExist()
|
|
|
|
.withTimeout(5000);
|
2021-12-02 13:19:15 +00:00
|
|
|
await sleep(300);
|
|
|
|
await element(by.id('rooms-list-view-search-input')).replaceText(room);
|
2021-07-02 17:39:39 +00:00
|
|
|
await sleep(300);
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
async function tryTapping(theElement, timeout, longtap = false) {
|
2020-07-22 16:32:21 +00:00
|
|
|
try {
|
2021-07-02 17:39:39 +00:00
|
|
|
if (longtap) {
|
|
|
|
await theElement.longPress();
|
|
|
|
} else {
|
|
|
|
await theElement.tap();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (timeout <= 0) {
|
|
|
|
// TODO: Maths. How closely has the timeout been honoured here?
|
2021-07-02 17:39:39 +00:00
|
|
|
throw e;
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
2021-07-02 17:39:39 +00:00
|
|
|
await sleep(100);
|
|
|
|
await tryTapping(theElement, timeout - 100);
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const checkServer = async server => {
|
|
|
|
const label = `Connected to ${server}`;
|
2021-03-31 21:01:20 +00:00
|
|
|
await element(by.id('rooms-list-view-sidebar')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('sidebar-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
|
|
|
await waitFor(element(by.label(label)))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await element(by.id('sidebar-close-drawer')).tap();
|
2021-07-02 17:39:39 +00:00
|
|
|
};
|
2021-03-31 21:01:20 +00:00
|
|
|
|
2021-12-02 13:19:15 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:39:18 +00:00
|
|
|
module.exports = {
|
2021-07-02 17:39:39 +00:00
|
|
|
navigateToWorkspace,
|
|
|
|
navigateToLogin,
|
|
|
|
navigateToRegister,
|
|
|
|
login,
|
|
|
|
logout,
|
|
|
|
mockMessage,
|
|
|
|
starMessage,
|
|
|
|
pinMessage,
|
|
|
|
dismissReviewNag,
|
|
|
|
tapBack,
|
|
|
|
sleep,
|
|
|
|
searchRoom,
|
|
|
|
tryTapping,
|
2021-12-02 13:19:15 +00:00
|
|
|
checkServer,
|
|
|
|
platformTypes,
|
|
|
|
prepareAndroid
|
2021-07-02 17:39:39 +00:00
|
|
|
};
|