mattermost-mobile/detox/e2e/support/utils.js
Joseph Baylon 7aebfd0b13
MM-30286 Detox/E2E: Add e2e test for MM-T3249 and added useful helpers (#4990)
* MM-30286 Detox/E2E: Add e2e test for MM-T3249 and added useful helper functions

* Update app/components/sidebars/main/channels_list/channels_list.js

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Add team icon content helper query

* Fixed reset for teams

* MM-30286 Detox/E2E: Add e2e test for MM-T3235 (#5003)

* MM-30286 Detox/E2E: Add e2e test for MM-T3255 (#5006)

* Fix merge issues

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-12-15 17:24:45 -08:00

71 lines
1.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {v4 as uuidv4} from 'uuid';
/**
* Explicit `wait` should not normally used but made available for special cases.
* @param {number} ms - duration in millisecond
*/
export const wait = async (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};
export const isAndroid = () => {
return device.getPlatform() === 'android';
};
export const isIos = () => {
return device.getPlatform() === 'ios';
};
/**
* @param {number} length - length on random string to return, e.g. 6 (default)
* @return {string} random string
*/
export const getRandomId = (length = 6) => {
const MAX_SUBSTRING_INDEX = 27;
return uuidv4().replace(/-/g, '').substring(MAX_SUBSTRING_INDEX - length, MAX_SUBSTRING_INDEX);
};
/**
* @param {string} text
* @return {string} capitalized text
*/
export const capitalize = (text) => {
return text.charAt(0).toUpperCase() + text.slice(1);
};
/**
* @param {map} testIDMap - map of testIDs
* @return {map} map of testID matchers
*/
export const testIDMatcherMap = (testIDMap) => {
const testIDFilter = (k, v) => {
const key = k.toLowerCase();
if (key.endsWith('prefix') ||
key.endsWith('suffix') ||
v.startsWith('.') ||
v.endsWith('.')) {
return false;
}
return true;
};
return testIDMap.filter(([k, v]) => testIDFilter(k, v)).map(([k, v]) => [k, by.id(v)]);
};
const SECOND = 1000;
const MINUTE = 60 * 1000;
export const timeouts = {
HALF_SEC: SECOND / 2,
ONE_SEC: SECOND,
TWO_SEC: SECOND * 2,
FOUR_SEC: SECOND * 4,
TEN_SEC: SECOND * 10,
HALF_MIN: MINUTE / 2,
ONE_MIN: MINUTE,
TWO_MIN: MINUTE * 2,
FOUR_MIN: MINUTE * 4,
};