Rocket.Chat.ReactNative/e2e/tests/room/08-roominfo.spec.ts

258 lines
9.5 KiB
TypeScript
Raw Normal View History

2023-01-25 19:03:02 +00:00
import { expect } from 'detox';
2023-02-22 20:54:30 +00:00
import { navigateToLogin, login, tapBack, sleep, platformTypes, TTextMatcher, navigateToRoom } from '../../helpers/app';
import { createRandomRoom, createRandomUser, ITestUser } from '../../helpers/data_setup';
async function navigateToRoomInfo(room: string) {
await navigateToRoom(room);
2023-01-25 19:03:02 +00:00
await element(by.id('room-header')).tap();
await waitFor(element(by.id('room-actions-view')))
.toExist()
.withTimeout(5000);
await element(by.id('room-actions-info')).tap();
await waitFor(element(by.id('room-info-view')))
.toExist()
.withTimeout(2000);
}
async function swipe(direction: Detox.Direction) {
2023-02-17 20:42:42 +00:00
await element(by.id('room-info-edit-view-list')).swipe(direction, 'fast', 0.8, 0.2);
2023-01-25 19:03:02 +00:00
}
async function waitForToast() {
await sleep(300);
}
describe('Room info screen', () => {
let alertButtonType: string;
let textMatcher: TTextMatcher;
2023-02-22 20:54:30 +00:00
let room: string;
let user: ITestUser;
2023-01-25 19:03:02 +00:00
beforeAll(async () => {
2023-02-22 20:54:30 +00:00
user = await createRandomUser();
({ name: room } = await createRandomRoom(user, 'p'));
2023-01-25 19:03:02 +00:00
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
({ alertButtonType, textMatcher } = platformTypes[device.getPlatform()]);
await navigateToLogin();
2023-02-22 20:54:30 +00:00
await login(user.username, user.password);
2023-01-25 19:03:02 +00:00
});
describe('Channel/Group', () => {
beforeAll(async () => {
2023-02-22 20:54:30 +00:00
await navigateToRoomInfo(room);
2023-01-25 19:03:02 +00:00
});
describe('Render', () => {
it('should have room info view', async () => {
await expect(element(by.id('room-info-view'))).toExist();
});
it('should have name', async () => {
await expect(element(by.id('room-info-view-name'))).toExist();
});
it('should have description', async () => {
await expect(element(by[textMatcher]('Description'))).toExist();
});
it('should have topic', async () => {
await expect(element(by[textMatcher]('Topic'))).toExist();
});
it('should have announcement', async () => {
await expect(element(by[textMatcher]('Announcement'))).toExist();
});
it('should have edit button', async () => {
await expect(element(by.id('room-info-view-edit-button'))).toExist();
});
});
describe('Render Edit', () => {
beforeAll(async () => {
await waitFor(element(by.id('room-info-view-edit-button')))
.toExist()
.withTimeout(10000);
await element(by.id('room-info-view-edit-button')).tap();
await waitFor(element(by.id('room-info-edit-view')))
.toExist()
.withTimeout(2000);
});
it('should have room info edit view', async () => {
await expect(element(by.id('room-info-edit-view'))).toExist();
});
it('should have name input', async () => {
await expect(element(by.id('room-info-edit-view-name'))).toExist();
});
it('should have description input', async () => {
await expect(element(by.id('room-info-edit-view-description'))).toExist();
});
it('should have topic input', async () => {
await expect(element(by.id('room-info-edit-view-topic'))).toExist();
});
it('should have announcement input', async () => {
await expect(element(by.id('room-info-edit-view-announcement'))).toExist();
});
it('should have password input', async () => {
await expect(element(by.id('room-info-edit-view-password'))).toExist();
});
it('should have type switch', async () => {
await swipe('up');
await expect(element(by.id('room-info-edit-view-t'))).toExist();
});
it('should have ready only switch', async () => {
await expect(element(by.id('room-info-edit-view-ro'))).toExist();
});
it('should have submit button', async () => {
await expect(element(by.id('room-info-edit-view-submit'))).toExist();
});
it('should have reset button', async () => {
await expect(element(by.id('room-info-edit-view-reset'))).toExist();
});
it('should have archive button', async () => {
await expect(element(by.id('room-info-edit-view-archive'))).toExist();
});
it('should have delete button', async () => {
await expect(element(by.id('room-info-edit-view-delete'))).toExist();
});
afterAll(async () => {
await swipe('down');
});
});
describe('Usage', () => {
it('should reset form', async () => {
await element(by.id('room-info-edit-view-name')).replaceText('abc');
await element(by.id('room-info-edit-view-description')).replaceText('abc');
await element(by.id('room-info-edit-view-topic')).replaceText('abc');
2023-02-20 20:34:51 +00:00
await element(by.id('room-info-edit-view-topic')).tapReturnKey();
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-announcement')).replaceText('abc');
2023-02-20 20:34:51 +00:00
await element(by.id('room-info-edit-view-announcement')).tapReturnKey();
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-password')).replaceText('abc');
2023-02-20 20:34:51 +00:00
await element(by.id('room-info-edit-view-password')).tapReturnKey();
await swipe('down'); // dismiss keyboard
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-t')).tap();
await swipe('up');
2023-02-17 20:42:42 +00:00
await element(by.id('room-info-edit-view-ro')).tap();
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-react-when-ro')).tap();
await element(by.id('room-info-edit-view-reset')).tap();
// after reset
2023-02-22 20:54:30 +00:00
await expect(element(by.id('room-info-edit-view-name'))).toHaveText(room);
2023-01-25 19:03:02 +00:00
await expect(element(by.id('room-info-edit-view-description'))).toHaveText('');
await expect(element(by.id('room-info-edit-view-topic'))).toHaveText('');
await expect(element(by.id('room-info-edit-view-announcement'))).toHaveText('');
await expect(element(by.id('room-info-edit-view-password'))).toHaveText('');
await expect(element(by.id('room-info-edit-view-t'))).toHaveToggleValue(true);
await expect(element(by.id('room-info-edit-view-ro'))).toHaveToggleValue(false);
2023-02-17 20:42:42 +00:00
await expect(element(by.id('room-info-edit-view-react-when-ro'))).not.toBeVisible();
2023-01-25 19:03:02 +00:00
await swipe('down');
});
2023-02-17 20:42:42 +00:00
it('should change room name', async () => {
2023-02-22 20:54:30 +00:00
await element(by.id('room-info-edit-view-name')).replaceText(`${room}new`);
2023-02-20 20:34:51 +00:00
await swipe('down'); // dismiss keyboard
2023-02-17 20:42:42 +00:00
await swipe('up');
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-submit')).tap();
await waitForToast();
await tapBack();
await waitFor(element(by.id('room-info-view')))
.toExist()
.withTimeout(2000);
2023-02-17 20:42:42 +00:00
const matcher = device.getPlatform() === 'android' ? 'toHaveText' : 'toHaveLabel';
await waitFor(element(by.id('room-info-view-name')))
2023-02-22 20:54:30 +00:00
[matcher](`${room}new`)
2023-01-25 19:03:02 +00:00
.withTimeout(10000);
await element(by.id('room-info-view-edit-button')).tap();
await waitFor(element(by.id('room-info-edit-view')))
.toExist()
.withTimeout(2000);
});
2023-02-17 20:42:42 +00:00
it('should change room description, topic, announcement', async () => {
2023-02-22 20:54:30 +00:00
await sleep(5000); // wait for changes to be applied from socket
2023-02-17 20:42:42 +00:00
await element(by.id('room-info-edit-view-description')).replaceText('new description');
await element(by.id('room-info-edit-view-topic')).replaceText('new topic');
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-announcement')).replaceText('new announcement');
2023-02-20 20:34:51 +00:00
await element(by.id('room-info-edit-view-announcement')).tapReturnKey();
await element(by.id('room-info-edit-view-password')).tapReturnKey();
await swipe('down'); // dismiss keyboard
2023-02-17 20:42:42 +00:00
await swipe('up');
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-submit')).tap();
await waitForToast();
await tapBack();
await waitFor(element(by.id('room-info-view')))
.toExist()
.withTimeout(2000);
2023-02-17 20:42:42 +00:00
await waitFor(element(by[textMatcher]('new description').withAncestor(by.id('room-info-view-description'))))
2023-01-25 19:03:02 +00:00
.toExist()
.withTimeout(10000);
2023-02-17 20:42:42 +00:00
await expect(element(by[textMatcher]('new topic').withAncestor(by.id('room-info-view-topic')))).toExist();
await expect(element(by[textMatcher]('new announcement').withAncestor(by.id('room-info-view-announcement')))).toExist();
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-view-edit-button')).tap();
await waitFor(element(by.id('room-info-edit-view')))
.toExist()
.withTimeout(2000);
});
2023-02-17 20:42:42 +00:00
// Commented because we're not actually asserting anything
// it('should change room password', async () => {
// await waitFor(element(by.id('room-info-view-edit-button')))
// .toExist()
// .withTimeout(10000);
// await element(by.id('room-info-view-edit-button')).tap();
// await waitFor(element(by.id('room-info-edit-view')))
// .toExist()
// .withTimeout(2000);
// await sleep(2000);
// await element(by.id('room-info-edit-view-password')).replaceText('password');
// await element(by.id('room-info-edit-view-list')).swipe('up', 'fast', 0.5);
// await element(by.id('room-info-edit-view-submit')).tap();
// await waitForToast();
// });
2023-01-25 19:03:02 +00:00
it('should change room type', async () => {
await swipe('down');
await element(by.id('room-info-edit-view-t')).tap();
2023-02-17 20:42:42 +00:00
await swipe('up');
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-submit')).tap();
await waitForToast();
});
it('should archive room', async () => {
2023-02-17 20:42:42 +00:00
await swipe('up');
2023-01-25 19:03:02 +00:00
await element(by.id('room-info-edit-view-archive')).tap();
await waitFor(element(by[textMatcher]('Yes, archive it!')))
.toExist()
.withTimeout(5000);
await element(by[textMatcher]('Yes, archive it!').and(by.type(alertButtonType))).tap();
await waitForToast();
});
it('should delete room', async () => {
await element(by.id('room-info-edit-view-delete')).tap();
await waitFor(element(by[textMatcher]('Yes, delete it!')))
.toExist()
.withTimeout(5000);
await element(by[textMatcher]('Yes, delete it!').and(by.type(alertButtonType))).tap();
2023-02-22 20:54:30 +00:00
await waitFor(element(by.id(`rooms-list-view-item-${room}new`)))
2023-02-17 20:42:42 +00:00
.not.toBeVisible()
2023-01-25 19:03:02 +00:00
.withTimeout(60000);
});
});
});
});