refactoring

This commit is contained in:
Diego Mello 2023-02-22 14:46:16 -03:00
parent ac827ffa07
commit 8d9644c8ac
21 changed files with 115 additions and 98 deletions

View File

@ -29,14 +29,14 @@ const login = async (username: string, password: string) => {
return { authToken, userId }; return { authToken, userId };
}; };
export interface ICreateUser { export interface ITestUser {
username: string; username: string;
password: string; password: string;
name: string; name: string;
email: string; email: string;
} }
export const createRandomUser = async (): Promise<ICreateUser> => { export const createRandomUser = async (): Promise<ITestUser> => {
try { try {
await login(data.adminUser, data.adminPassword); await login(data.adminUser, data.adminPassword);
const user = data.randomUser(); const user = data.randomUser();
@ -89,15 +89,21 @@ const createChannelIfNotExists = async (channelname: string) => {
} }
}; };
export const createRandomRoom = async (user: { username: string; password: string }, type: 'p' | 'c' = 'c'): Promise<string> => { export const createRandomRoom = async (
user: { username: string; password: string },
type: 'p' | 'c' = 'c'
): Promise<{ _id: string; name: string }> => {
try { try {
await login(user.username, user.password); await login(user.username, user.password);
const room = `room${random()}`; const room = `room${random()}`;
console.log(`Creating room ${room}`); console.log(`Creating room ${room}`);
await rocketchat.post(type === 'c' ? 'channels.create' : 'groups.create', { const result = await rocketchat.post(type === 'c' ? 'channels.create' : 'groups.create', {
name: room name: room
}); });
return room; return {
_id: type === 'c' ? result.data.channel._id : result.data.group._id,
name: type === 'c' ? result.data.channel.name : result.data.group.name
};
} catch (e) { } catch (e) {
console.log(JSON.stringify(e)); console.log(JSON.stringify(e));
throw new Error('Failed to create room'); throw new Error('Failed to create room');

View File

@ -14,7 +14,7 @@ import {
mockRandomMessage mockRandomMessage
} from '../../helpers/app'; } from '../../helpers/app';
import data from '../../data'; import data from '../../data';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
import random from '../../helpers/random'; import random from '../../helpers/random';
const checkServer = async (server: string) => { const checkServer = async (server: string) => {
@ -71,8 +71,8 @@ async function navigateSecurityPrivacy() {
describe('E2E Encryption', () => { describe('E2E Encryption', () => {
const room = `encrypted${random()}`; const room = `encrypted${random()}`;
let user: ICreateUser; let user: ITestUser;
let otherUser: ICreateUser; let otherUser: ITestUser;
let mockedMessageText: string; let mockedMessageText: string;
const newPassword = 'abc'; const newPassword = 'abc';

View File

@ -13,13 +13,13 @@ import {
checkRoomTitle, checkRoomTitle,
mockRandomMessage mockRandomMessage
} from '../../helpers/app'; } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
import random from '../../helpers/random'; import random from '../../helpers/random';
describe('Broadcast room', () => { describe('Broadcast room', () => {
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser; let user: ITestUser;
let otherUser: ICreateUser; let otherUser: ITestUser;
let message: string; let message: string;
const room = `broadcast${random()}`; const room = `broadcast${random()}`;

View File

@ -1,7 +1,7 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { navigateToLogin, login, sleep, platformTypes, TTextMatcher } from '../../helpers/app'; import { navigateToLogin, login, sleep, platformTypes, TTextMatcher } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
import random from '../../helpers/random'; import random from '../../helpers/random';
const scrollDown = 200; const scrollDown = 200;
@ -13,7 +13,7 @@ async function waitForToast() {
describe('Profile screen', () => { describe('Profile screen', () => {
let scrollViewType: string; let scrollViewType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser; let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();

View File

@ -1,17 +1,17 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { navigateToLogin, login, platformTypes, TTextMatcher } from '../../helpers/app'; import { navigateToLogin, login, platformTypes, TTextMatcher } from '../../helpers/app';
import { createRandomRoom, createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomRoom, createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Settings screen', () => { describe('Settings screen', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser; let user: ITestUser;
let room: string; let room: string;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();
room = await createRandomRoom(user); ({ name: room } = await createRandomRoom(user));
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin(); await navigateToLogin();

View File

@ -2,7 +2,7 @@ import { expect } from 'detox';
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, tapBack, searchRoom, platformTypes, TTextMatcher, mockRandomMessage } from '../../helpers/app'; import { navigateToLogin, login, tapBack, searchRoom, platformTypes, TTextMatcher, mockRandomMessage } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
const room = data.channels.detoxpublic.name; const room = data.channels.detoxpublic.name;
@ -24,7 +24,7 @@ async function navigateToRoomActions() {
describe('Join public room', () => { describe('Join public room', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser; let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();

View File

@ -1,10 +1,10 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { navigateToLogin, login, sleep } from '../../helpers/app'; import { navigateToLogin, login, sleep } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Status screen', () => { describe('Status screen', () => {
let user: ICreateUser; let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();

View File

@ -1,6 +1,6 @@
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, checkServer, expectValidRegisterOrRetry } from '../../helpers/app'; import { navigateToLogin, login, checkServer, expectValidRegisterOrRetry } from '../../helpers/app';
import { createRandomRoom, createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomRoom, createRandomUser, ITestUser } from '../../helpers/data_setup';
const reopenAndCheckServer = async (server: string) => { const reopenAndCheckServer = async (server: string) => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true }); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true });
@ -11,12 +11,12 @@ const reopenAndCheckServer = async (server: string) => {
}; };
describe('Change server', () => { describe('Change server', () => {
let user: ICreateUser; let user: ITestUser;
let room: string; let room: string;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();
room = await createRandomRoom(user); ({ name: room } = await createRandomRoom(user));
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(user.username, user.password); await login(user.username, user.password);

View File

@ -2,7 +2,7 @@ import { expect } from 'detox';
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, searchRoom, mockRandomMessage } from '../../helpers/app'; import { navigateToLogin, login, searchRoom, mockRandomMessage } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
const room = data.channels.detoxpublicprotected.name; const room = data.channels.detoxpublicprotected.name;
const { joinCode } = data.channels.detoxpublicprotected; const { joinCode } = data.channels.detoxpublicprotected;
@ -34,7 +34,7 @@ async function openJoinCode() {
} }
describe('Join protected room', () => { describe('Join protected room', () => {
let user: ICreateUser; let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();

View File

@ -1,6 +1,6 @@
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, tapBack, sleep } from '../../helpers/app'; import { navigateToLogin, login, tapBack, sleep } from '../../helpers/app';
import { createRandomTeam, createRandomUser, ICreateUser, sendMessage } from '../../helpers/data_setup'; import { createRandomTeam, createRandomUser, ITestUser, sendMessage } from '../../helpers/data_setup';
import random from '../../helpers/random'; import random from '../../helpers/random';
async function navigateToRoom(search: string) { async function navigateToRoom(search: string) {
@ -19,8 +19,8 @@ async function navigateToRoom(search: string) {
} }
describe('Join room from directory', () => { describe('Join room from directory', () => {
let user: ICreateUser; let user: ITestUser;
let otherUser: ICreateUser; let otherUser: ITestUser;
let team: string; let team: string;
beforeAll(async () => { beforeAll(async () => {

View File

@ -8,12 +8,12 @@ import {
TTextMatcher, TTextMatcher,
expectValidRegisterOrRetry expectValidRegisterOrRetry
} from '../../helpers/app'; } from '../../helpers/app';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Delete server', () => { describe('Delete server', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser; let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser(); user = await createRandomUser();

View File

@ -9,7 +9,8 @@ import {
TTextMatcher, TTextMatcher,
expectValidRegisterOrRetry expectValidRegisterOrRetry
} from '../../helpers/app'; } from '../../helpers/app';
import { get, login, sendMessage } from '../../helpers/data_setup'; import { createRandomRoom, createRandomUser, get, login, sendMessage } from '../../helpers/data_setup';
import random from '../../helpers/random';
const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' }; const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
@ -24,20 +25,24 @@ const getDeepLink = (method: string, server: string, params?: string) => {
describe('Deep linking', () => { describe('Deep linking', () => {
let userId: string; let userId: string;
let authToken: string; let authToken: string;
let scrollViewType: string;
let threadId: string; let threadId: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
const threadMessage = `to-thread-${data.random}`; let rid: string;
let room: string;
const threadMessage = `to-thread-${random()}`;
beforeAll(async () => { beforeAll(async () => {
const loginResult = await login(data.users.regular.username, data.users.regular.password); const user = await createRandomUser();
({ _id: rid, name: room } = await createRandomRoom(user, 'p'));
const loginResult = await login(user.username, user.password);
({ userId, authToken } = loginResult); ({ userId, authToken } = loginResult);
const deviceType = device.getPlatform(); const deviceType = device.getPlatform();
amp = deviceType === 'android' ? '\\&' : '&'; amp = deviceType === 'android' ? '\\&' : '&';
({ scrollViewType, textMatcher } = platformTypes[deviceType]); ({ textMatcher } = platformTypes[deviceType]);
// create a thread with api // create a thread with api
const result = await sendMessage(data.users.regular, data.groups.alternate2.name, threadMessage); const result = await sendMessage(user, room, threadMessage);
threadId = result.message._id; threadId = result.message._id;
await sendMessage(data.users.regular, result.message.rid, data.random, threadId); await sendMessage(user, result.message.rid, random(), threadId);
}); });
describe('Authentication', () => { describe('Authentication', () => {
@ -56,13 +61,9 @@ describe('Deep linking', () => {
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: true, newInstance: true,
url: getDeepLink( url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=${userId}${amp}token=${authToken}${amp}path=group/${room}`)
DEEPLINK_METHODS.AUTH,
data.server,
`userId=${userId}${amp}token=${authToken}${amp}path=group/${data.groups.private.name}`
)
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
await tapBack(); await tapBack();
@ -70,7 +71,7 @@ describe('Deep linking', () => {
.toBeVisible() .toBeVisible()
.withTimeout(10000); .withTimeout(10000);
await checkServer(data.server); await checkServer(data.server);
await waitFor(element(by.id(`rooms-list-view-item-${data.groups.private.name}`))) await waitFor(element(by.id(`rooms-list-view-item-${room}`)))
.toExist() .toExist()
.withTimeout(2000); .withTimeout(2000);
}; };
@ -82,10 +83,11 @@ describe('Deep linking', () => {
it('should authenticate while logged in another server', async () => { it('should authenticate while logged in another server', async () => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToRegister(data.alternateServer); await navigateToRegister(data.alternateServer);
await element(by.id('register-view-name')).replaceText(data.registeringUser4.username); const randomUser = data.randomUser();
await element(by.id('register-view-username')).replaceText(data.registeringUser4.username); await element(by.id('register-view-name')).replaceText(randomUser.name);
await element(by.id('register-view-email')).replaceText(data.registeringUser4.email); await element(by.id('register-view-username')).replaceText(randomUser.username);
await element(by.id('register-view-password')).replaceText(data.registeringUser4.password); 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 element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform()); await expectValidRegisterOrRetry(device.getPlatform());
await authAndNavigate(); await authAndNavigate();
@ -98,9 +100,9 @@ describe('Deep linking', () => {
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: true, newInstance: true,
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${data.groups.private.name}`) url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
}); });
@ -109,7 +111,7 @@ describe('Deep linking', () => {
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: true, newInstance: true,
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${data.groups.alternate2.name}/thread/${threadId}`) url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}/thread/${threadId}`)
}); });
await waitFor(element(by.id(`room-view-title-${threadMessage}`))) await waitFor(element(by.id(`room-view-title-${threadMessage}`)))
.toExist() .toExist()
@ -117,13 +119,12 @@ describe('Deep linking', () => {
}); });
it('should navigate to the room using rid', async () => { it('should navigate to the room using rid', async () => {
const roomResult = await get(`groups.info?roomName=${data.groups.private.name}`);
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: true, newInstance: true,
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `rid=${roomResult.data.group._id}`) url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `rid=${rid}`)
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
await tapBack(); await tapBack();
@ -137,9 +138,9 @@ describe('Deep linking', () => {
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: false, newInstance: false,
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${data.groups.private.name}`) url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
await tapBack(); await tapBack();
@ -168,13 +169,13 @@ describe('Deep linking', () => {
ejson: EJSON.stringify({ ejson: EJSON.stringify({
rid: null, rid: null,
host: data.server, host: data.server,
name: data.groups.private.name, name: room,
type: 'p' type: 'p'
}) })
} }
} }
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
await tapBack(); await tapBack();
@ -199,9 +200,9 @@ describe('Deep linking', () => {
await device.launchApp({ await device.launchApp({
permissions: { notifications: 'YES' }, permissions: { notifications: 'YES' },
newInstance: true, newInstance: true,
url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${data.groups.private.name}`) url: getDeepLink(DEEPLINK_METHODS.ROOM, data.server, `path=group/${room}`)
}); });
await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) await waitFor(element(by.id(`room-view-title-${room}`)))
.toExist() .toExist()
.withTimeout(30000); .withTimeout(30000);
}); });

View File

@ -1,10 +1,8 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { navigateToLogin, login, sleep } from '../../helpers/app'; import { navigateToLogin, login } from '../../helpers/app';
import { post } from '../../helpers/data_setup'; import { createRandomUser, ITestUser, post } from '../../helpers/data_setup';
import data from '../../data';
const testuser = data.users.regular;
const defaultLaunchArgs = { permissions: { notifications: 'YES' } } as Detox.DeviceLaunchAppConfig; const defaultLaunchArgs = { permissions: { notifications: 'YES' } } as Detox.DeviceLaunchAppConfig;
const navToLanguage = async () => { const navToLanguage = async () => {
@ -81,10 +79,12 @@ describe('i18n', () => {
}); });
describe('Rocket.Chat language', () => { describe('Rocket.Chat language', () => {
let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ ...defaultLaunchArgs, delete: true }); await device.launchApp({ ...defaultLaunchArgs, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(testuser.username, testuser.password); await login(user.username, user.password);
}); });
it("should select 'en'", async () => { it("should select 'en'", async () => {
@ -119,10 +119,6 @@ describe('i18n', () => {
await element(by.id('sidebar-close-drawer')).tap(); await element(by.id('sidebar-close-drawer')).tap();
}); });
afterAll(async () => {
await post('users.setPreferences', { data: { language: 'en' } }); // Set back to english
});
// it("should set unsupported language and fallback to 'en'", async () => { // it("should set unsupported language and fallback to 'en'", async () => {
// await post('users.setPreferences', { data: { language: 'eo' } }); // Set language to Esperanto // await post('users.setPreferences', { data: { language: 'eo' } }); // Set language to Esperanto
// await device.launchApp({ ...defaultLaunchArgs, newInstance: true }); // await device.launchApp({ ...defaultLaunchArgs, newInstance: true });

View File

@ -1,7 +1,7 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { login, navigateToLogin } from '../../helpers/app'; import { login, navigateToLogin } from '../../helpers/app';
import data from '../../data'; import { createRandomUser } from '../../helpers/data_setup';
const goToDisplayPref = async () => { const goToDisplayPref = async () => {
await expect(element(by.id('rooms-list-view-sidebar'))).toBeVisible(); await expect(element(by.id('rooms-list-view-sidebar'))).toBeVisible();
@ -18,9 +18,10 @@ const goToRoomList = async () => {
describe('Display prefs', () => { describe('Display prefs', () => {
beforeAll(async () => { beforeAll(async () => {
const user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(user.username, user.password);
}); });
describe('Render', () => { describe('Render', () => {

View File

@ -1,18 +1,20 @@
import data from '../../data';
import { navigateToLogin, login, sleep, tapBack, navigateToRoom, checkRoomTitle } from '../../helpers/app'; import { navigateToLogin, login, sleep, tapBack, navigateToRoom, checkRoomTitle } from '../../helpers/app';
import { sendMessage, post } from '../../helpers/data_setup'; import { sendMessage, post, ITestUser, createRandomUser, createRandomRoom } from '../../helpers/data_setup';
const waitForInAppNotificationAnimation = async () => { const waitForInAppNotificationAnimation = async () => {
await sleep(500); await sleep(500);
}; };
const sender = data.users.alternate;
const receiver = data.users.inapp;
describe('InApp Notification', () => { describe('InApp Notification', () => {
let dmCreatedRid: string; let dmCreatedRid: string;
let sender: ITestUser;
let receiver: ITestUser;
let room: string;
beforeAll(async () => { beforeAll(async () => {
sender = await createRandomUser();
receiver = await createRandomUser();
({ name: room } = await createRandomRoom(sender));
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(receiver.username, receiver.password); await login(receiver.username, receiver.password);
@ -37,7 +39,7 @@ describe('InApp Notification', () => {
describe('receive in another room', () => { describe('receive in another room', () => {
const text = 'Another msg'; const text = 'Another msg';
it('should receive and tap InAppNotification while in another room', async () => { it('should receive and tap InAppNotification while in another room', async () => {
await navigateToRoom(data.userRegularChannels.detoxpublic.name); await navigateToRoom(room);
await sendMessage(sender, dmCreatedRid, text); await sendMessage(sender, dmCreatedRid, text);
await waitFor(element(by.id(`in-app-notification-${text}`))) await waitFor(element(by.id(`in-app-notification-${text}`)))
.toExist() .toExist()

View File

@ -1,12 +1,14 @@
import { expect } from 'detox'; import { expect } from 'detox';
import data from '../../data';
import { navigateToLogin, platformTypes, TTextMatcher } from '../../helpers/app'; import { navigateToLogin, platformTypes, TTextMatcher } from '../../helpers/app';
import { createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Forgot password screen', () => { describe('Forgot password screen', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin(); await navigateToLogin();
@ -32,7 +34,7 @@ describe('Forgot password screen', () => {
describe('Usage', () => { describe('Usage', () => {
it('should reset password and navigate to login', async () => { it('should reset password and navigate to login', async () => {
await element(by.id('forgot-password-view-email')).replaceText(data.users.existing.email); await element(by.id('forgot-password-view-email')).replaceText(user.email);
await element(by.id('forgot-password-view-submit')).tap(); await element(by.id('forgot-password-view-submit')).tap();
await waitFor(element(by[textMatcher]('OK'))) await waitFor(element(by[textMatcher]('OK')))
.toExist() .toExist()

View File

@ -8,13 +8,14 @@ describe('Create user screen', () => {
}); });
describe('Usage', () => { describe('Usage', () => {
it('should register', async () => { it('should register', async () => {
await element(by.id('register-view-name')).replaceText(data.registeringUser.username); const user = data.randomUser();
await element(by.id('register-view-name')).replaceText(user.username);
await element(by.id('register-view-name')).tapReturnKey(); await element(by.id('register-view-name')).tapReturnKey();
await element(by.id('register-view-username')).replaceText(data.registeringUser.username); await element(by.id('register-view-username')).replaceText(user.username);
await element(by.id('register-view-username')).tapReturnKey(); await element(by.id('register-view-username')).tapReturnKey();
await element(by.id('register-view-email')).replaceText(data.registeringUser.email); await element(by.id('register-view-email')).replaceText(user.email);
await element(by.id('register-view-email')).tapReturnKey(); await element(by.id('register-view-email')).tapReturnKey();
await element(by.id('register-view-password')).replaceText(data.registeringUser.password); await element(by.id('register-view-password')).replaceText(user.password);
await element(by.id('register-view-password')).tapReturnKey(); await element(by.id('register-view-password')).tapReturnKey();
await expectValidRegisterOrRetry(device.getPlatform()); await expectValidRegisterOrRetry(device.getPlatform());

View File

@ -1,10 +1,12 @@
import { navigateToLogin, tapBack, platformTypes, navigateToWorkspace, login, TTextMatcher } from '../../helpers/app'; import { navigateToLogin, tapBack, platformTypes, navigateToWorkspace, login, TTextMatcher } from '../../helpers/app';
import data from '../../data'; import { createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Login screen', () => { describe('Login screen', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin(); await navigateToLogin();
@ -12,7 +14,7 @@ describe('Login screen', () => {
describe('Usage', () => { describe('Usage', () => {
it('should insert wrong password and get error', async () => { it('should insert wrong password and get error', async () => {
await element(by.id('login-view-email')).replaceText(data.users.regular.username); await element(by.id('login-view-email')).replaceText(user.username);
await element(by.id('login-view-email')).tapReturnKey(); await element(by.id('login-view-email')).tapReturnKey();
await element(by.id('login-view-password')).replaceText('NotMyActualPassword'); await element(by.id('login-view-password')).replaceText('NotMyActualPassword');
await element(by.id('login-view-password')).tapReturnKey(); await element(by.id('login-view-password')).tapReturnKey();
@ -23,7 +25,7 @@ describe('Login screen', () => {
}); });
it('should login with success', async () => { it('should login with success', async () => {
await element(by.id('login-view-password')).replaceText(data.users.regular.password); await element(by.id('login-view-password')).replaceText(user.password);
await element(by.id('login-view-password')).tapReturnKey(); await element(by.id('login-view-password')).tapReturnKey();
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toBeVisible() .toBeVisible()
@ -35,7 +37,7 @@ describe('Login screen', () => {
await navigateToWorkspace(); await navigateToWorkspace();
await tapBack(); await tapBack();
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(user.username, user.password);
}); });
}); });
}); });

View File

@ -1,13 +1,14 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { login, navigateToLogin, logout, tapBack, searchRoom } from '../../helpers/app'; import { login, navigateToLogin, logout, tapBack, searchRoom } from '../../helpers/app';
import data from '../../data'; import { createRandomUser } from '../../helpers/data_setup';
describe('Rooms list screen', () => { describe('Rooms list screen', () => {
beforeAll(async () => { beforeAll(async () => {
const user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(user.username, user.password);
}); });
describe('Render', () => { describe('Render', () => {

View File

@ -1,17 +1,20 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { login, navigateToLogin, logout, tapBack, tryTapping, tapAndWaitFor } from '../../helpers/app'; import { login, navigateToLogin, logout, tapBack, tapAndWaitFor } from '../../helpers/app';
import data from '../../data'; import data from '../../data';
import { createRandomUser, ITestUser } from '../../helpers/data_setup';
describe('Server history', () => { describe('Server history', () => {
let user: ITestUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
}); });
describe('Usage', () => { describe('Usage', () => {
it('should login, save server as history and logout', async () => { it('should login, save server as history and logout', async () => {
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(user.username, user.password);
await logout(); await logout();
await waitFor(element(by.id('new-server-view'))) await waitFor(element(by.id('new-server-view')))
.toBeVisible() .toBeVisible()
@ -30,7 +33,7 @@ describe('Server history', () => {
await waitFor(element(by.id('login-view-email'))) await waitFor(element(by.id('login-view-email')))
.toBeVisible() .toBeVisible()
.withTimeout(5000); .withTimeout(5000);
await expect(element(by.label(data.users.regular.username).withAncestor(by.id('login-view-email')))); await expect(element(by.label(user.username).withAncestor(by.id('login-view-email'))));
}); });
it('should delete server from history', async () => { it('should delete server from history', async () => {

View File

@ -1,16 +1,18 @@
import { expect } from 'detox'; import { expect } from 'detox';
import data from '../../data'; import { tapBack, navigateToLogin, login, platformTypes, TTextMatcher, tapAndWaitFor } from '../../helpers/app';
import { tapBack, navigateToLogin, login, tryTapping, platformTypes, TTextMatcher, tapAndWaitFor } from '../../helpers/app'; import { createRandomUser } from '../../helpers/data_setup';
import random from '../../helpers/random';
describe('Create room screen', () => { describe('Create room screen', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
beforeAll(async () => { beforeAll(async () => {
const user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin(); await navigateToLogin();
await login(data.users.regular.username, data.users.regular.password); await login(user.username, user.password);
}); });
describe('New Message', () => { describe('New Message', () => {
@ -139,7 +141,7 @@ describe('Create room screen', () => {
}); });
it('should create public room', async () => { it('should create public room', async () => {
const room = `public${data.random}`; const room = `public${random()}`;
await element(by.id('create-channel-name')).replaceText(room); await element(by.id('create-channel-name')).replaceText(room);
await element(by.id('create-channel-name')).tapReturnKey(); await element(by.id('create-channel-name')).tapReturnKey();
await element(by.id('create-channel-type')).tap(); await element(by.id('create-channel-type')).tap();
@ -166,7 +168,7 @@ describe('Create room screen', () => {
}); });
it('should create private room', async () => { it('should create private room', async () => {
const room = `private${data.random}`; const room = `private${random()}`;
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toExist() .toExist()
.withTimeout(5000); .withTimeout(5000);
@ -211,7 +213,7 @@ describe('Create room screen', () => {
}); });
it('should create empty room', async () => { it('should create empty room', async () => {
const room = `empty${data.random}`; const room = `empty${random()}`;
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toExist() .toExist()
.withTimeout(10000); .withTimeout(10000);