til changeserver

This commit is contained in:
Diego Mello 2023-02-22 10:36:51 -03:00
parent e9721c8743
commit cc121e66f5
9 changed files with 75 additions and 55 deletions

View File

@ -105,11 +105,12 @@ const data = {
email: `mobile+registeringfour${value}@rocket.chat` email: `mobile+registeringfour${value}@rocket.chat`
}, },
random: value, random: value,
randomUser: (): { username: string; password: string; email: string } => { randomUser: (): { username: string; name: string; password: string; email: string } => {
const randomVal = random(); const randomVal = random();
return { return {
username: `user${randomVal}`, username: `user${randomVal}`,
password: '123', name: `name${randomVal}`,
password: `password${randomVal}`,
email: `mobile+${randomVal}@rocket.chat` email: `mobile+${randomVal}@rocket.chat`
}; };
} }

View File

@ -95,6 +95,9 @@ async function logout() {
await expect(element(by.id('new-server-view'))).toBeVisible(); await expect(element(by.id('new-server-view'))).toBeVisible();
} }
/**
* @deprecated use mockRandomMessage
*/
async function mockMessage(message: string, isThread = false) { async function mockMessage(message: string, isThread = false) {
const deviceType = device.getPlatform(); const deviceType = device.getPlatform();
const { textMatcher } = platformTypes[deviceType]; const { textMatcher } = platformTypes[deviceType];

View File

@ -37,22 +37,17 @@ export interface ICreateUser {
} }
export const createRandomUser = async (): Promise<ICreateUser> => { export const createRandomUser = async (): Promise<ICreateUser> => {
await login(data.adminUser, data.adminPassword);
const val = random(5);
console.log(`Creating user user${val}`);
try { try {
const username = `user${val}`; await login(data.adminUser, data.adminPassword);
const password = `pass${val}`; const user = data.randomUser();
const name = `name${val}`; console.log(`Creating user ${user.username}`);
const email = `mobile+${val}@rocket.chat`;
await rocketchat.post('users.create', { await rocketchat.post('users.create', {
username, username: user.username,
password, password: user.password,
name, name: user.name,
email email: user.email
}); });
return { username, password, name, email } as const; return user;
} catch (error) { } catch (error) {
console.log(JSON.stringify(error)); console.log(JSON.stringify(error));
throw new Error('Failed to create user'); 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) => { const createTeamIfNotExists = async (teamname: string) => {
console.log(`Creating private team ${teamname}`); console.log(`Creating private team ${teamname}`);
try { try {

View File

@ -13,7 +13,6 @@ import {
checkRoomTitle, checkRoomTitle,
mockRandomMessage mockRandomMessage
} from '../../helpers/app'; } from '../../helpers/app';
import data from '../../data';
import { createRandomUser, ICreateUser } from '../../helpers/data_setup'; import { createRandomUser, ICreateUser } from '../../helpers/data_setup';
import random from '../../helpers/random'; import random from '../../helpers/random';

View File

@ -1,29 +1,26 @@
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 data from '../../data'; import { createRandomUser, ICreateUser } from '../../helpers/data_setup';
import random from '../../helpers/random';
const profileChangeUser = data.users.profileChanges;
const scrollDown = 200; const scrollDown = 200;
async function waitForToast() { 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); await sleep(600);
} }
describe('Profile screen', () => { describe('Profile screen', () => {
let scrollViewType: string; let scrollViewType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ scrollViewType, textMatcher } = platformTypes[device.getPlatform()]); ({ scrollViewType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin(); await navigateToLogin();
await login(profileChangeUser.username, profileChangeUser.password); await login(user.username, user.password);
await element(by.id('rooms-list-view-sidebar')).tap(); await element(by.id('rooms-list-view-sidebar')).tap();
await waitFor(element(by.id('sidebar-view'))) await waitFor(element(by.id('sidebar-view')))
.toBeVisible() .toBeVisible()
@ -97,8 +94,8 @@ describe('Profile screen', () => {
describe('Usage', () => { describe('Usage', () => {
it('should change name and username', async () => { it('should change name and username', async () => {
await element(by.id('profile-view-name')).replaceText(`${profileChangeUser.username}new`); await element(by.id('profile-view-name')).replaceText(`${user.username}new`);
await element(by.id('profile-view-username')).replaceText(`${profileChangeUser.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-list')).swipe('down');
await element(by.id('profile-view-submit')).tap(); await element(by.id('profile-view-submit')).tap();
await waitForToast(); await waitForToast();
@ -108,8 +105,8 @@ describe('Profile screen', () => {
await waitFor(element(by.id('profile-view-email'))) await waitFor(element(by.id('profile-view-email')))
.toBeVisible() .toBeVisible()
.withTimeout(2000); .withTimeout(2000);
await element(by.id('profile-view-email')).replaceText(`mobile+profileChangesNew${data.random}@rocket.chat`); await element(by.id('profile-view-email')).replaceText(`mobile+profileChangesNew${random()}@rocket.chat`);
await element(by.id('profile-view-new-password')).replaceText(`${profileChangeUser.password}new`); await element(by.id('profile-view-new-password')).replaceText(`${user.password}new`);
await waitFor(element(by.id('profile-view-submit'))) await waitFor(element(by.id('profile-view-submit')))
.toExist() .toExist()
.withTimeout(2000); .withTimeout(2000);
@ -117,7 +114,7 @@ describe('Profile screen', () => {
await waitFor(element(by.id('profile-view-enter-password-sheet'))) await waitFor(element(by.id('profile-view-enter-password-sheet')))
.toBeVisible() .toBeVisible()
.withTimeout(2000); .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'))) await element(by[textMatcher]('Save').withAncestor(by.id('action-sheet-content-with-input-and-submit')))
.atIndex(0) .atIndex(0)
.tap(); .tap();

View File

@ -1,18 +1,21 @@
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 data from '../../data'; import { createRandomChannel, createRandomUser, ICreateUser } from '../../helpers/data_setup';
const testuser = data.users.regular;
describe('Settings screen', () => { describe('Settings screen', () => {
let alertButtonType: string; let alertButtonType: string;
let textMatcher: TTextMatcher; let textMatcher: TTextMatcher;
let user: ICreateUser;
let channel: string;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
channel = await createRandomChannel(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();
await login(testuser.username, testuser.password); await login(user.username, user.password);
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toBeVisible() .toBeVisible()
.withTimeout(10000); .withTimeout(10000);
@ -84,7 +87,7 @@ describe('Settings screen', () => {
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toBeVisible() .toBeVisible()
.withTimeout(5000); .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() .toExist()
.withTimeout(10000); .withTimeout(10000);
}); });

View File

@ -1,9 +1,9 @@
import { expect } from 'detox'; import { expect } from 'detox';
import data from '../../data'; 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; const room = data.channels.detoxpublic.name;
async function navigateToRoom() { async function navigateToRoom() {
@ -24,11 +24,14 @@ 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;
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();
await login(testuser.username, testuser.password); await login(user.username, user.password);
await navigateToRoom(); await navigateToRoom();
}); });
@ -141,7 +144,7 @@ describe('Join public room', () => {
}); });
it('should send message', async () => { it('should send message', async () => {
await mockMessage('message'); await mockRandomMessage('message');
}); });
it('should have notifications and leave channel', async () => { it('should have notifications and leave channel', async () => {

View File

@ -1,15 +1,16 @@
import { expect } from 'detox'; import { expect } from 'detox';
import { navigateToLogin, login, sleep } from '../../helpers/app'; import { navigateToLogin, login, sleep } from '../../helpers/app';
import data from '../../data'; import { createRandomUser, ICreateUser } from '../../helpers/data_setup';
const testuser = data.users.regular;
describe('Status screen', () => { describe('Status screen', () => {
let user: ICreateUser;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin(); await navigateToLogin();
await login(testuser.username, testuser.password); await login(user.username, user.password);
await element(by.id('rooms-list-view-sidebar')).tap(); await element(by.id('rooms-list-view-sidebar')).tap();
await waitFor(element(by.id('sidebar-view'))) await waitFor(element(by.id('sidebar-view')))

View File

@ -1,5 +1,6 @@
import data from '../../data'; 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) => { const reopenAndCheckServer = async (server: string) => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true }); await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true });
@ -10,13 +11,15 @@ const reopenAndCheckServer = async (server: string) => {
}; };
describe('Change server', () => { describe('Change server', () => {
let user: ICreateUser;
let channel: string;
beforeAll(async () => { beforeAll(async () => {
user = await createRandomUser();
channel = await createRandomChannel(user);
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(user.username, user.password);
await waitFor(element(by.id('rooms-list-view')))
.toBeVisible()
.withTimeout(10000);
}); });
it('should open the dropdown button, have the server add button and create workspace button', async () => { 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'))) await waitFor(element(by.id('new-server-view')))
.toBeVisible() .toBeVisible()
.withTimeout(6000); .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 element(by.id('new-server-view-input')).tapReturnKey();
await waitFor(element(by.id('workspace-view'))) await waitFor(element(by.id('workspace-view')))
.toBeVisible() .toBeVisible()
@ -60,15 +63,15 @@ describe('Change server', () => {
.withTimeout(2000); .withTimeout(2000);
// Register new user // Register new user
await sleep(5000); const randomUser = data.randomUser();
await element(by.id('register-view-name')).replaceText(data.registeringUser2.username); await element(by.id('register-view-name')).replaceText(randomUser.name);
await element(by.id('register-view-username')).replaceText(data.registeringUser2.username); await element(by.id('register-view-username')).replaceText(randomUser.username);
await element(by.id('register-view-email')).replaceText(data.registeringUser2.email); await element(by.id('register-view-email')).replaceText(randomUser.email);
await element(by.id('register-view-password')).replaceText(data.registeringUser2.password); 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 waitFor(element(by.id(`rooms-list-view-item-${data.groups.private.name}`))) await waitFor(element(by.id(`rooms-list-view-item-${channel}`)))
.toBeNotVisible() .toBeNotVisible()
.withTimeout(60000); .withTimeout(60000);
await checkServer(data.alternateServer); await checkServer(data.alternateServer);
@ -87,7 +90,7 @@ describe('Change server', () => {
await waitFor(element(by.id('rooms-list-view'))) await waitFor(element(by.id('rooms-list-view')))
.toBeVisible() .toBeVisible()
.withTimeout(10000); .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() .toBeVisible()
.withTimeout(60000); .withTimeout(60000);
await checkServer(data.server); await checkServer(data.server);