From cc121e66f5a360303d3bbdc011830fa6766d1c8d Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Wed, 22 Feb 2023 10:36:51 -0300 Subject: [PATCH] til changeserver --- e2e/data.ts | 5 +-- e2e/helpers/app.ts | 3 ++ e2e/helpers/data_setup.ts | 36 +++++++++++++------- e2e/tests/assorted/02-broadcast.spec.ts | 1 - e2e/tests/assorted/03-profile.spec.ts | 23 ++++++------- e2e/tests/assorted/04-setting.spec.ts | 13 ++++--- e2e/tests/assorted/05-joinpublicroom.spec.ts | 11 +++--- e2e/tests/assorted/06-status.spec.ts | 9 ++--- e2e/tests/assorted/07-changeserver.spec.ts | 29 +++++++++------- 9 files changed, 75 insertions(+), 55 deletions(-) diff --git a/e2e/data.ts b/e2e/data.ts index 916c7acb4..26eeadbe8 100644 --- a/e2e/data.ts +++ b/e2e/data.ts @@ -105,11 +105,12 @@ const data = { email: `mobile+registeringfour${value}@rocket.chat` }, random: value, - randomUser: (): { username: string; password: string; email: string } => { + randomUser: (): { username: string; name: string; password: string; email: string } => { const randomVal = random(); return { username: `user${randomVal}`, - password: '123', + name: `name${randomVal}`, + password: `password${randomVal}`, email: `mobile+${randomVal}@rocket.chat` }; } diff --git a/e2e/helpers/app.ts b/e2e/helpers/app.ts index 8e2af887a..2a6b72d48 100644 --- a/e2e/helpers/app.ts +++ b/e2e/helpers/app.ts @@ -95,6 +95,9 @@ async function logout() { await expect(element(by.id('new-server-view'))).toBeVisible(); } +/** + * @deprecated use mockRandomMessage + */ async function mockMessage(message: string, isThread = false) { const deviceType = device.getPlatform(); const { textMatcher } = platformTypes[deviceType]; diff --git a/e2e/helpers/data_setup.ts b/e2e/helpers/data_setup.ts index 489803a08..89f33935c 100644 --- a/e2e/helpers/data_setup.ts +++ b/e2e/helpers/data_setup.ts @@ -37,22 +37,17 @@ export interface ICreateUser { } export const createRandomUser = async (): Promise => { - await login(data.adminUser, data.adminPassword); - const val = random(5); - console.log(`Creating user user${val}`); - try { - const username = `user${val}`; - const password = `pass${val}`; - const name = `name${val}`; - const email = `mobile+${val}@rocket.chat`; + await login(data.adminUser, data.adminPassword); + const user = data.randomUser(); + console.log(`Creating user ${user.username}`); await rocketchat.post('users.create', { - username, - password, - name, - email + username: user.username, + password: user.password, + name: user.name, + email: user.email }); - return { username, password, name, email } as const; + return user; } catch (error) { console.log(JSON.stringify(error)); throw new Error('Failed to create user'); @@ -94,6 +89,21 @@ const createChannelIfNotExists = async (channelname: string) => { } }; +export const createRandomChannel = async (user: { username: string; password: string }) => { + await login(user.username, user.password); + const room = `room${random()}`; + console.log(`Creating public channel ${room}`); + try { + const result = await rocketchat.post('channels.create', { + name: room + }); + return result.data.channel.name; + } catch (e) { + console.log(JSON.stringify(e)); + throw new Error('Failed to create public channel'); + } +}; + const createTeamIfNotExists = async (teamname: string) => { console.log(`Creating private team ${teamname}`); try { diff --git a/e2e/tests/assorted/02-broadcast.spec.ts b/e2e/tests/assorted/02-broadcast.spec.ts index f49e52e43..a35aafc2b 100644 --- a/e2e/tests/assorted/02-broadcast.spec.ts +++ b/e2e/tests/assorted/02-broadcast.spec.ts @@ -13,7 +13,6 @@ import { checkRoomTitle, mockRandomMessage } from '../../helpers/app'; -import data from '../../data'; import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import random from '../../helpers/random'; diff --git a/e2e/tests/assorted/03-profile.spec.ts b/e2e/tests/assorted/03-profile.spec.ts index 113ff3205..725531886 100644 --- a/e2e/tests/assorted/03-profile.spec.ts +++ b/e2e/tests/assorted/03-profile.spec.ts @@ -1,29 +1,26 @@ import { expect } from 'detox'; import { navigateToLogin, login, sleep, platformTypes, TTextMatcher } from '../../helpers/app'; -import data from '../../data'; - -const profileChangeUser = data.users.profileChanges; +import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; +import random from '../../helpers/random'; const scrollDown = 200; async function waitForToast() { - // await waitFor(element(by.id('toast'))).toBeVisible().withTimeout(1000); - // await expect(element(by.id('toast'))).toBeVisible(); - // await waitFor(element(by.id('toast'))).not.toBeNotVisible().withTimeout(1000); - // await expect(element(by.id('toast'))).not.toBeVisible(); await sleep(600); } describe('Profile screen', () => { let scrollViewType: string; let textMatcher: TTextMatcher; + let user: ICreateUser; beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ scrollViewType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); - await login(profileChangeUser.username, profileChangeUser.password); + await login(user.username, user.password); await element(by.id('rooms-list-view-sidebar')).tap(); await waitFor(element(by.id('sidebar-view'))) .toBeVisible() @@ -97,8 +94,8 @@ describe('Profile screen', () => { describe('Usage', () => { it('should change name and username', async () => { - await element(by.id('profile-view-name')).replaceText(`${profileChangeUser.username}new`); - await element(by.id('profile-view-username')).replaceText(`${profileChangeUser.username}new`); + await element(by.id('profile-view-name')).replaceText(`${user.username}new`); + await element(by.id('profile-view-username')).replaceText(`${user.username}new`); await element(by.id('profile-view-list')).swipe('down'); await element(by.id('profile-view-submit')).tap(); await waitForToast(); @@ -108,8 +105,8 @@ describe('Profile screen', () => { await waitFor(element(by.id('profile-view-email'))) .toBeVisible() .withTimeout(2000); - await element(by.id('profile-view-email')).replaceText(`mobile+profileChangesNew${data.random}@rocket.chat`); - await element(by.id('profile-view-new-password')).replaceText(`${profileChangeUser.password}new`); + await element(by.id('profile-view-email')).replaceText(`mobile+profileChangesNew${random()}@rocket.chat`); + await element(by.id('profile-view-new-password')).replaceText(`${user.password}new`); await waitFor(element(by.id('profile-view-submit'))) .toExist() .withTimeout(2000); @@ -117,7 +114,7 @@ describe('Profile screen', () => { await waitFor(element(by.id('profile-view-enter-password-sheet'))) .toBeVisible() .withTimeout(2000); - await element(by.id('profile-view-enter-password-sheet')).replaceText(`${profileChangeUser.password}`); + await element(by.id('profile-view-enter-password-sheet')).replaceText(`${user.password}`); await element(by[textMatcher]('Save').withAncestor(by.id('action-sheet-content-with-input-and-submit'))) .atIndex(0) .tap(); diff --git a/e2e/tests/assorted/04-setting.spec.ts b/e2e/tests/assorted/04-setting.spec.ts index a22266b7e..a529b5706 100644 --- a/e2e/tests/assorted/04-setting.spec.ts +++ b/e2e/tests/assorted/04-setting.spec.ts @@ -1,18 +1,21 @@ import { expect } from 'detox'; import { navigateToLogin, login, platformTypes, TTextMatcher } from '../../helpers/app'; -import data from '../../data'; - -const testuser = data.users.regular; +import { createRandomChannel, createRandomUser, ICreateUser } from '../../helpers/data_setup'; describe('Settings screen', () => { let alertButtonType: string; let textMatcher: TTextMatcher; + let user: ICreateUser; + let channel: string; + beforeAll(async () => { + user = await createRandomUser(); + channel = await createRandomChannel(user); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); - await login(testuser.username, testuser.password); + await login(user.username, user.password); await waitFor(element(by.id('rooms-list-view'))) .toBeVisible() .withTimeout(10000); @@ -84,7 +87,7 @@ describe('Settings screen', () => { await waitFor(element(by.id('rooms-list-view'))) .toBeVisible() .withTimeout(5000); - await waitFor(element(by.id(`rooms-list-view-item-${data.groups.private.name}`))) + await waitFor(element(by.id(`rooms-list-view-item-${channel}`))) .toExist() .withTimeout(10000); }); diff --git a/e2e/tests/assorted/05-joinpublicroom.spec.ts b/e2e/tests/assorted/05-joinpublicroom.spec.ts index c05a3271f..a5968e59b 100644 --- a/e2e/tests/assorted/05-joinpublicroom.spec.ts +++ b/e2e/tests/assorted/05-joinpublicroom.spec.ts @@ -1,9 +1,9 @@ import { expect } from 'detox'; import data from '../../data'; -import { navigateToLogin, login, mockMessage, tapBack, searchRoom, platformTypes, TTextMatcher, sleep } from '../../helpers/app'; +import { navigateToLogin, login, tapBack, searchRoom, platformTypes, TTextMatcher, mockRandomMessage } from '../../helpers/app'; +import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; -const testuser = data.users.regular; const room = data.channels.detoxpublic.name; async function navigateToRoom() { @@ -24,11 +24,14 @@ async function navigateToRoomActions() { describe('Join public room', () => { let alertButtonType: string; let textMatcher: TTextMatcher; + let user: ICreateUser; + beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); ({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]); await navigateToLogin(); - await login(testuser.username, testuser.password); + await login(user.username, user.password); await navigateToRoom(); }); @@ -141,7 +144,7 @@ describe('Join public room', () => { }); it('should send message', async () => { - await mockMessage('message'); + await mockRandomMessage('message'); }); it('should have notifications and leave channel', async () => { diff --git a/e2e/tests/assorted/06-status.spec.ts b/e2e/tests/assorted/06-status.spec.ts index cf5f6d436..2f41be364 100644 --- a/e2e/tests/assorted/06-status.spec.ts +++ b/e2e/tests/assorted/06-status.spec.ts @@ -1,15 +1,16 @@ import { expect } from 'detox'; import { navigateToLogin, login, sleep } from '../../helpers/app'; -import data from '../../data'; - -const testuser = data.users.regular; +import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; describe('Status screen', () => { + let user: ICreateUser; + beforeAll(async () => { + user = await createRandomUser(); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await navigateToLogin(); - await login(testuser.username, testuser.password); + await login(user.username, user.password); await element(by.id('rooms-list-view-sidebar')).tap(); await waitFor(element(by.id('sidebar-view'))) diff --git a/e2e/tests/assorted/07-changeserver.spec.ts b/e2e/tests/assorted/07-changeserver.spec.ts index 6a1cca6e1..771282427 100644 --- a/e2e/tests/assorted/07-changeserver.spec.ts +++ b/e2e/tests/assorted/07-changeserver.spec.ts @@ -1,5 +1,6 @@ import data from '../../data'; -import { navigateToLogin, login, checkServer, sleep, expectValidRegisterOrRetry } from '../../helpers/app'; +import { navigateToLogin, login, checkServer, expectValidRegisterOrRetry } from '../../helpers/app'; +import { createRandomChannel, createRandomUser, ICreateUser } from '../../helpers/data_setup'; const reopenAndCheckServer = async (server: string) => { await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true }); @@ -10,13 +11,15 @@ const reopenAndCheckServer = async (server: string) => { }; describe('Change server', () => { + let user: ICreateUser; + let channel: string; + beforeAll(async () => { + user = await createRandomUser(); + channel = await createRandomChannel(user); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await navigateToLogin(); - await login(data.users.regular.username, data.users.regular.password); - await waitFor(element(by.id('rooms-list-view'))) - .toBeVisible() - .withTimeout(10000); + await login(user.username, user.password); }); it('should open the dropdown button, have the server add button and create workspace button', async () => { @@ -37,7 +40,7 @@ describe('Change server', () => { await waitFor(element(by.id('new-server-view'))) .toBeVisible() .withTimeout(6000); - await element(by.id('new-server-view-input')).replaceText(`${data.alternateServer}`); + await element(by.id('new-server-view-input')).replaceText(data.alternateServer); await element(by.id('new-server-view-input')).tapReturnKey(); await waitFor(element(by.id('workspace-view'))) .toBeVisible() @@ -60,15 +63,15 @@ describe('Change server', () => { .withTimeout(2000); // Register new user - await sleep(5000); - await element(by.id('register-view-name')).replaceText(data.registeringUser2.username); - await element(by.id('register-view-username')).replaceText(data.registeringUser2.username); - await element(by.id('register-view-email')).replaceText(data.registeringUser2.email); - await element(by.id('register-view-password')).replaceText(data.registeringUser2.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 waitFor(element(by.id(`rooms-list-view-item-${data.groups.private.name}`))) + await waitFor(element(by.id(`rooms-list-view-item-${channel}`))) .toBeNotVisible() .withTimeout(60000); await checkServer(data.alternateServer); @@ -87,7 +90,7 @@ describe('Change server', () => { await waitFor(element(by.id('rooms-list-view'))) .toBeVisible() .withTimeout(10000); - await waitFor(element(by.id(`rooms-list-view-item-${data.groups.private.name}`))) + await waitFor(element(by.id(`rooms-list-view-item-${channel}`))) .toBeVisible() .withTimeout(60000); await checkServer(data.server);