2018-05-23 13:39:18 +00:00
|
|
|
const data = require('../data');
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
async function navigateToWorkspace(server = data.server) {
|
2021-07-02 17:39:39 +00:00
|
|
|
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(10000);
|
2020-05-20 16:33:40 +00:00
|
|
|
await element(by.id('join-workspace')).tap();
|
|
|
|
await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(60000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('new-server-view-input')).typeText(`${ server }\n`);
|
2020-05-20 16:33:40 +00:00
|
|
|
await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(60000);
|
|
|
|
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 waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(20000);
|
|
|
|
await navigateToWorkspace(server);
|
2020-05-20 16:33:40 +00:00
|
|
|
await element(by.id('workspace-view-login')).tap();
|
2021-07-02 17:39:39 +00:00
|
|
|
await waitFor(element(by.id('login-view'))).toBeVisible().withTimeout(2000);
|
|
|
|
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 waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(20000);
|
|
|
|
await navigateToWorkspace(server);
|
2020-05-20 16:33:40 +00:00
|
|
|
await element(by.id('workspace-view-register')).tap();
|
2021-07-02 17:39:39 +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-07-02 17:39:39 +00:00
|
|
|
await waitFor(element(by.id('login-view'))).toBeVisible().withTimeout(2000);
|
|
|
|
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();
|
|
|
|
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(30000);
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function logout() {
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('rooms-list-view-sidebar')).tap();
|
|
|
|
await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000);
|
2020-03-03 20:27:38 +00:00
|
|
|
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();
|
|
|
|
await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000);
|
|
|
|
await element(by.type('UIScrollView')).atIndex(1).scrollTo('bottom');
|
|
|
|
await element(by.id('settings-logout')).tap();
|
|
|
|
const logoutAlertMessage = 'You will be logged out of this application.';
|
|
|
|
await waitFor(element(by.text(logoutAlertMessage)).atIndex(0)).toExist().withTimeout(10000);
|
|
|
|
await expect(element(by.text(logoutAlertMessage)).atIndex(0)).toExist();
|
|
|
|
await element(by.text('Logout')).tap();
|
|
|
|
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(10000);
|
|
|
|
await expect(element(by.id('onboarding-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-07-02 17:39:39 +00:00
|
|
|
const input = isThread ? 'messagebox-input-thread' : 'messagebox-input';
|
2021-04-19 14:31:43 +00:00
|
|
|
await element(by.id(input)).tap();
|
|
|
|
await element(by.id(input)).typeText(`${ data.random }${ message }`);
|
|
|
|
await element(by.id('messagebox-send-message')).tap();
|
|
|
|
await waitFor(element(by.label(`${ data.random }${ message }`))).toExist().withTimeout(60000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await expect(element(by.label(`${ data.random }${ message }`))).toExist();
|
|
|
|
await element(by.label(`${ data.random }${ message }`)).atIndex(0).tap();
|
|
|
|
}
|
2020-05-20 16:33:40 +00:00
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
async function starMessage(message) {
|
|
|
|
const messageLabel = `${ data.random }${ message }`;
|
|
|
|
await element(by.label(messageLabel)).atIndex(0).longPress();
|
|
|
|
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);
|
|
|
|
await element(by.label('Star')).atIndex(0).tap();
|
|
|
|
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 pinMessage(message) {
|
|
|
|
const messageLabel = `${ data.random }${ message }`;
|
|
|
|
await waitFor(element(by.label(messageLabel)).atIndex(0)).toExist();
|
|
|
|
await element(by.label(messageLabel)).atIndex(0).longPress();
|
|
|
|
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);
|
|
|
|
await element(by.label('Pin')).atIndex(0).tap();
|
|
|
|
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() {
|
|
|
|
await waitFor(element(by.text('Are you enjoying this app?'))).toExist().withTimeout(60000);
|
|
|
|
await element(by.label('No').and(by.type('_UIAlertControllerActionView'))).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
|
|
|
}
|
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise(res => setTimeout(res, ms));
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
async function searchRoom(room) {
|
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();
|
|
|
|
await waitFor(element(by.id('rooms-list-view-search-input'))).toExist().withTimeout(5000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('rooms-list-view-search-input')).typeText(room);
|
|
|
|
await sleep(300);
|
2021-04-07 18:56:16 +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) {
|
|
|
|
if (timeout <= 0) { // TODO: Maths. How closely has the timeout been honoured here?
|
|
|
|
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-03-31 21:01:20 +00:00
|
|
|
const checkServer = async(server) => {
|
|
|
|
const label = `Connected to ${ server }`;
|
|
|
|
await element(by.id('rooms-list-view-sidebar')).tap();
|
|
|
|
await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000);
|
|
|
|
await waitFor(element(by.label(label))).toBeVisible().withTimeout(10000);
|
|
|
|
await element(by.id('sidebar-close-drawer')).tap();
|
2021-07-02 17:39:39 +00:00
|
|
|
};
|
2021-03-31 21:01:20 +00:00
|
|
|
|
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,
|
|
|
|
checkServer
|
|
|
|
};
|