From 8d9644c8ac2b1056c69b2bc872d4e4e421a496f5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 22 Feb 2023 14:46:16 -0300 Subject: [PATCH] refactoring --- e2e/helpers/data_setup.ts | 16 +++-- e2e/tests/assorted/01-e2eencryption.spec.ts | 6 +- e2e/tests/assorted/02-broadcast.spec.ts | 6 +- e2e/tests/assorted/03-profile.spec.ts | 4 +- e2e/tests/assorted/04-setting.spec.ts | 6 +- e2e/tests/assorted/05-joinpublicroom.spec.ts | 4 +- e2e/tests/assorted/06-status.spec.ts | 4 +- e2e/tests/assorted/07-changeserver.spec.ts | 6 +- .../assorted/08-joinprotectedroom.spec.ts | 4 +- .../assorted/09-joinfromdirectory.spec.ts | 6 +- e2e/tests/assorted/10-deleteserver.spec.ts | 4 +- e2e/tests/assorted/11-deeplinking.spec.ts | 61 ++++++++++--------- e2e/tests/assorted/12-i18n.spec.ts | 14 ++--- e2e/tests/assorted/13-display-pref.spec.ts | 5 +- .../assorted/14-in-app-notification.spec.ts | 14 +++-- .../onboarding/03-forgotpassword.spec.ts | 6 +- e2e/tests/onboarding/04-createuser.spec.ts | 9 +-- e2e/tests/onboarding/05-login.spec.ts | 10 +-- e2e/tests/onboarding/06-roomslist.spec.ts | 5 +- .../onboarding/07-server-history.spec.ts | 9 ++- e2e/tests/room/01-createroom.spec.ts | 14 +++-- 21 files changed, 115 insertions(+), 98 deletions(-) diff --git a/e2e/helpers/data_setup.ts b/e2e/helpers/data_setup.ts index 82175c731..ed9215738 100644 --- a/e2e/helpers/data_setup.ts +++ b/e2e/helpers/data_setup.ts @@ -29,14 +29,14 @@ const login = async (username: string, password: string) => { return { authToken, userId }; }; -export interface ICreateUser { +export interface ITestUser { username: string; password: string; name: string; email: string; } -export const createRandomUser = async (): Promise => { +export const createRandomUser = async (): Promise => { try { await login(data.adminUser, data.adminPassword); 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 => { +export const createRandomRoom = async ( + user: { username: string; password: string }, + type: 'p' | 'c' = 'c' +): Promise<{ _id: string; name: string }> => { try { await login(user.username, user.password); const room = `room${random()}`; 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 }); - 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) { console.log(JSON.stringify(e)); throw new Error('Failed to create room'); diff --git a/e2e/tests/assorted/01-e2eencryption.spec.ts b/e2e/tests/assorted/01-e2eencryption.spec.ts index b61a37130..5a1069bcb 100644 --- a/e2e/tests/assorted/01-e2eencryption.spec.ts +++ b/e2e/tests/assorted/01-e2eencryption.spec.ts @@ -14,7 +14,7 @@ import { mockRandomMessage } from '../../helpers/app'; import data from '../../data'; -import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; import random from '../../helpers/random'; const checkServer = async (server: string) => { @@ -71,8 +71,8 @@ async function navigateSecurityPrivacy() { describe('E2E Encryption', () => { const room = `encrypted${random()}`; - let user: ICreateUser; - let otherUser: ICreateUser; + let user: ITestUser; + let otherUser: ITestUser; let mockedMessageText: string; const newPassword = 'abc'; diff --git a/e2e/tests/assorted/02-broadcast.spec.ts b/e2e/tests/assorted/02-broadcast.spec.ts index a35aafc2b..051ed0015 100644 --- a/e2e/tests/assorted/02-broadcast.spec.ts +++ b/e2e/tests/assorted/02-broadcast.spec.ts @@ -13,13 +13,13 @@ import { checkRoomTitle, mockRandomMessage } from '../../helpers/app'; -import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; import random from '../../helpers/random'; describe('Broadcast room', () => { let textMatcher: TTextMatcher; - let user: ICreateUser; - let otherUser: ICreateUser; + let user: ITestUser; + let otherUser: ITestUser; let message: string; const room = `broadcast${random()}`; diff --git a/e2e/tests/assorted/03-profile.spec.ts b/e2e/tests/assorted/03-profile.spec.ts index 725531886..033693e8c 100644 --- a/e2e/tests/assorted/03-profile.spec.ts +++ b/e2e/tests/assorted/03-profile.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'detox'; 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'; const scrollDown = 200; @@ -13,7 +13,7 @@ async function waitForToast() { describe('Profile screen', () => { let scrollViewType: string; let textMatcher: TTextMatcher; - let user: ICreateUser; + let user: ITestUser; beforeAll(async () => { user = await createRandomUser(); diff --git a/e2e/tests/assorted/04-setting.spec.ts b/e2e/tests/assorted/04-setting.spec.ts index 5da09379f..ff9efd761 100644 --- a/e2e/tests/assorted/04-setting.spec.ts +++ b/e2e/tests/assorted/04-setting.spec.ts @@ -1,17 +1,17 @@ import { expect } from 'detox'; 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', () => { let alertButtonType: string; let textMatcher: TTextMatcher; - let user: ICreateUser; + let user: ITestUser; let room: string; beforeAll(async () => { user = await createRandomUser(); - room = await createRandomRoom(user); + ({ name: room } = await createRandomRoom(user)); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); diff --git a/e2e/tests/assorted/05-joinpublicroom.spec.ts b/e2e/tests/assorted/05-joinpublicroom.spec.ts index a5968e59b..2ef99fbd9 100644 --- a/e2e/tests/assorted/05-joinpublicroom.spec.ts +++ b/e2e/tests/assorted/05-joinpublicroom.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'detox'; import data from '../../data'; 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; @@ -24,7 +24,7 @@ async function navigateToRoomActions() { describe('Join public room', () => { let alertButtonType: string; let textMatcher: TTextMatcher; - let user: ICreateUser; + let user: ITestUser; beforeAll(async () => { user = await createRandomUser(); diff --git a/e2e/tests/assorted/06-status.spec.ts b/e2e/tests/assorted/06-status.spec.ts index 2f41be364..67cb89006 100644 --- a/e2e/tests/assorted/06-status.spec.ts +++ b/e2e/tests/assorted/06-status.spec.ts @@ -1,10 +1,10 @@ import { expect } from 'detox'; import { navigateToLogin, login, sleep } from '../../helpers/app'; -import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; describe('Status screen', () => { - let user: ICreateUser; + let user: ITestUser; beforeAll(async () => { user = await createRandomUser(); diff --git a/e2e/tests/assorted/07-changeserver.spec.ts b/e2e/tests/assorted/07-changeserver.spec.ts index 614b38072..98c8205f0 100644 --- a/e2e/tests/assorted/07-changeserver.spec.ts +++ b/e2e/tests/assorted/07-changeserver.spec.ts @@ -1,6 +1,6 @@ import data from '../../data'; 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) => { await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true }); @@ -11,12 +11,12 @@ const reopenAndCheckServer = async (server: string) => { }; describe('Change server', () => { - let user: ICreateUser; + let user: ITestUser; let room: string; beforeAll(async () => { user = await createRandomUser(); - room = await createRandomRoom(user); + ({ name: room } = await createRandomRoom(user)); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await navigateToLogin(); await login(user.username, user.password); diff --git a/e2e/tests/assorted/08-joinprotectedroom.spec.ts b/e2e/tests/assorted/08-joinprotectedroom.spec.ts index 812b58fe2..6b8990ba5 100644 --- a/e2e/tests/assorted/08-joinprotectedroom.spec.ts +++ b/e2e/tests/assorted/08-joinprotectedroom.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'detox'; import data from '../../data'; 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 { joinCode } = data.channels.detoxpublicprotected; @@ -34,7 +34,7 @@ async function openJoinCode() { } describe('Join protected room', () => { - let user: ICreateUser; + let user: ITestUser; beforeAll(async () => { user = await createRandomUser(); diff --git a/e2e/tests/assorted/09-joinfromdirectory.spec.ts b/e2e/tests/assorted/09-joinfromdirectory.spec.ts index 2794a3757..2ee01f415 100644 --- a/e2e/tests/assorted/09-joinfromdirectory.spec.ts +++ b/e2e/tests/assorted/09-joinfromdirectory.spec.ts @@ -1,6 +1,6 @@ import data from '../../data'; 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'; async function navigateToRoom(search: string) { @@ -19,8 +19,8 @@ async function navigateToRoom(search: string) { } describe('Join room from directory', () => { - let user: ICreateUser; - let otherUser: ICreateUser; + let user: ITestUser; + let otherUser: ITestUser; let team: string; beforeAll(async () => { diff --git a/e2e/tests/assorted/10-deleteserver.spec.ts b/e2e/tests/assorted/10-deleteserver.spec.ts index 8fa895f81..c70b83e8a 100644 --- a/e2e/tests/assorted/10-deleteserver.spec.ts +++ b/e2e/tests/assorted/10-deleteserver.spec.ts @@ -8,12 +8,12 @@ import { TTextMatcher, expectValidRegisterOrRetry } from '../../helpers/app'; -import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; describe('Delete server', () => { let alertButtonType: string; let textMatcher: TTextMatcher; - let user: ICreateUser; + let user: ITestUser; beforeAll(async () => { user = await createRandomUser(); diff --git a/e2e/tests/assorted/11-deeplinking.spec.ts b/e2e/tests/assorted/11-deeplinking.spec.ts index 037fbcf6e..b75034da3 100644 --- a/e2e/tests/assorted/11-deeplinking.spec.ts +++ b/e2e/tests/assorted/11-deeplinking.spec.ts @@ -9,7 +9,8 @@ import { TTextMatcher, expectValidRegisterOrRetry } 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' }; @@ -24,20 +25,24 @@ const getDeepLink = (method: string, server: string, params?: string) => { describe('Deep linking', () => { let userId: string; let authToken: string; - let scrollViewType: string; let threadId: string; let textMatcher: TTextMatcher; - const threadMessage = `to-thread-${data.random}`; + let rid: string; + let room: string; + const threadMessage = `to-thread-${random()}`; + 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); const deviceType = device.getPlatform(); amp = deviceType === 'android' ? '\\&' : '&'; - ({ scrollViewType, textMatcher } = platformTypes[deviceType]); + ({ textMatcher } = platformTypes[deviceType]); // 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; - await sendMessage(data.users.regular, result.message.rid, data.random, threadId); + await sendMessage(user, result.message.rid, random(), threadId); }); describe('Authentication', () => { @@ -56,13 +61,9 @@ describe('Deep linking', () => { await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, - url: getDeepLink( - DEEPLINK_METHODS.AUTH, - data.server, - `userId=${userId}${amp}token=${authToken}${amp}path=group/${data.groups.private.name}` - ) + url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=${userId}${amp}token=${authToken}${amp}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() .withTimeout(30000); await tapBack(); @@ -70,7 +71,7 @@ describe('Deep linking', () => { .toBeVisible() .withTimeout(10000); 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() .withTimeout(2000); }; @@ -82,10 +83,11 @@ describe('Deep linking', () => { it('should authenticate while logged in another server', async () => { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await navigateToRegister(data.alternateServer); - await element(by.id('register-view-name')).replaceText(data.registeringUser4.username); - await element(by.id('register-view-username')).replaceText(data.registeringUser4.username); - await element(by.id('register-view-email')).replaceText(data.registeringUser4.email); - await element(by.id('register-view-password')).replaceText(data.registeringUser4.password); + 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()); await authAndNavigate(); @@ -98,9 +100,9 @@ describe('Deep linking', () => { await device.launchApp({ permissions: { notifications: 'YES' }, 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() .withTimeout(30000); }); @@ -109,7 +111,7 @@ describe('Deep linking', () => { await device.launchApp({ permissions: { notifications: 'YES' }, 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}`))) .toExist() @@ -117,13 +119,12 @@ describe('Deep linking', () => { }); it('should navigate to the room using rid', async () => { - const roomResult = await get(`groups.info?roomName=${data.groups.private.name}`); await device.launchApp({ permissions: { notifications: 'YES' }, 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() .withTimeout(30000); await tapBack(); @@ -137,9 +138,9 @@ describe('Deep linking', () => { await device.launchApp({ permissions: { notifications: 'YES' }, 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() .withTimeout(30000); await tapBack(); @@ -168,13 +169,13 @@ describe('Deep linking', () => { ejson: EJSON.stringify({ rid: null, host: data.server, - name: data.groups.private.name, + name: room, type: 'p' }) } } }); - await waitFor(element(by.id(`room-view-title-${data.groups.private.name}`))) + await waitFor(element(by.id(`room-view-title-${room}`))) .toExist() .withTimeout(30000); await tapBack(); @@ -199,9 +200,9 @@ describe('Deep linking', () => { await device.launchApp({ permissions: { notifications: 'YES' }, 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() .withTimeout(30000); }); diff --git a/e2e/tests/assorted/12-i18n.spec.ts b/e2e/tests/assorted/12-i18n.spec.ts index 29f310602..a1a335ec8 100644 --- a/e2e/tests/assorted/12-i18n.spec.ts +++ b/e2e/tests/assorted/12-i18n.spec.ts @@ -1,10 +1,8 @@ import { expect } from 'detox'; -import { navigateToLogin, login, sleep } from '../../helpers/app'; -import { post } from '../../helpers/data_setup'; -import data from '../../data'; +import { navigateToLogin, login } from '../../helpers/app'; +import { createRandomUser, ITestUser, post } from '../../helpers/data_setup'; -const testuser = data.users.regular; const defaultLaunchArgs = { permissions: { notifications: 'YES' } } as Detox.DeviceLaunchAppConfig; const navToLanguage = async () => { @@ -81,10 +79,12 @@ describe('i18n', () => { }); describe('Rocket.Chat language', () => { + let user: ITestUser; beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ ...defaultLaunchArgs, delete: true }); await navigateToLogin(); - await login(testuser.username, testuser.password); + await login(user.username, user.password); }); it("should select 'en'", async () => { @@ -119,10 +119,6 @@ describe('i18n', () => { 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 () => { // await post('users.setPreferences', { data: { language: 'eo' } }); // Set language to Esperanto // await device.launchApp({ ...defaultLaunchArgs, newInstance: true }); diff --git a/e2e/tests/assorted/13-display-pref.spec.ts b/e2e/tests/assorted/13-display-pref.spec.ts index 5ca1633d1..c56a47791 100644 --- a/e2e/tests/assorted/13-display-pref.spec.ts +++ b/e2e/tests/assorted/13-display-pref.spec.ts @@ -1,7 +1,7 @@ import { expect } from 'detox'; import { login, navigateToLogin } from '../../helpers/app'; -import data from '../../data'; +import { createRandomUser } from '../../helpers/data_setup'; const goToDisplayPref = async () => { await expect(element(by.id('rooms-list-view-sidebar'))).toBeVisible(); @@ -18,9 +18,10 @@ const goToRoomList = async () => { describe('Display prefs', () => { beforeAll(async () => { + const user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); + await login(user.username, user.password); }); describe('Render', () => { diff --git a/e2e/tests/assorted/14-in-app-notification.spec.ts b/e2e/tests/assorted/14-in-app-notification.spec.ts index 3c74648bb..661860d5c 100644 --- a/e2e/tests/assorted/14-in-app-notification.spec.ts +++ b/e2e/tests/assorted/14-in-app-notification.spec.ts @@ -1,18 +1,20 @@ -import data from '../../data'; 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 () => { await sleep(500); }; -const sender = data.users.alternate; -const receiver = data.users.inapp; - describe('InApp Notification', () => { let dmCreatedRid: string; + let sender: ITestUser; + let receiver: ITestUser; + let room: string; beforeAll(async () => { + sender = await createRandomUser(); + receiver = await createRandomUser(); + ({ name: room } = await createRandomRoom(sender)); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await navigateToLogin(); await login(receiver.username, receiver.password); @@ -37,7 +39,7 @@ describe('InApp Notification', () => { describe('receive in another room', () => { const text = 'Another msg'; 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 waitFor(element(by.id(`in-app-notification-${text}`))) .toExist() diff --git a/e2e/tests/onboarding/03-forgotpassword.spec.ts b/e2e/tests/onboarding/03-forgotpassword.spec.ts index bbad13c10..275866b12 100644 --- a/e2e/tests/onboarding/03-forgotpassword.spec.ts +++ b/e2e/tests/onboarding/03-forgotpassword.spec.ts @@ -1,12 +1,14 @@ import { expect } from 'detox'; -import data from '../../data'; import { navigateToLogin, platformTypes, TTextMatcher } from '../../helpers/app'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; describe('Forgot password screen', () => { let alertButtonType: string; let textMatcher: TTextMatcher; + let user: ITestUser; beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); @@ -32,7 +34,7 @@ describe('Forgot password screen', () => { describe('Usage', () => { 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 waitFor(element(by[textMatcher]('OK'))) .toExist() diff --git a/e2e/tests/onboarding/04-createuser.spec.ts b/e2e/tests/onboarding/04-createuser.spec.ts index ea01b83dd..e0e6738ac 100644 --- a/e2e/tests/onboarding/04-createuser.spec.ts +++ b/e2e/tests/onboarding/04-createuser.spec.ts @@ -8,13 +8,14 @@ describe('Create user screen', () => { }); describe('Usage', () => { 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-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-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-password')).replaceText(data.registeringUser.password); + await element(by.id('register-view-password')).replaceText(user.password); await element(by.id('register-view-password')).tapReturnKey(); await expectValidRegisterOrRetry(device.getPlatform()); diff --git a/e2e/tests/onboarding/05-login.spec.ts b/e2e/tests/onboarding/05-login.spec.ts index 40b6ee071..d7fd3817b 100644 --- a/e2e/tests/onboarding/05-login.spec.ts +++ b/e2e/tests/onboarding/05-login.spec.ts @@ -1,10 +1,12 @@ import { navigateToLogin, tapBack, platformTypes, navigateToWorkspace, login, TTextMatcher } from '../../helpers/app'; -import data from '../../data'; +import { createRandomUser, ITestUser } from '../../helpers/data_setup'; describe('Login screen', () => { let alertButtonType: string; let textMatcher: TTextMatcher; + let user: ITestUser; beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); @@ -12,7 +14,7 @@ describe('Login screen', () => { describe('Usage', () => { 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-password')).replaceText('NotMyActualPassword'); await element(by.id('login-view-password')).tapReturnKey(); @@ -23,7 +25,7 @@ describe('Login screen', () => { }); 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 waitFor(element(by.id('rooms-list-view'))) .toBeVisible() @@ -35,7 +37,7 @@ describe('Login screen', () => { await navigateToWorkspace(); await tapBack(); await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); + await login(user.username, user.password); }); }); }); diff --git a/e2e/tests/onboarding/06-roomslist.spec.ts b/e2e/tests/onboarding/06-roomslist.spec.ts index 8366d0c96..262426646 100644 --- a/e2e/tests/onboarding/06-roomslist.spec.ts +++ b/e2e/tests/onboarding/06-roomslist.spec.ts @@ -1,13 +1,14 @@ import { expect } from 'detox'; import { login, navigateToLogin, logout, tapBack, searchRoom } from '../../helpers/app'; -import data from '../../data'; +import { createRandomUser } from '../../helpers/data_setup'; describe('Rooms list screen', () => { beforeAll(async () => { + const user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true }); await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); + await login(user.username, user.password); }); describe('Render', () => { diff --git a/e2e/tests/onboarding/07-server-history.spec.ts b/e2e/tests/onboarding/07-server-history.spec.ts index ca9652b26..9b786fa31 100644 --- a/e2e/tests/onboarding/07-server-history.spec.ts +++ b/e2e/tests/onboarding/07-server-history.spec.ts @@ -1,17 +1,20 @@ 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 { createRandomUser, ITestUser } from '../../helpers/data_setup'; describe('Server history', () => { + let user: ITestUser; beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); }); describe('Usage', () => { it('should login, save server as history and logout', async () => { await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); + await login(user.username, user.password); await logout(); await waitFor(element(by.id('new-server-view'))) .toBeVisible() @@ -30,7 +33,7 @@ describe('Server history', () => { await waitFor(element(by.id('login-view-email'))) .toBeVisible() .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 () => { diff --git a/e2e/tests/room/01-createroom.spec.ts b/e2e/tests/room/01-createroom.spec.ts index e11dabfdb..6edc060d4 100644 --- a/e2e/tests/room/01-createroom.spec.ts +++ b/e2e/tests/room/01-createroom.spec.ts @@ -1,16 +1,18 @@ import { expect } from 'detox'; -import data from '../../data'; -import { tapBack, navigateToLogin, login, tryTapping, platformTypes, TTextMatcher, tapAndWaitFor } from '../../helpers/app'; +import { tapBack, navigateToLogin, login, platformTypes, TTextMatcher, tapAndWaitFor } from '../../helpers/app'; +import { createRandomUser } from '../../helpers/data_setup'; +import random from '../../helpers/random'; describe('Create room screen', () => { let alertButtonType: string; let textMatcher: TTextMatcher; beforeAll(async () => { + const user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); + await login(user.username, user.password); }); describe('New Message', () => { @@ -139,7 +141,7 @@ describe('Create room screen', () => { }); 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')).tapReturnKey(); await element(by.id('create-channel-type')).tap(); @@ -166,7 +168,7 @@ describe('Create room screen', () => { }); it('should create private room', async () => { - const room = `private${data.random}`; + const room = `private${random()}`; await waitFor(element(by.id('rooms-list-view'))) .toExist() .withTimeout(5000); @@ -211,7 +213,7 @@ describe('Create room screen', () => { }); it('should create empty room', async () => { - const room = `empty${data.random}`; + const room = `empty${random()}`; await waitFor(element(by.id('rooms-list-view'))) .toExist() .withTimeout(10000);