fix in app notification and added navigateToRoom and checkRoomTitle

This commit is contained in:
Diego Mello 2023-02-16 11:39:56 -03:00
parent a0606aa23c
commit d3763e37db
3 changed files with 36 additions and 39 deletions

View File

@ -163,6 +163,12 @@ async function searchRoom(room: string) {
.withTimeout(60000); .withTimeout(60000);
} }
async function navigateToRoom(room: string) {
await searchRoom(room);
await element(by.id(`rooms-list-view-item-${room}`)).tap();
await checkRoomTitle(room);
}
async function tryTapping(theElement: Detox.IndexableNativeElement, timeout: number, longtap = false) { async function tryTapping(theElement: Detox.IndexableNativeElement, timeout: number, longtap = false) {
try { try {
if (longtap) { if (longtap) {
@ -196,6 +202,12 @@ async function tapAndWaitFor(
} }
} }
async function checkRoomTitle(room: string) {
await waitFor(element(by.id(`room-view-title-${room}`)))
.toBeVisible()
.withTimeout(60000);
}
const checkServer = async (server: string) => { const checkServer = async (server: string) => {
const label = `Connected to ${server}`; const label = `Connected to ${server}`;
await element(by.id('rooms-list-view-sidebar')).tap(); await element(by.id('rooms-list-view-sidebar')).tap();
@ -227,8 +239,10 @@ export {
tapBack, tapBack,
sleep, sleep,
searchRoom, searchRoom,
navigateToRoom,
tryTapping, tryTapping,
tapAndWaitFor, tapAndWaitFor,
checkRoomTitle,
checkServer, checkServer,
platformTypes platformTypes
}; };

View File

@ -22,8 +22,7 @@ const login = async (username: string, password: string) => {
user: username, user: username,
password password
}); });
const { userId } = response.data.data; const { authToken, userId } = response.data.data;
const { authToken } = response.data.data;
rocketchat.defaults.headers.common['X-User-Id'] = userId; rocketchat.defaults.headers.common['X-User-Id'] = userId;
rocketchat.defaults.headers.common['X-Auth-Token'] = authToken; rocketchat.defaults.headers.common['X-Auth-Token'] = authToken;
return { authToken, userId }; return { authToken, userId };
@ -186,7 +185,9 @@ const get = (endpoint: string) => {
return rocketchat.get(endpoint); return rocketchat.get(endpoint);
}; };
const post = (endpoint: string, body: any) => { const post = async (endpoint: string, body: any) => {
const data = new Data(globalThis.random);
await login(data.users.regular.username, data.users.regular.password);
console.log(`POST /${endpoint} ${JSON.stringify(body)}`); console.log(`POST /${endpoint} ${JSON.stringify(body)}`);
return rocketchat.post(endpoint, body); return rocketchat.post(endpoint, body);
}; };

View File

@ -1,9 +1,11 @@
import { expect } from 'detox';
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, sleep, tapBack } from '../../helpers/app'; import { navigateToLogin, login, sleep, tapBack, navigateToRoom, checkRoomTitle } from '../../helpers/app';
import { sendMessage, post } from '../../helpers/data_setup'; import { sendMessage, post } from '../../helpers/data_setup';
const waitForInAppNotificationAnimation = async () => {
await sleep(500);
};
describe('InApp Notification', () => { describe('InApp Notification', () => {
let dmCreatedRid: string; let dmCreatedRid: string;
@ -11,62 +13,42 @@ describe('InApp Notification', () => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(data.users.regular.username, data.users.regular.password);
const result = await post(`im.create`, { username: data.users.alternate.username }); const result = await post('im.create', { username: data.users.alternate.username });
dmCreatedRid = result.data.room.rid; dmCreatedRid = result.data.room.rid;
}); });
describe('receive in RoomsListView', () => { describe('receive in RoomsListView', () => {
const text = 'Message in DM'; const text = 'Message in DM';
it('should have rooms list screen', async () => {
await expect(element(by.id('rooms-list-view'))).toBeVisible();
});
it('should send direct message from user alternate to user regular', async () => {
await sleep(1000);
await sendMessage(data.users.alternate, dmCreatedRid, text);
});
it('should tap on InApp Notification', async () => { it('should tap on InApp Notification', async () => {
await sendMessage(data.users.alternate, dmCreatedRid, text);
await waitFor(element(by.id(`in-app-notification-${text}`))) await waitFor(element(by.id(`in-app-notification-${text}`)))
.toExist() .toExist()
.withTimeout(2000); .withTimeout(2000);
await sleep(500); await waitForInAppNotificationAnimation();
await element(by.id(`in-app-notification-${text}`)).tap(); await element(by.id(`in-app-notification-${text}`)).tap();
await waitFor(element(by.id('room-view'))) await checkRoomTitle(data.users.alternate.username);
.toBeVisible() await tapBack();
.withTimeout(5000);
await expect(element(by.id(`room-view-title-${data.users.alternate.username}`))).toExist();
}); });
}); });
describe('receive in another room', () => { describe('receive in another room', () => {
const text = 'Another msg'; const text = 'Another msg';
it('should back to RoomsListView and open the channel Detox Public', async () => { it('should receive and tap InAppNotification while in another room', async () => {
await tapBack(); await navigateToRoom(data.userRegularChannels.detoxpublic.name);
await sleep(500);
await element(by.id(`rooms-list-view-item-${data.userRegularChannels.detoxpublic.name}`)).tap();
await waitFor(element(by.id('room-view')))
.toBeVisible()
.withTimeout(5000);
await expect(element(by.id(`room-view-title-${data.userRegularChannels.detoxpublic.name}`))).toExist();
});
it('should receive and tap InAppNotification in another room', async () => {
await sendMessage(data.users.alternate, dmCreatedRid, text); await sendMessage(data.users.alternate, dmCreatedRid, text);
await waitFor(element(by.id(`in-app-notification-${text}`))) await waitFor(element(by.id(`in-app-notification-${text}`)))
.toExist() .toExist()
.withTimeout(2000); .withTimeout(2000);
await sleep(500); await waitForInAppNotificationAnimation();
await element(by.id(`in-app-notification-${text}`)).tap(); await element(by.id(`in-app-notification-${text}`)).tap();
await sleep(500); await checkRoomTitle(data.users.alternate.username);
await expect(element(by.id('room-header'))).toExist();
await expect(element(by.id(`room-view-title-${data.users.alternate.username}`))).toExist();
}); });
it('should back to RoomsListView', async () => { it('should tap back and go back to RoomsListView', async () => {
await tapBack(); await tapBack();
await sleep(500); await waitFor(element(by.id('rooms-list-view')))
await expect(element(by.id('rooms-list-view'))).toBeVisible(); .toBeVisible()
.withTimeout(2000);
}); });
}); });
}); });