This commit is contained in:
Anant Bhasin 2021-07-16 02:29:16 +05:30
parent 4cc3d8a26b
commit 047d4e5889
18 changed files with 155 additions and 136 deletions

View File

@ -38,7 +38,7 @@ async function login(username, password) {
async function logout() {
const deviceType = device.getPlatform();
const { scrollViewType } = platformTypes[deviceType];
const { scrollViewType } = platformTypes[deviceType];
await element(by.id('rooms-list-view-sidebar')).tap();
await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000);
await waitFor(element(by.id('sidebar-settings'))).toBeVisible().withTimeout(2000);
@ -60,48 +60,48 @@ async function mockMessage(message, isThread = false) {
await element(by.id(input)).typeText(`${ data.random }${ message }`);
await element(by.id('messagebox-send-message')).tap();
await waitFor(element(by.text(`${ data.random }${ message }`))).toExist().withTimeout(60000);
await expect(element(by.text(`${ data.random }${ message }`))).toExist();
await element(by.text(`${ data.random }${ message }`)).atIndex(0).tap();
};
async function starMessage(message){
const messageLabel = `${ data.random }${ message }`
await element(by.text(messageLabel)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5);
await element(by.text('Star')).atIndex(0).tap();
await waitFor(element(by.id('action-sheet'))).not.toExist().withTimeout(5000);
};
async function pinMessage(message){
const messageLabel = `${ data.random }${ message }`
await waitFor(element(by.text(messageLabel)).atIndex(0)).toExist();
await element(by.text(messageLabel)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5);
await element(by.text('Pin')).atIndex(0).tap();
await waitFor(element(by.id('action-sheet'))).not.toExist().withTimeout(5000);
await expect(element(by.text(`${ data.random }${ message }`))).toExist();
await element(by.text(`${ data.random }${ message }`)).atIndex(0).tap();
}
async function dismissReviewNag(){
const deviceType = device.getPlatform();
const { alertButtonType } = platformTypes[deviceType];
await waitFor(element(by.text('Are you enjoying this app?'))).toExist().withTimeout(60000);
await element(by.text('NO').and(by.type(alertButtonType))).tap(); // Tap `no` on ask for review alert
async function starMessage(message) {
const messageLabel = `${ data.random }${ message }`;
await element(by.text(messageLabel)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5);
await element(by.text('Star')).atIndex(0).tap();
await waitFor(element(by.id('action-sheet'))).not.toExist().withTimeout(5000);
}
async function pinMessage(message) {
const messageLabel = `${ data.random }${ message }`;
await waitFor(element(by.text(messageLabel)).atIndex(0)).toExist();
await element(by.text(messageLabel)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();
await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5);
await element(by.text('Pin')).atIndex(0).tap();
await waitFor(element(by.id('action-sheet'))).not.toExist().withTimeout(5000);
}
async function dismissReviewNag() {
const deviceType = device.getPlatform();
const { alertButtonType } = platformTypes[deviceType];
await waitFor(element(by.text('Are you enjoying this app?'))).toExist().withTimeout(60000);
await element(by.text('NO').and(by.type(alertButtonType))).tap(); // Tap `no` on ask for review alert
}
async function mockMessageWithNag(message, isThread = false) {
let input = isThread ? 'messagebox-input-thread' : 'messagebox-input';
const input = isThread ? 'messagebox-input-thread' : 'messagebox-input';
await element(by.id(input)).tap();
await element(by.id(input)).typeText(`${ data.random }${ message }`);
await element(by.id('messagebox-send-message')).tap();
await dismissReviewNag();
await dismissReviewNag();
await waitFor(element(by.text(`${ data.random }${ message }`))).toExist().withTimeout(60000);
await expect(element(by.text(`${ data.random }${ message }`))).toExist();
await element(by.text(`${ data.random }${ message }`)).atIndex(0).tap();
};
await expect(element(by.text(`${ data.random }${ message }`))).toExist();
await element(by.text(`${ data.random }${ message }`)).atIndex(0).tap();
}
async function tapBack() {
await element(by.id('header-back')).atIndex(0).tap();
@ -145,25 +145,26 @@ const checkServer = async(server) => {
};
async function closeKeyboard() {
if(device.getPlatform() === 'android')
await device.goBack();
if (device.getPlatform() === 'android') {
await device.goBack();
}
}
module.exports = {
navigateToWorkspace,
navigateToLogin,
navigateToRegister,
login,
logout,
mockMessage,
starMessage,
pinMessage,
dismissReviewNag,
tapBack,
sleep,
searchRoom,
tryTapping,
checkServer,
closeKeyboard,
mockMessageWithNag
navigateToWorkspace,
navigateToLogin,
navigateToRegister,
login,
logout,
mockMessage,
starMessage,
pinMessage,
dismissReviewNag,
tapBack,
sleep,
searchRoom,
tryTapping,
checkServer,
closeKeyboard,
mockMessageWithNag
};

View File

@ -5,51 +5,48 @@ const { sleep } = require('./app');
const defaultLaunchArgs = { permissions: { notifications: 'YES' } };
function runCommand(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if(error)
{
reject(new Error(`exec error: ${stderr}`));
return;
}
resolve();
})
});
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(new Error(`exec error: ${ stderr }`));
return;
}
resolve();
});
});
}
// The Spell Checker and the autofill service introduce additional flakiness, and appear over other elements.
// So, we disable them before running the tests.
exports.prepareAndroid = async () => {
if(device.getPlatform() !== 'android') return;
await runCommand('adb shell settings put secure spell_checker_enabled 0');
await runCommand('adb shell settings put secure autofill_service null');
}
exports.prepareAndroid = async() => {
if (device.getPlatform() !== 'android') {
return;
}
await runCommand('adb shell settings put secure spell_checker_enabled 0');
await runCommand('adb shell settings put secure autofill_service null');
};
exports.launchWithLanguage = async (language, countryCode="US", launchArgs=defaultLaunchArgs) => {
if(device.id === undefined)
{
await device.launchApp(launchArgs);
}
if(device.getPlatform() === 'android')
{
await runCommand('adb root');
await runCommand(`adb shell "setprop persist.sys.locale ${language}-${countryCode}; setprop ctl.restart zygote"`);
await sleep(20000);
await device.launchApp(launchArgs);
}
else
{
const langLocale = typeof countryCode === 'string' ? `${language}-${countryCode}` : language;
await device.launchApp({
...launchArgs,
languageAndLocale: {
language: langLocale,
locale: langLocale
}
});
}
}
exports.launchWithLanguage = async(language, countryCode = 'US', launchArgs = defaultLaunchArgs) => {
if (device.id === undefined) {
await device.launchApp(launchArgs);
}
if (device.getPlatform() === 'android') {
await runCommand('adb root');
await runCommand(`adb shell "setprop persist.sys.locale ${ language }-${ countryCode }; setprop ctl.restart zygote"`);
await sleep(20000);
await device.launchApp(launchArgs);
} else {
const langLocale = typeof countryCode === 'string' ? `${ language }-${ countryCode }` : language;
await device.launchApp({
...launchArgs,
languageAndLocale: {
language: langLocale,
locale: langLocale
}
});
}
};
exports.closeKeyboardAndroid = async () => {
await device.pressBack(); // Android-only
}
exports.closeKeyboardAndroid = async() => {
await device.pressBack(); // Android-only
};

View File

@ -1,13 +1,13 @@
exports.android = {
//Android types
alertButtonType: 'android.widget.Button',
scrollViewType: 'android.widget.ScrollView',
textInputType: 'android.widget.EditText',
// Android types
alertButtonType: 'android.widget.Button',
scrollViewType: 'android.widget.ScrollView',
textInputType: 'android.widget.EditText'
};
exports.ios = {
//iOS types
alertButtonType: '_UIAlertControllerActionView',
scrollViewType: 'UIScrollView',
textInputType: '_UIAlertControllerTextField'
};
// iOS types
alertButtonType: '_UIAlertControllerActionView',
scrollViewType: 'UIScrollView',
textInputType: '_UIAlertControllerTextField'
};

View File

@ -20,7 +20,7 @@ const checkServer = async(server) => {
const checkBanner = async() => {
await waitFor(element(by.id('listheader-encryption').withDescendant(by.text('Save Your Encryption Password')))).toBeVisible().withTimeout(10000);
}
};
async function navigateToRoom(roomName) {
await searchRoom(`${ roomName }`);
@ -46,7 +46,8 @@ async function navigateSecurityPrivacy() {
describe('E2E Encryption', () => {
const room = `encrypted${ data.random }`;
const newPassword = 'abc';
let alertButtonType, scrollViewType;
let alertButtonType;
let scrollViewType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
@ -206,7 +207,7 @@ describe('E2E Encryption', () => {
await waitFor(element(by.id('login-view'))).toBeVisible().withTimeout(2000);
await login(testuser.username, testuser.password);
await waitFor(element(by.id('listheader-encryption').withDescendant(by.text('Save Your Encryption Password')))).toBeVisible().withTimeout(2000);
})
});
});
});

View File

@ -17,7 +17,8 @@ async function waitForToast() {
}
describe('Profile screen', () => {
let textInputType, scrollViewType;
let textInputType;
let scrollViewType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
@ -94,7 +95,9 @@ describe('Profile screen', () => {
await element(by.id('profile-view-submit')).tap();
await element(by.type(textInputType)).typeText(`${ profileChangeUser.password }\n`);
// TODO: Check if this is fine on iOS
if(device.getPlatform() === 'android') await element(by.text('SAVE')).tap();
if (device.getPlatform() === 'android') {
await element(by.text('SAVE')).tap();
}
await waitForToast();
});

View File

@ -70,7 +70,7 @@ describe('Settings screen', () => {
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);
await element(by.text('Clear').and(by.type(alertButtonType))).tap();
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-${ data.groups.private.name }`))).toExist().withTimeout(10000);
});

View File

@ -34,7 +34,7 @@ describe('Join public room', () => {
describe('Render', () => {
it('should have room screen', async() => {
await expect(element(by.id('room-view'))).toBeVisible();
});
});
// it('should have messages list', async() => {
// await expect(element(by.id('room-view-messages'))).toBeVisible();

View File

@ -1,5 +1,7 @@
const data = require('../../data');
const { navigateToLogin, login, mockMessage, searchRoom } = require('../../helpers/app');
const {
navigateToLogin, login, mockMessage, searchRoom
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');
const testuser = data.users.regular;

View File

@ -7,7 +7,8 @@ const platformTypes = require('../../helpers/platformTypes');
const { prepareAndroid } = require('../../helpers/platformFunctions');
describe('Delete server', () => {
let scrollViewType, alertButtonType;
let scrollViewType;
let alertButtonType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
await prepareAndroid();
@ -48,7 +49,7 @@ describe('Delete server', () => {
await element(by.id('rooms-list-header-server-dropdown-button')).tap();
await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000);
await element(by.id(`rooms-list-header-server-${ data.server }`)).longPress(1500);
await element(by.text('Delete').and(by.type(alertButtonType))).tap();
await element(by.text('Delete').and(by.type(alertButtonType))).tap();
await element(by.id('rooms-list-header-server-dropdown-button')).tap();
await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000);
await waitFor(element(by.id(`rooms-list-header-server-${ data.server }`))).toBeNotVisible().withTimeout(10000);

View File

@ -9,7 +9,7 @@ const DEEPLINK_METHODS = { AUTH: 'auth', ROOM: 'room' };
let amp = '&';
const getDeepLink = (method, server, params) => {
const deeplink = `rocketchat://${ method }?host=${ server.replace(/^(http:\/\/|https:\/\/)/, '') }${amp}${params}`;
const deeplink = `rocketchat://${ method }?host=${ server.replace(/^(http:\/\/|https:\/\/)/, '') }${ amp }${ params }`;
console.log(`Deeplinking to: ${ deeplink }`);
return deeplink;
};
@ -17,11 +17,13 @@ const getDeepLink = (method, server, params) => {
describe('Deep linking', () => {
let userId;
let authToken;
let scrollViewType;
before(async() => {
const loginResult = await login(data.users.regular.username, data.users.regular.password);
({ userId, authToken } = loginResult);
const deviceType = device.getPlatform();
amp = deviceType == 'android' ? '\\&' : '&';
amp = deviceType === 'android' ? '\\&' : '&';
({ scrollViewType } = platformTypes[deviceType]);
});
@ -30,7 +32,7 @@ describe('Deep linking', () => {
await device.launchApp({
permissions: { notifications: 'YES' },
delete: true,
url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=123${amp}token=abc`),
url: getDeepLink(DEEPLINK_METHODS.AUTH, data.server, `userId=123${ amp }token=abc`)
});
await prepareAndroid();
await waitFor(element(by.text('You\'ve been logged out by the server. Please log in again.'))).toExist().withTimeout(10000); // TODO: we need to improve this message
@ -40,7 +42,7 @@ 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/${ data.groups.private.name }`)
});
await waitFor(element(by.id(`room-view-title-${ data.groups.private.name }`))).toExist().withTimeout(30000);
await tapBack();
@ -74,7 +76,7 @@ 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/${ data.groups.private.name }`)
});
await waitFor(element(by.id(`room-view-title-${ data.groups.private.name }`))).toExist().withTimeout(10000);
@ -85,7 +87,7 @@ describe('Deep linking', () => {
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=${ roomResult.data.group._id }`)
});
await waitFor(element(by.id(`room-view-title-${ data.groups.private.name }`))).toExist().withTimeout(15000);
@ -104,7 +106,7 @@ 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/${ data.groups.private.name }`)
});
await waitFor(element(by.id(`room-view-title-${ data.groups.private.name }`))).toExist().withTimeout(10000);
@ -114,7 +116,7 @@ describe('Deep linking', () => {
await device.launchApp({
permissions: { notifications: 'YES' },
newInstance: true,
url: getDeepLink(DEEPLINK_METHODS.ROOM, 'https://google.com'),
url: getDeepLink(DEEPLINK_METHODS.ROOM, 'https://google.com')
});
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);

View File

@ -19,13 +19,15 @@ const navToLanguage = async() => {
};
describe('i18n', () => {
before(async () => {
before(async() => {
await prepareAndroid();
});
describe('OS language', () => {
it('OS set to \'en\' and proper translate to \'en\'', async() => {
if(device.getPlatform() === "android") return; // Not run on android
if (device.getPlatform() === 'android') {
return;
}
await device.launchApp({
...defaultLaunchArgs,
languageAndLocale: {
@ -40,7 +42,9 @@ describe('i18n', () => {
});
it('OS set to unavailable language and fallback to \'en\'', async() => {
if(device.getPlatform() === "android") return; // Not run on android
if (device.getPlatform() === 'android') {
return;
}
await device.launchApp({
...defaultLaunchArgs,
languageAndLocale: {

View File

@ -1,7 +1,9 @@
const {
device, expect, element, by, waitFor
} = require('detox');
const { login, navigateToLogin, logout, tapBack, searchRoom } = require('../../helpers/app');
const {
login, navigateToLogin, logout, tapBack, searchRoom
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');
const data = require('../../data');

View File

@ -1,7 +1,9 @@
const {
device, expect, element, by, waitFor
} = require('detox');
const { login, navigateToLogin, logout, tapBack } = require('../../helpers/app');
const {
login, navigateToLogin, logout, tapBack
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');
const data = require('../../data');

View File

@ -1,5 +1,7 @@
const data = require('../../data');
const { tapBack, navigateToLogin, login, tryTapping } = require('../../helpers/app');
const {
tapBack, navigateToLogin, login, tryTapping
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');

View File

@ -187,7 +187,7 @@ describe('Room screen', () => {
it('should star message', async() => {
await starMessage('message');
await sleep(1000); //https://github.com/RocketChat/Rocket.Chat.ReactNative/issues/2324
await sleep(1000); // https://github.com/RocketChat/Rocket.Chat.ReactNative/issues/2324
await element(by.text(`${ data.random }message`)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();

View File

@ -1,7 +1,9 @@
const data = require('../../data');
const { navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage } = require('../../helpers/app');
const {
navigateToLogin, login, tapBack, sleep, searchRoom, mockMessage, starMessage, pinMessage
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');
const { sendMessage } = require('../../helpers/data_setup')
const { sendMessage } = require('../../helpers/data_setup');
const platformTypes = require('../../helpers/platformTypes');
@ -213,14 +215,14 @@ describe('Room actions screen', () => {
await element(by.id('room-header')).tap();
await waitFor(element(by.id('room-actions-view'))).toExist().withTimeout(5000);
//Go to starred messages
// Go to starred messages
await element(by.id('room-actions-view')).swipe('up');
await waitFor(element(by.id('room-actions-starred'))).toExist();
await element(by.id('room-actions-starred')).tap();
await waitFor(element(by.id('starred-messages-view'))).toExist().withTimeout(2000);
await waitFor(element(by.text(`${ data.random }messageToStar`).withAncestor(by.id('starred-messages-view')))).toExist().withTimeout(60000);
//Unstar message
// Unstar message
await element(by.text(`${ data.random }messageToStar`)).atIndex(0).longPress();
await expect(element(by.id('action-sheet'))).toExist();
await expect(element(by.id('action-sheet-handle'))).toBeVisible();

View File

@ -15,7 +15,7 @@ const navigateToRoom = async() => {
describe('Discussion', () => {
let scrollViewType;
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
await prepareAndroid();
@ -68,7 +68,7 @@ describe('Discussion', () => {
const discussionName = `${ data.random }message`;
await element(by.text(discussionName)).atIndex(0).longPress();
await waitFor(element(by.id('action-sheet'))).toExist().withTimeout(2000);
await element(by.text(`Start a Discussion`)).atIndex(0).tap();
await element(by.text('Start a Discussion')).atIndex(0).tap();
await waitFor(element(by.id('create-discussion-view'))).toExist().withTimeout(2000);
await element(by.id('create-discussion-submit')).tap();
await waitFor(element(by.id('room-view'))).toExist().withTimeout(10000);

View File

@ -3,7 +3,7 @@ const {
navigateToLogin, login, searchRoom, sleep
} = require('../../helpers/app');
const { prepareAndroid } = require('../../helpers/platformFunctions');
const { sendMessage } = require('../../helpers/data_setup')
const { sendMessage } = require('../../helpers/data_setup');
async function navigateToRoom(user) {
await searchRoom(`${ user }`);