verdnatura-chat/e2e/tests/room/09-jumptomessage.spec.js

176 lines
7.8 KiB
JavaScript
Raw Normal View History

const data = require('../../data');
const {
2021-08-17 18:05:45 +00:00
navigateToLogin, tapBack, login, searchRoom, sleep, platformTypes
} = require('../../helpers/app');
async function navigateToRoom(roomName) {
await searchRoom(`${ roomName }`);
await element(by.id(`rooms-list-view-item-${ roomName }`)).tap();
await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000);
}
async function clearCache() {
2021-07-24 21:09:53 +00:00
const { alertButtonType } = platformTypes[device.getPlatform()];
await waitFor(element(by.id('room-view'))).toBeVisible().withTimeout(5000);
await tapBack();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);
await element(by.id('rooms-list-view-sidebar')).tap();
await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000);
await element(by.id('sidebar-settings')).tap();
await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000);
await element(by.id('settings-view-clear-cache')).tap();
await waitFor(element(by.text('This will clear all your offline data.'))).toExist().withTimeout(2000);
2021-07-24 21:09:53 +00:00
await element(by.text('Clear').and(by.type(alertButtonType))).tap();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(5000);
await waitFor(element(by.id('rooms-list-view-item-jumping'))).toExist().withTimeout(10000);
}
async function waitForLoading() {
2021-07-24 21:09:53 +00:00
if (device.getPlatform() === 'android') {
await sleep(10000);
2021-08-10 19:33:58 +00:00
return; // Loading indicator doesn't animate properly on android
2021-07-24 21:09:53 +00:00
}
await waitFor(element(by.id('loading'))).toBeVisible().withTimeout(5000); // Fails on Android
await waitFor(element(by.id('loading'))).toBeNotVisible().withTimeout(10000);
}
describe('Room', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await navigateToLogin();
await login(data.adminUser, data.adminPassword);
});
it('should jump to an old message and load its surroundings', async() => {
2021-07-26 21:54:31 +00:00
if (device.getPlatform() === 'android') {
return; // 'Room' tests don't work well on Android currently
}
await navigateToRoom('jumping');
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('Quote first message'))).toExist().withTimeout(5000);
await element(by.text('1')).atIndex(0).tap();
await waitForLoading();
await waitFor(element(by.text('1')).atIndex(0)).toExist().withTimeout(10000);
2021-07-21 09:33:16 +00:00
await expect(element(by.text('2'))).toExist();
});
it('should tap FAB and scroll to bottom', async() => {
2021-07-26 21:54:31 +00:00
if (device.getPlatform() === 'android') {
2021-08-10 19:33:58 +00:00
return; // 'Room' tests don't work well on Android currently
2021-07-26 21:54:31 +00:00
}
await waitFor(element(by.id('nav-jump-to-bottom'))).toExist().withTimeout(5000);
await element(by.id('nav-jump-to-bottom')).tap();
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('Quote first message'))).toExist().withTimeout(5000);
await clearCache();
});
it('should load messages on scroll', async() => {
2021-07-26 21:54:31 +00:00
if (device.getPlatform() === 'android') {
2021-08-10 19:33:58 +00:00
return; // 'Room' tests don't work well on Android currently
2021-07-26 21:54:31 +00:00
}
await navigateToRoom('jumping');
await waitFor(element(by.id('room-view-messages'))).toExist().withTimeout(5000);
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('300'))).toExist().withTimeout(5000);
let found = false;
while (!found) {
2021-07-26 21:54:31 +00:00
await element(by.id('room-view-messages')).atIndex(0).scroll(500, 'down');
try {
2021-07-21 09:33:16 +00:00
await expect(element(by.text('249'))).toExist();
found = true;
} catch {
//
}
}
await clearCache();
});
it('should search for old message and load its surroundings', async() => {
2021-07-26 21:54:31 +00:00
if (device.getPlatform() === 'android') {
2021-08-10 19:33:58 +00:00
return; // 'Room' tests don't work well on Android currently
2021-07-26 21:54:31 +00:00
}
await navigateToRoom('jumping');
await element(by.id('room-view-search')).tap();
await waitFor(element(by.id('search-messages-view'))).toExist().withTimeout(5000);
2021-08-03 07:58:30 +00:00
await element(by.id('search-message-view-input')).replaceText('30');
2021-07-26 21:54:31 +00:00
await waitFor(element(by.text('30')).atIndex(1)).toExist().withTimeout(5000);
await element(by.text('30')).atIndex(1).tap();
await waitForLoading();
2021-07-21 09:33:16 +00:00
await expect(element(by.text('30'))).toExist();
await expect(element(by.text('31'))).toExist();
await expect(element(by.text('32'))).toExist();
2021-07-26 21:54:31 +00:00
await waitFor(element(by.text('32'))).toBeVisible().withTimeout(5000);
});
it('should load newer and older messages', async() => {
2021-07-26 21:54:31 +00:00
if (device.getPlatform() === 'android') {
2021-08-10 19:33:58 +00:00
return; // 'Room' tests don't work well on Android currently
2021-07-26 21:54:31 +00:00
}
await element(by.id('room-view-messages')).atIndex(0).swipe('down', 'fast', 0.8);
await waitFor(element(by.text('5'))).toExist().withTimeout(10000);
await waitFor(element(by.label('Load Older'))).toExist().withTimeout(5000);
await element(by.label('Load Older')).atIndex(0).tap();
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('4'))).toExist().withTimeout(5000);
await element(by.id('room-view-messages')).atIndex(0).swipe('down', 'fast', 0.5);
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('1'))).toExist().withTimeout(5000);
await element(by.id('room-view-messages')).atIndex(0).swipe('up', 'fast', 0.5);
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('25'))).toExist().withTimeout(5000);
await element(by.id('room-view-messages')).atIndex(0).swipe('up', 'fast', 0.5);
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('50'))).toExist().withTimeout(5000);
await element(by.id('room-view-messages')).atIndex(0).swipe('up', 'slow', 0.5);
await waitFor(element(by.label('Load Newer'))).toExist().withTimeout(5000);
await element(by.label('Load Newer')).atIndex(0).tap();
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('104'))).toExist().withTimeout(5000);
await waitFor(element(by.label('Load Newer'))).toExist().withTimeout(5000);
await element(by.label('Load Newer')).atIndex(0).tap();
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('154'))).toExist().withTimeout(5000);
await waitFor(element(by.label('Load Newer'))).toExist().withTimeout(5000);
await element(by.label('Load Newer')).atIndex(0).tap();
await waitFor(element(by.label('Load Newer'))).toNotExist().withTimeout(5000);
await expect(element(by.label('Load More'))).toNotExist();
2021-07-21 09:33:16 +00:00
await expect(element(by.text('201'))).toExist();
await expect(element(by.text('202'))).toExist();
await tapBack();
});
});
const expectThreadMessages = async(message) => {
await waitFor(element(by.id('room-view-title-jumping-thread'))).toExist().withTimeout(5000);
2021-07-26 21:54:31 +00:00
await expect(element(by.text(message)).atIndex(0)).toExist();
};
describe('Threads', () => {
it('should navigate to a thread from another room', async() => {
await navigateToRoom('jumping');
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('Go to jumping-thread\'s thread')).atIndex(0)).toExist().withTimeout(5000);
await element(by.text('Go to jumping-thread\'s thread')).atIndex(0).tap();
await waitForLoading();
await expectThreadMessages('Go to jumping-thread\'s thread');
await tapBack();
});
it('should tap on thread message from main room', async() => {
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('thread message sent to main room')).atIndex(0)).toExist().withTimeout(5000);
await element(by.text('thread message sent to main room')).atIndex(0).tap();
await expectThreadMessages('thread message sent to main room');
await tapBack();
});
it('should tap on quote', async() => {
2021-07-21 09:33:16 +00:00
await waitFor(element(by.text('quoted'))).toExist().withTimeout(5000);
await element(by.text('quoted')).atIndex(0).tap();
await expectThreadMessages('quoted');
await tapBack();
});
it('should jump from search message', async() => {
await waitFor(element(by.id('room-view-title-jumping-thread'))).toExist().withTimeout(5000);
await element(by.id('room-view-search')).atIndex(0).tap();
await waitFor(element(by.id('search-messages-view'))).toExist().withTimeout(5000);
2021-08-03 07:58:30 +00:00
await element(by.id('search-message-view-input')).replaceText('to be searched');
2021-07-26 21:54:31 +00:00
await waitFor(element(by.text('to be searched')).atIndex(1)).toExist().withTimeout(5000);
2021-07-21 09:33:16 +00:00
await element(by.text('to be searched')).atIndex(1).tap();
await expectThreadMessages('to be searched');
});
// TODO: Threads pagination
});