2023-03-07 12:28:51 +00:00
|
|
|
import Detox, { device, waitFor, element, by, expect } from 'detox';
|
2022-09-12 14:51:33 +00:00
|
|
|
|
|
|
|
import data from '../data';
|
|
|
|
|
|
|
|
export type TTextMatcher = keyof Pick<Detox.ByFacade, 'text' | 'label'>;
|
2018-05-23 13:39:18 +00:00
|
|
|
|
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',
|
2022-09-12 14:51:33 +00:00
|
|
|
textMatcher: 'text' as TTextMatcher
|
2021-12-02 13:19:15 +00:00
|
|
|
},
|
|
|
|
ios: {
|
|
|
|
// iOS types
|
|
|
|
alertButtonType: '_UIAlertControllerActionView',
|
|
|
|
scrollViewType: 'UIScrollView',
|
|
|
|
textInputType: '_UIAlertControllerTextField',
|
2022-09-12 14:51:33 +00:00
|
|
|
textMatcher: 'label' as TTextMatcher
|
2021-12-02 13:19:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
function sleep(ms: number) {
|
2021-12-02 13:19:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
async function navigateToLogin(server?: string) {
|
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')))
|
2022-05-26 17:10:24 +00:00
|
|
|
.toExist()
|
2021-09-13 20:41:05 +00:00
|
|
|
.withTimeout(2000);
|
2020-05-20 16:33:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
async function navigateToRegister(server?: string) {
|
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')))
|
2022-05-26 17:10:24 +00:00
|
|
|
.toExist()
|
2021-09-13 20:41:05 +00:00
|
|
|
.withTimeout(2000);
|
2018-05-23 13:39:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
async function login(username: string, password: string) {
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('login-view')))
|
2022-05-26 17:10:24 +00:00
|
|
|
.toExist()
|
2021-09-13 20:41:05 +00:00
|
|
|
.withTimeout(2000);
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('login-view-email')).replaceText(username);
|
2023-03-07 12:28:51 +00:00
|
|
|
await element(by.id('login-view-email')).tapReturnKey();
|
2021-07-02 17:39:39 +00:00
|
|
|
await element(by.id('login-view-password')).replaceText(password);
|
2023-03-07 12:28:51 +00:00
|
|
|
await element(by.id('login-view-password')).tapReturnKey();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
2022-05-26 17:10:24 +00:00
|
|
|
.toExist()
|
2021-09-13 20:41:05 +00:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
async function mockMessage(message: string, isThread = false) {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
2024-01-25 14:11:07 +00:00
|
|
|
const input = isThread ? 'message-composer-input-thread' : 'message-composer-input';
|
|
|
|
await element(by.id(input)).typeText(message);
|
|
|
|
await element(by.id('message-composer-send')).tap();
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by[textMatcher](message)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(60000);
|
2023-03-07 12:28:51 +00:00
|
|
|
await element(by[textMatcher](message)).atIndex(0).tap();
|
|
|
|
return message;
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
async function tapBack() {
|
2023-03-07 12:28:51 +00:00
|
|
|
try {
|
|
|
|
await element(by.id('header-back')).atIndex(0).tap();
|
|
|
|
} catch (error) {
|
|
|
|
await device.pressBack();
|
|
|
|
}
|
|
|
|
await sleep(300); // Wait for animation to finish
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 18:20:04 +00:00
|
|
|
async function searchRoom(
|
|
|
|
room: string,
|
|
|
|
nativeElementAction: keyof Pick<Detox.NativeElementActions, 'typeText' | 'replaceText'> = 'typeText',
|
|
|
|
roomTestID?: string
|
|
|
|
) {
|
2021-12-02 13:19:15 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
2024-01-25 14:11:07 +00:00
|
|
|
.toExist()
|
2021-12-02 13:19:15 +00:00
|
|
|
.withTimeout(30000);
|
2023-03-07 12:28:51 +00:00
|
|
|
await tapAndWaitFor(element(by.id('rooms-list-view-search')), element(by.id('rooms-list-view-search-input')), 5000);
|
2023-06-16 18:20:04 +00:00
|
|
|
if (nativeElementAction === 'replaceText') {
|
|
|
|
// trigger the input's onChangeText
|
|
|
|
await element(by.id('rooms-list-view-search-input')).typeText(' ');
|
|
|
|
}
|
|
|
|
await element(by.id('rooms-list-view-search-input'))[nativeElementAction](room);
|
2023-05-29 15:03:24 +00:00
|
|
|
await sleep(500);
|
|
|
|
await sleep(500);
|
|
|
|
await waitFor(element(by.id(roomTestID || `rooms-list-view-item-${room}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
async function navigateToRoom(room: string) {
|
|
|
|
await searchRoom(room);
|
|
|
|
await element(by.id(`rooms-list-view-item-${room}`)).tap();
|
|
|
|
await checkRoomTitle(room);
|
|
|
|
}
|
|
|
|
|
2024-02-15 19:41:03 +00:00
|
|
|
async function navigateToRecentRoom(room: string) {
|
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toExist()
|
|
|
|
.withTimeout(10000);
|
|
|
|
await tapAndWaitFor(element(by.id('rooms-list-view-search')), element(by.id('rooms-list-view-search-input')), 5000);
|
|
|
|
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
|
|
|
await element(by.id(`rooms-list-view-item-${room}`)).tap();
|
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
|
|
|
}
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
async function tryTapping(
|
|
|
|
theElement: Detox.IndexableNativeElement | Detox.NativeElement,
|
|
|
|
timeout: number,
|
|
|
|
longPress = false
|
|
|
|
): Promise<void> {
|
2020-07-22 16:32:21 +00:00
|
|
|
try {
|
2023-03-07 12:28:51 +00:00
|
|
|
if (longPress) {
|
|
|
|
await theElement.tap();
|
2021-07-02 17:39:39 +00:00
|
|
|
await theElement.longPress();
|
|
|
|
} else {
|
|
|
|
await theElement.tap();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (timeout <= 0) {
|
2023-03-07 12:28:51 +00:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
return tryTapping(theElement, timeout - 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 15:03:03 +00:00
|
|
|
async function jumpToQuotedMessage(theElement: Detox.IndexableNativeElement | Detox.NativeElement): Promise<void> {
|
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
const { textMatcher } = platformTypes[deviceType];
|
|
|
|
await tryTapping(theElement, 2000, true);
|
|
|
|
await element(by[textMatcher]('Jump to message')).atIndex(0).tap();
|
|
|
|
}
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
async function tapAndWaitFor(
|
|
|
|
elementToTap: Detox.IndexableNativeElement | Detox.NativeElement,
|
|
|
|
elementToWaitFor: Detox.IndexableNativeElement | Detox.NativeElement,
|
|
|
|
timeout: number,
|
|
|
|
longPress = false
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
if (longPress) {
|
|
|
|
elementToTap.longPress();
|
|
|
|
} else {
|
|
|
|
await elementToTap.tap();
|
|
|
|
}
|
|
|
|
await waitFor(elementToWaitFor).toBeVisible().withTimeout(1000);
|
2023-05-18 21:09:33 +00:00
|
|
|
await sleep(300); // Wait for animation
|
2023-03-07 12:28:51 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (timeout <= 0) {
|
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);
|
2023-03-07 12:28:51 +00:00
|
|
|
await tapAndWaitFor(elementToTap, elementToWaitFor, timeout - 100);
|
2020-07-22 16:32:21 +00:00
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
async function checkRoomTitle(room: string) {
|
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
const checkServer = async (server: string) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
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);
|
2022-02-16 15:02:17 +00:00
|
|
|
await waitFor(element(by.id('sidebar-close-drawer')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await element(by.id('sidebar-close-drawer')).tap();
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
if (device.getPlatform() === 'ios') {
|
|
|
|
await waitFor(element(by.id('sidebar-close-drawer')))
|
|
|
|
.not.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
|
|
|
} else {
|
|
|
|
// toBeVisible is not working on Android
|
|
|
|
// It is always visible, even when it's not
|
|
|
|
await sleep(2000);
|
|
|
|
}
|
|
|
|
};
|
2021-12-02 13:19:15 +00:00
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
// Useful to get rid of `Too many requests` alert on register
|
|
|
|
async function expectValidRegisterOrRetry(platform: keyof typeof platformTypes, retries = 3) {
|
|
|
|
if (retries === 0) {
|
|
|
|
throw new Error('Too many retries');
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(60000);
|
|
|
|
} catch (error) {
|
|
|
|
/**
|
|
|
|
* We can't use regex to properly match by label, so we assume [error-too-many-requests] is visible.
|
|
|
|
* We don't need to wait for another 60 seconds, because we already did above, so we just try again.
|
|
|
|
* */
|
|
|
|
await element(by[platformTypes[platform].textMatcher]('OK').and(by.type(platformTypes[platform].alertButtonType))).tap();
|
|
|
|
await element(by.id('register-view-submit')).tap();
|
|
|
|
await expectValidRegisterOrRetry(platform, retries - 1);
|
2021-12-02 13:19:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
export {
|
2021-07-02 17:39:39 +00:00
|
|
|
navigateToWorkspace,
|
|
|
|
navigateToLogin,
|
|
|
|
navigateToRegister,
|
|
|
|
login,
|
|
|
|
logout,
|
|
|
|
mockMessage,
|
|
|
|
tapBack,
|
|
|
|
sleep,
|
|
|
|
searchRoom,
|
2023-03-07 12:28:51 +00:00
|
|
|
navigateToRoom,
|
2021-07-02 17:39:39 +00:00
|
|
|
tryTapping,
|
2023-03-07 12:28:51 +00:00
|
|
|
tapAndWaitFor,
|
|
|
|
checkRoomTitle,
|
2021-12-02 13:19:15 +00:00
|
|
|
checkServer,
|
|
|
|
platformTypes,
|
2023-11-30 15:03:03 +00:00
|
|
|
expectValidRegisterOrRetry,
|
2024-02-15 19:41:03 +00:00
|
|
|
jumpToQuotedMessage,
|
|
|
|
navigateToRecentRoom
|
2021-07-02 17:39:39 +00:00
|
|
|
};
|