2023-03-07 12:28:51 +00:00
|
|
|
import { device, waitFor, element, by } from 'detox';
|
2022-09-23 20:35:03 +00:00
|
|
|
import EJSON from 'ejson';
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
import data from '../../data';
|
2023-03-07 12:28:51 +00:00
|
|
|
import {
|
|
|
|
tapBack,
|
|
|
|
checkServer,
|
|
|
|
navigateToRegister,
|
|
|
|
platformTypes,
|
|
|
|
TTextMatcher,
|
|
|
|
expectValidRegisterOrRetry
|
|
|
|
} from '../../helpers/app';
|
2023-06-27 12:57:52 +00:00
|
|
|
import {
|
|
|
|
IDeleteCreateUser,
|
|
|
|
createRandomRoom,
|
|
|
|
createRandomUser,
|
|
|
|
deleteCreatedUsers,
|
|
|
|
login,
|
|
|
|
sendMessage
|
|
|
|
} from '../../helpers/data_setup';
|
2023-03-07 12:28:51 +00:00
|
|
|
import random from '../../helpers/random';
|
2021-03-31 21:01:20 +00:00
|
|
|
|
|
|
|
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
|
2021-12-02 13:19:15 +00:00
|
|
|
|
|
|
|
let amp = '&';
|
|
|
|
|
2022-09-12 14:51:33 +00:00
|
|
|
const getDeepLink = (method: string, server: string, params?: string) => {
|
2021-12-02 13:19:15 +00:00
|
|
|
const deeplink = `rocketchat://${method}?host=${server.replace(/^(http:\/\/|https:\/\/)/, '')}${amp}${params}`;
|
2021-09-13 20:41:05 +00:00
|
|
|
console.log(`Deeplinking to: ${deeplink}`);
|
2021-03-31 21:01:20 +00:00
|
|
|
return deeplink;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Deep linking', () => {
|
2022-09-12 14:51:33 +00:00
|
|
|
let userId: string;
|
|
|
|
let authToken: string;
|
|
|
|
let threadId: string;
|
|
|
|
let textMatcher: TTextMatcher;
|
2023-03-07 12:28:51 +00:00
|
|
|
let rid: string;
|
|
|
|
let room: string;
|
|
|
|
const threadMessage = `to-thread-${random()}`;
|
|
|
|
|
2023-06-27 12:57:52 +00:00
|
|
|
const deleteUsersAfterAll: IDeleteCreateUser[] = [];
|
|
|
|
|
2023-03-07 12:28:51 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
const user = await createRandomUser();
|
|
|
|
({ _id: rid, name: room } = await createRandomRoom(user, 'p'));
|
|
|
|
const loginResult = await login(user.username, user.password);
|
2021-04-19 14:31:43 +00:00
|
|
|
({ userId, authToken } = loginResult);
|
2021-12-02 13:19:15 +00:00
|
|
|
const deviceType = device.getPlatform();
|
|
|
|
amp = deviceType === 'android' ? '\\&' : '&';
|
2023-03-07 12:28:51 +00:00
|
|
|
({ textMatcher } = platformTypes[deviceType]);
|
2021-10-26 16:11:50 +00:00
|
|
|
// create a thread with api
|
2023-03-07 12:28:51 +00:00
|
|
|
const result = await sendMessage(user, room, threadMessage);
|
2021-10-26 16:11:50 +00:00
|
|
|
threadId = result.message._id;
|
2023-03-07 12:28:51 +00:00
|
|
|
await sendMessage(user, result.message.rid, random(), threadId);
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
|
|
|
|
2023-06-27 12:57:52 +00:00
|
|
|
afterAll(async () => {
|
|
|
|
await deleteCreatedUsers(deleteUsersAfterAll);
|
|
|
|
});
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
describe('Authentication', () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should run a deep link to an invalid account and raise error', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
2021-04-19 14:31:43 +00:00
|
|
|
delete: true,
|
2021-12-02 13:19:15 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=123${amp}token=abc`)
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2023-06-26 19:28:11 +00:00
|
|
|
await waitFor(element(by[textMatcher]("You've been logged out by the workspace. Please log in again.")))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000); // TODO: we need to improve this message
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const authAndNavigate = async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=${userId}${amp}token=${authToken}${amp}path=group/${room}`)
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(30000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await tapBack();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(10000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await checkServer(data.server);
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
|
2021-12-02 13:19:15 +00:00
|
|
|
.toExist()
|
2021-09-13 20:41:05 +00:00
|
|
|
.withTimeout(2000);
|
2021-07-02 17:39:39 +00:00
|
|
|
};
|
2021-03-31 21:01:20 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should authenticate and navigate', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await authAndNavigate();
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should authenticate while logged in another server', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
|
|
|
|
await navigateToRegister(data.alternateServer);
|
2023-03-07 12:28:51 +00:00
|
|
|
const randomUser = data.randomUser();
|
|
|
|
await element(by.id('register-view-name')).replaceText(randomUser.name);
|
|
|
|
await element(by.id('register-view-username')).replaceText(randomUser.username);
|
|
|
|
await element(by.id('register-view-email')).replaceText(randomUser.email);
|
|
|
|
await element(by.id('register-view-password')).replaceText(randomUser.password);
|
|
|
|
await element(by.id('register-view-password')).tapReturnKey();
|
|
|
|
await expectValidRegisterOrRetry(device.getPlatform());
|
2023-06-27 12:57:52 +00:00
|
|
|
deleteUsersAfterAll.push({ server: data.alternateServer, username: randomUser.username });
|
|
|
|
|
2021-03-31 21:01:20 +00:00
|
|
|
await authAndNavigate();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Room', () => {
|
2021-07-02 17:39:39 +00:00
|
|
|
describe('While logged in', () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should navigate to the room using path', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000);
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
|
|
|
|
2021-10-26 16:11:50 +00:00
|
|
|
it('should navigate to the thread using path', async () => {
|
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}/thread/${threadId}`)
|
2021-10-26 16:11:50 +00:00
|
|
|
});
|
|
|
|
await waitFor(element(by.id(`room-view-title-${threadMessage}`)))
|
|
|
|
.toExist()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000);
|
2021-10-26 16:11:50 +00:00
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should navigate to the room using rid', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `rid=${rid}`)
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await tapBack();
|
2022-08-11 19:40:31 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should resume from background and navigate to the room', async () => {
|
2023-03-07 12:28:51 +00:00
|
|
|
if (device.getPlatform() === 'android') {
|
|
|
|
console.log('Skipped on Android');
|
|
|
|
return;
|
|
|
|
}
|
2022-08-11 19:40:31 +00:00
|
|
|
await device.sendToHome();
|
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: false,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
|
2022-08-11 19:40:31 +00:00
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2022-08-11 19:40:31 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(30000);
|
|
|
|
await tapBack();
|
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2022-09-23 20:35:03 +00:00
|
|
|
|
|
|
|
it('should simulate a tap on a push notification and navigate to the room', async () => {
|
2023-03-07 12:28:51 +00:00
|
|
|
if (device.getPlatform() === 'android') {
|
|
|
|
console.log('Skipped on Android');
|
|
|
|
return;
|
|
|
|
}
|
2022-09-23 20:35:03 +00:00
|
|
|
/**
|
|
|
|
* Ideally, we would repeat this test to simulate a resume from background,
|
|
|
|
* but for some reason it was not working as expected
|
|
|
|
* This was always turning to false right before running the logic https://github.com/RocketChat/Rocket.Chat.ReactNative/blob/18f359a8ef9691144970c0c1fad990f82096b024/app/lib/notifications/push.ts#L58
|
|
|
|
*/
|
|
|
|
// await device.sendToHome();
|
|
|
|
await device.launchApp({
|
|
|
|
newInstance: true,
|
|
|
|
userNotification: {
|
|
|
|
trigger: {
|
|
|
|
type: 'push'
|
|
|
|
},
|
|
|
|
title: 'From push',
|
|
|
|
body: 'Body',
|
|
|
|
badge: 1,
|
|
|
|
payload: {
|
|
|
|
ejson: EJSON.stringify({
|
|
|
|
rid: null,
|
|
|
|
host: data.server,
|
2023-03-07 12:28:51 +00:00
|
|
|
name: room,
|
2022-09-23 20:35:03 +00:00
|
|
|
type: 'p'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2022-09-23 20:35:03 +00:00
|
|
|
.toExist()
|
|
|
|
.withTimeout(30000);
|
|
|
|
await tapBack();
|
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
|
|
|
});
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
|
|
|
|
2021-07-02 17:39:39 +00:00
|
|
|
describe('Others', () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should change server', async () => {
|
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(2000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await element(by.id('rooms-list-header-server-dropdown-button')).tap();
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-header-server-dropdown')))
|
|
|
|
.toBeVisible()
|
|
|
|
.withTimeout(5000);
|
|
|
|
await element(by.id(`rooms-list-header-server-${data.alternateServer}`)).tap();
|
2021-03-31 21:01:20 +00:00
|
|
|
await checkServer(data.alternateServer);
|
|
|
|
|
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2023-03-07 12:28:51 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2023-03-07 12:28:51 +00:00
|
|
|
await waitFor(element(by.id(`room-view-title-${room}`)))
|
2021-09-13 20:41:05 +00:00
|
|
|
.toExist()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000);
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
it('should add a not existing server and fallback to the previous one', async () => {
|
2021-03-31 21:01:20 +00:00
|
|
|
await device.launchApp({
|
|
|
|
permissions: { notifications: 'YES' },
|
|
|
|
newInstance: true,
|
2021-12-02 13:19:15 +00:00
|
|
|
url: getDeepLink(DEEPLINK_METHODS.ROOM, 'https://google.com')
|
2021-03-31 21:01:20 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
await waitFor(element(by.id('rooms-list-view')))
|
|
|
|
.toBeVisible()
|
2022-02-16 15:02:17 +00:00
|
|
|
.withTimeout(30000);
|
2021-03-31 21:01:20 +00:00
|
|
|
await checkServer(data.server);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|