Best JavaScript code snippet using webdriverio-monorepo
index.js
Source:index.js
1import { NativeModules, Platform, Alert } from 'react-native';2import { listeners, emit } from './actions';3const RNCallKeepModule = NativeModules.RNCallKeep;4const isIOS = Platform.OS === 'ios';5const supportConnectionService = !isIOS && Platform.Version >= 23;6const CONSTANTS = {7 END_CALL_REASONS: {8 FAILED: 1,9 REMOTE_ENDED: 2,10 UNANSWERED: 3,11 ANSWERED_ELSEWHERE: 4,12 DECLINED_ELSEWHERE: isIOS ? 5 : 2, // make declined elsewhere link to "Remote ended" on android because that's kinda true13 MISSED: isIOS ? 2 : 6,14 },15};16export { emit, CONSTANTS };17class RNCallKeep {18 constructor() {19 this._callkeepEventHandlers = new Map();20 }21 addEventListener = (type, handler) => {22 const listener = listeners[type](handler);23 this._callkeepEventHandlers.set(type, listener);24 };25 removeEventListener = (type) => {26 const listener = this._callkeepEventHandlers.get(type);27 if (!listener) {28 return;29 }30 listener.remove();31 this._callkeepEventHandlers.delete(type);32 };33 setup = async (options) => {34 if (!isIOS) {35 return this._setupAndroid(options.android);36 }37 return this._setupIOS(options.ios);38 };39 registerPhoneAccount = (options) => {40 if (isIOS) {41 return;42 }43 RNCallKeepModule.registerPhoneAccount(options.android);44 };45 registerAndroidEvents = () => {46 if (isIOS) {47 return;48 }49 RNCallKeepModule.registerEvents();50 };51 unregisterAndroidEvents = () => {52 if (isIOS) {53 return;54 }55 RNCallKeepModule.unregisterEvents();56 };57 hasDefaultPhoneAccount = async (options) => {58 if (!isIOS) {59 return this._hasDefaultPhoneAccount(options);60 }61 return;62 };63 displayIncomingCall = (64 uuid,65 handle,66 localizedCallerName = '',67 handleType = 'number',68 hasVideo = false,69 options = null70 ) => {71 if (!isIOS) {72 RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName);73 return;74 }75 // should be boolean type value76 let supportsHolding = !!(options?.ios?.supportsHolding ?? true);77 let supportsDTMF = !!(options?.ios?.supportsDTMF ?? true);78 let supportsGrouping = !!(options?.ios?.supportsGrouping ?? true);79 let supportsUngrouping = !!(options?.ios?.supportsUngrouping ?? true);80 RNCallKeepModule.displayIncomingCall(81 uuid,82 handle,83 handleType,84 hasVideo,85 localizedCallerName,86 supportsHolding,87 supportsDTMF,88 supportsGrouping,89 supportsUngrouping90 );91 };92 answerIncomingCall = (uuid) => {93 RNCallKeepModule.answerIncomingCall(uuid);94 };95 startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => {96 if (!isIOS) {97 RNCallKeepModule.startCall(uuid, handle, contactIdentifier);98 return;99 }100 RNCallKeepModule.startCall(uuid, handle, contactIdentifier, handleType, hasVideo);101 };102 checkPhoneAccountEnabled = async () => {103 if (isIOS) {104 return;105 }106 return RNCallKeepModule.checkPhoneAccountEnabled();107 };108 isConnectionServiceAvailable = async () => {109 if (isIOS) {110 return true;111 }112 return RNCallKeepModule.isConnectionServiceAvailable();113 };114 reportConnectingOutgoingCallWithUUID = (uuid) => {115 //only available on iOS116 if (isIOS) {117 RNCallKeepModule.reportConnectingOutgoingCallWithUUID(uuid);118 }119 };120 reportConnectedOutgoingCallWithUUID = (uuid) => {121 //only available on iOS122 if (isIOS) {123 RNCallKeepModule.reportConnectedOutgoingCallWithUUID(uuid);124 }125 };126 reportEndCallWithUUID = (uuid, reason) => RNCallKeepModule.reportEndCallWithUUID(uuid, reason);127 /*128 * Android explicitly states we reject a call129 * On iOS we just notify of an endCall130 */131 rejectCall = (uuid) => {132 if (!isIOS) {133 RNCallKeepModule.rejectCall(uuid);134 } else {135 RNCallKeepModule.endCall(uuid);136 }137 };138 isCallActive = async (uuid) => await RNCallKeepModule.isCallActive(uuid);139 getCalls = () => {140 if (isIOS) {141 return RNCallKeepModule.getCalls();142 }143 };144 endCall = (uuid) => RNCallKeepModule.endCall(uuid);145 endAllCalls = () => RNCallKeepModule.endAllCalls();146 supportConnectionService = () => supportConnectionService;147 hasPhoneAccount = async () => (isIOS ? true : await RNCallKeepModule.hasPhoneAccount());148 hasOutgoingCall = async () => (isIOS ? null : await RNCallKeepModule.hasOutgoingCall());149 setMutedCall = (uuid, shouldMute) => {150 RNCallKeepModule.setMutedCall(uuid, shouldMute);151 };152 sendDTMF = (uuid, key) => RNCallKeepModule.sendDTMF(uuid, key);153 /**154 * @description when Phone call is active, Android control the audio service via connection service. so this function help to toggle the audio to Speaker or wired/ear-piece or vice-versa155 * @param {*} uuid156 * @param {*} routeSpeaker157 * @returns Audio route state of audio service158 */159 toggleAudioRouteSpeaker = (uuid, routeSpeaker) => isIOS ? null : RNCallKeepModule.toggleAudioRouteSpeaker(uuid, routeSpeaker);160 getAudioRoutes = () => RNCallKeepModule.getAudioRoutes();161 setAudioRoute = (uuid, inputName) => RNCallKeepModule.setAudioRoute(uuid, inputName);162 checkIfBusy = () =>163 isIOS ? RNCallKeepModule.checkIfBusy() : Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');164 checkSpeaker = () =>165 isIOS ? RNCallKeepModule.checkSpeaker() : Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');166 setAvailable = (state) => {167 if (isIOS) {168 return;169 }170 // Tell android that we are able to make outgoing calls171 RNCallKeepModule.setAvailable(state);172 };173 setForegroundServiceSettings = (settings) => {174 if (isIOS) {175 return;176 }177 RNCallKeepModule.setForegroundServiceSettings(settings);178 };179 canMakeMultipleCalls = (state) => {180 if (isIOS) {181 return;182 }183 RNCallKeepModule.canMakeMultipleCalls(state);184 };185 setCurrentCallActive = (callUUID) => {186 if (isIOS) {187 return;188 }189 RNCallKeepModule.setCurrentCallActive(callUUID);190 };191 updateDisplay = (uuid, displayName, handle, options = null) => {192 if (!isIOS) {193 RNCallKeepModule.updateDisplay(uuid, displayName, handle);194 return;195 }196 let iosOptions = {};197 if (options && options.ios) {198 iosOptions = {199 ...options.ios,200 };201 }202 RNCallKeepModule.updateDisplay(uuid, displayName, handle, iosOptions);203 };204 setOnHold = (uuid, shouldHold) => RNCallKeepModule.setOnHold(uuid, shouldHold);205 setConnectionState = (uuid, state) => isIOS ? null : RNCallKeepModule.setConnectionState(uuid, state);206 setReachable = () => RNCallKeepModule.setReachable();207 // @deprecated208 reportUpdatedCall = (uuid, localizedCallerName) => {209 console.warn('RNCallKeep.reportUpdatedCall is deprecated, use RNCallKeep.updateDisplay instead');210 return isIOS211 ? RNCallKeepModule.reportUpdatedCall(uuid, localizedCallerName)212 : Promise.reject('RNCallKeep.reportUpdatedCall was called from unsupported OS');213 };214 _setupIOS = async (options) =>215 new Promise((resolve, reject) => {216 if (!options.appName) {217 reject('RNCallKeep.setup: option "appName" is required');218 }219 if (typeof options.appName !== 'string') {220 reject('RNCallKeep.setup: option "appName" should be of type "string"');221 }222 resolve(RNCallKeepModule.setup(options));223 });224 _setupAndroid = async (options) => {225 RNCallKeepModule.setup(options);226 if (options.selfManaged) {227 return false;228 }229 const showAccountAlert = await RNCallKeepModule.checkPhoneAccountPermission(options.additionalPermissions || []);230 const shouldOpenAccounts = await this._alert(options, showAccountAlert);231 if (shouldOpenAccounts) {232 RNCallKeepModule.openPhoneAccounts();233 return true;234 }235 return false;236 };237 _hasDefaultPhoneAccount = async (options) => {238 const hasDefault = await RNCallKeepModule.checkDefaultPhoneAccount();239 const shouldOpenAccounts = await this._alert(options, hasDefault);240 if (shouldOpenAccounts) {241 RNCallKeepModule.openPhoneAccountSettings();242 }243 };244 _alert = async (options, condition) =>245 new Promise((resolve, reject) => {246 if (!condition) {247 return resolve(false);248 }249 Alert.alert(250 options.alertTitle,251 options.alertDescription,252 [253 {254 text: options.cancelButton,255 onPress: reject,256 style: 'cancel',257 },258 { text: options.okButton, onPress: () => resolve(true) },259 ],260 { cancelable: true }261 );262 });263 backToForeground() {264 if (isIOS) {265 return;266 }267 NativeModules.RNCallKeep.backToForeground();268 }269 getInitialEvents() {270 if (isIOS) {271 return RNCallKeepModule.getInitialEvents()272 }273 return Promise.resolve([])274 }275}...
platform.js
Source:platform.js
1// @flow2import color from 'color';3import { Platform, Dimensions, PixelRatio } from 'react-native';4import { isIos } from './commonColor';5const deviceHeight = Dimensions.get('window').height;6const deviceWidth = Dimensions.get('window').width;7const platform = Platform.OS;8const platformStyle = undefined;9const isIphoneX = isIos && (deviceHeight === 812 || deviceWidth === 812 || deviceHeight === 896 || deviceWidth === 896);10export default {11 platformStyle,12 platform,13 // Accordion14 accordionBorderColor: '#d3d3d3',15 accordionContentPadding: 10,16 accordionIconFontSize: 18,17 contentStyle: '#f5f4f5',18 expandedIconStyle: '#000',19 headerStyle: '#edebed',20 iconStyle: '#000',21 // ActionSheet22 elevation: 4,23 containerTouchableBackgroundColor: 'rgba(0,0,0,0.4)',24 innerTouchableBackgroundColor: '#fff',25 listItemHeight: 50,26 listItemBorderColor: 'transparent',27 marginHorizontal: -15,28 marginLeft: 14,29 marginTop: 15,30 minHeight: 56,31 padding: 15,32 touchableTextColor: '#757575',33 // Android34 androidRipple: true,35 androidRippleColor: 'rgba(256, 256, 256, 0.3)',36 androidRippleColorDark: 'rgba(0, 0, 0, 0.15)',37 buttonUppercaseAndroidText: true,38 // Badge39 badgeBg: '#ED1727',40 badgeColor: '#fff',41 badgePadding: isIos ? 3 : 0,42 // Button43 buttonFontFamily: isIos ? 'System' : 'Roboto_medium',44 buttonDisabledBg: '#b5b5b5',45 buttonPadding: 6,46 buttonDefaultActiveOpacity: 0.5,47 buttonDefaultFlex: 1,48 buttonDefaultBorderRadius: 2,49 buttonDefaultBorderWidth: 1,50 get buttonPrimaryBg() {51 return this.brandPrimary;52 },53 get buttonPrimaryColor() {54 return this.inverseTextColor;55 },56 get buttonInfoBg() {57 return this.brandInfo;58 },59 get buttonInfoColor() {60 return this.inverseTextColor;61 },62 get buttonSuccessBg() {63 return this.brandSuccess;64 },65 get buttonSuccessColor() {66 return this.inverseTextColor;67 },68 get buttonDangerBg() {69 return this.brandDanger;70 },71 get buttonDangerColor() {72 return this.inverseTextColor;73 },74 get buttonWarningBg() {75 return this.brandWarning;76 },77 get buttonWarningColor() {78 return this.inverseTextColor;79 },80 get buttonTextSize() {81 return isIos ? this.fontSizeBase * 1.1 : this.fontSizeBase - 1;82 },83 get buttonTextSizeLarge() {84 return this.fontSizeBase * 1.5;85 },86 get buttonTextSizeSmall() {87 return this.fontSizeBase * 0.8;88 },89 get borderRadiusLarge() {90 return this.fontSizeBase * 3.8;91 },92 get iconSizeLarge() {93 return this.iconFontSize * 1.5;94 },95 get iconSizeSmall() {96 return this.iconFontSize * 0.6;97 },98 // Card99 cardDefaultBg: '#fff',100 cardBorderColor: '#ccc',101 cardBorderRadius: 2,102 cardItemPadding: isIos ? 10 : 12,103 // CheckBox104 CheckboxRadius: isIos ? 13 : 0,105 CheckboxBorderWidth: isIos ? 1 : 2,106 CheckboxPaddingLeft: isIos ? 4 : 2,107 CheckboxPaddingBottom: isIos ? 0 : 5,108 CheckboxIconSize: isIos ? 21 : 16,109 CheckboxIconMarginTop: isIos ? undefined : 1,110 CheckboxFontSize: isIos ? 23 / 0.9 : 17,111 checkboxBgColor: '#039BE5',112 checkboxSize: 20,113 checkboxTickColor: '#fff',114 checkboxDefaultColor: 'transparent',115 checkboxTextShadowRadius: 0,116 // Color117 brandPrimary: isIos ? '#007aff' : '#3F51B5',118 brandInfo: '#62B1F6',119 brandSuccess: '#5cb85c',120 brandDanger: '#d9534f',121 brandWarning: '#f0ad4e',122 brandDark: '#000',123 brandLight: '#a9a9a9',124 // Container125 containerBgColor: '#fff',126 // Date Picker127 datePickerFlex: 1,128 datePickerPadding: 10,129 datePickerTextColor: '#000',130 datePickerBg: 'transparent',131 // FAB132 fabBackgroundColor: 'blue',133 fabBorderRadius: 28,134 fabBottom: 0,135 fabButtonBorderRadius: 20,136 fabButtonHeight: 40,137 fabButtonLeft: 7,138 fabButtonMarginBottom: 10,139 fabContainerBottom: 20,140 fabDefaultPosition: 20,141 fabElevation: 4,142 fabIconColor: '#fff',143 fabIconSize: 24,144 fabShadowColor: '#000',145 fabShadowOffsetHeight: 2,146 fabShadowOffsetWidth: 0,147 fabShadowOpacity: 0.4,148 fabShadowRadius: 2,149 fabWidth: 56,150 // Font151 DefaultFontSize: 16,152 fontFamily: isIos ? 'System' : 'Roboto',153 fontSizeBase: 15,154 get fontSizeH1() {155 return this.fontSizeBase * 1.8;156 },157 get fontSizeH2() {158 return this.fontSizeBase * 1.6;159 },160 get fontSizeH3() {161 return this.fontSizeBase * 1.4;162 },163 // Footer164 footerHeight: 55,165 footerDefaultBg: isIos ? '#F8F8F8' : '#3F51B5',166 footerPaddingBottom: 0,167 // FooterTab168 tabBarTextColor: isIos ? '#6b6b6b' : '#b3c7f9',169 tabBarTextSize: isIos ? 14 : 11,170 activeTab: isIos ? '#007aff' : '#fff',171 sTabBarActiveTextColor: '#007aff',172 tabBarActiveTextColor: isIos ? '#007aff' : '#fff',173 tabActiveBgColor: isIos ? '#cde1f9' : '#3F51B5',174 // Header175 toolbarBtnColor: isIos ? '#007aff' : '#fff',176 toolbarDefaultBg: isIos ? '#F8F8F8' : '#3F51B5',177 toolbarHeight: isIos ? 64 : 56,178 toolbarSearchIconSize: isIos ? 20 : 23,179 toolbarInputColor: isIos ? '#CECDD2' : '#fff',180 searchBarHeight: isIos ? 30 : 40,181 searchBarInputHeight: isIos ? 30 : 50,182 toolbarBtnTextColor: isIos ? '#007aff' : '#fff',183 toolbarDefaultBorder: isIos ? '#a7a6ab' : '#3F51B5',184 iosStatusbar: isIos ? 'dark-content' : 'light-content',185 get statusBarColor() {186 return color(this.toolbarDefaultBg)187 .darken(0.2)188 .hex();189 },190 get darkenHeader() {191 return color(this.tabBgColor)192 .darken(0.03)193 .hex();194 },195 // Icon196 iconFamily: 'Ionicons',197 iconFontSize: isIos ? 30 : 28,198 iconHeaderSize: isIos ? 33 : 24,199 // InputGroup200 inputFontSize: 17,201 inputBorderColor: '#D9D5DC',202 inputSuccessBorderColor: '#2b8339',203 inputErrorBorderColor: '#ed2f2f',204 inputHeightBase: 50,205 get inputColor() {206 return this.textColor;207 },208 get inputColorPlaceholder() {209 return '#575757';210 },211 // Line Height212 buttonLineHeight: 19,213 lineHeightH1: 32,214 lineHeightH2: 27,215 lineHeightH3: 25,216 lineHeight: isIos ? 20 : 24,217 listItemSelected: isIos ? '#007aff' : '#3F51B5',218 // List219 listBg: 'transparent',220 listBorderColor: '#c9c9c9',221 listDividerBg: '#f4f4f4',222 listBtnUnderlayColor: '#DDD',223 listItemPadding: isIos ? 10 : 12,224 listNoteColor: '#808080',225 listNoteSize: 13,226 // Progress Bar227 defaultProgressColor: '#E4202D',228 inverseProgressColor: '#1A191B',229 // Radio Button230 radioBtnSize: isIos ? 25 : 23,231 radioSelectedColorAndroid: '#3F51B5',232 radioBtnLineHeight: isIos ? 29 : 24,233 get radioColor() {234 return this.brandPrimary;235 },236 // Segment237 segmentBackgroundColor: isIos ? '#F8F8F8' : '#3F51B5',238 segmentActiveBackgroundColor: isIos ? '#007aff' : '#fff',239 segmentTextColor: isIos ? '#007aff' : '#fff',240 segmentActiveTextColor: isIos ? '#fff' : '#3F51B5',241 segmentBorderColor: isIos ? '#007aff' : '#fff',242 segmentBorderColorMain: isIos ? '#a7a6ab' : '#3F51B5',243 // Spinner244 defaultSpinnerColor: '#45D56E',245 inverseSpinnerColor: '#1A191B',246 // Tab247 tabBarDisabledTextColor: '#BDBDBD',248 tabDefaultBg: isIos ? '#F8F8F8' : '#3F51B5',249 topTabBarTextColor: isIos ? '#6b6b6b' : '#b3c7f9',250 topTabBarActiveTextColor: isIos ? '#007aff' : '#fff',251 topTabBarBorderColor: isIos ? '#a7a6ab' : '#fff',252 topTabBarActiveBorderColor: isIos ? '#007aff' : '#fff',253 // Tabs254 tabBgColor: '#F8F8F8',255 tabFontSize: 15,256 // Text257 textColor: '#000',258 inverseTextColor: '#fff',259 noteFontSize: 14,260 get defaultTextColor() {261 return this.textColor;262 },263 // Title264 titleFontfamily: isIos ? 'System' : 'Roboto_medium',265 titleFontSize: isIos ? 17 : 19,266 subTitleFontSize: isIos ? 11 : 14,267 subtitleColor: isIos ? '#8e8e93' : '#FFF',268 titleFontColor: isIos ? '#000' : '#FFF',269 // Other270 borderRadiusBase: isIos ? 5 : 2,271 borderWidth: 1 / PixelRatio.getPixelSizeForLayoutSize(1),272 contentPadding: 10,273 dropdownLinkColor: '#414142',274 inputLineHeight: 24,275 deviceWidth,276 deviceHeight,277 isIphoneX,278 inputGroupRoundedBorderRadius: 30,279 // iPhoneX SafeArea280 Inset: {281 portrait: {282 topInset: 24,283 leftInset: 0,284 rightInset: 0,285 bottomInset: 34,286 },287 landscape: {288 topInset: 0,289 leftInset: 44,290 rightInset: 44,291 bottomInset: 21,292 },293 },...
test_browser.js
Source:test_browser.js
1( function ( $, M ) {2 var Browser = M.require( 'mobile.browser/Browser' ),3 // Use an empty html element to avoid calling methods in _fixIosLandscapeBug4 $html = $( '<html>' );5 QUnit.module( 'Browser.js' );6 QUnit.test( 'isIos()', 8, function ( assert ) {7 var browser = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),8 browser4 = new Browser( 'Mozilla/5.0 (iPad; CPU OS 4_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),9 browser5 = new Browser( 'Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),10 browser2 = new Browser( 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/8.0 Mobile/11A465 Safari/9537.53', $html );11 assert.strictEqual( browser.isIos(), true );12 assert.strictEqual( browser.isIos( 8 ), false );13 assert.strictEqual( browser.isIos( 4 ), false );14 assert.strictEqual( browser.isIos( 5 ), false );15 assert.strictEqual( browser2.isIos(), true );16 assert.strictEqual( browser2.isIos( 8 ), true );17 assert.strictEqual( browser4.isIos( 4 ), true );18 assert.strictEqual( browser5.isIos( 5 ), true );19 } );20 QUnit.test( 'supportsPositionFixed()', function ( assert ) {21 var userAgents, userAgentsFail;22 userAgents = [23 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36',24 'Firefox',25 // IE 1026 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)',27 // IE 1128 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',29 // When Trident hits 1030 'Mozilla/5.0 (Windows NT 6.3; Trident/10.0; rv:11.0) like Gecko',31 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/600 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36',32 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/1300 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36'33 ];34 userAgentsFail = [35 'Android 1',36 // IE 5.537 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 6.1; chromeframe/12.0.742.100; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)',38 // IE 639 'Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)',40 // IE 741 'Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.0; Trident/4.0; FBSMTWB; .NET CLR 2.0.34861; .NET CLR 3.0.3746.3218; .NET CLR 3.5.33652; msn OptimizedIE8;ENUS)',42 // IE 943 'Mozilla/5.0(compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0',44 // Older WebKit based browsers45 'AppleWebKit/400',46 'AppleWebKit/20',47 'AppleWebKit/533',48 'AppleWebKit/54',49 'AppleWebKit/6'50 ];51 QUnit.expect( userAgents.length + userAgentsFail.length );52 $.each( userAgents, function ( i, ua ) {53 var browser = new Browser( ua, $html );54 assert.strictEqual( browser.supportsPositionFixed(), true, 'Success test case ' + ua );55 } );56 $.each( userAgentsFail, function ( i, ua ) {57 var browser = new Browser( ua, $html );58 assert.strictEqual( browser.supportsPositionFixed(), false, 'Failure test case ' + ua );59 } );60 } );61 QUnit.test( 'Methods are cached', 15, function ( assert ) {62 var ipad = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),63 iphone = new Browser( 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/8.0 Mobile/11A465 Safari/9537.53', $html ),64 android2 = new Browser( 'Android 2', $html );65 function cache( obj, method ) {66 return obj[ '__cache' + obj[ method ].cacheId ];67 }68 function keys( obj ) {69 return $.map( obj, function ( key ) {70 return key;71 } );72 }73 // Check that the same methods across different instances have their own74 // cache and don't interfere with one another75 assert.strictEqual( ipad.isIos(), true );76 assert.strictEqual( ipad.isIos( 8 ), false );77 assert.strictEqual( ipad.isAndroid2(), false );78 assert.strictEqual( android2.isAndroid2(), true );79 assert.strictEqual( android2.isIos( 8 ), false );80 assert.strictEqual( iphone.isIos(), true );81 assert.strictEqual( iphone.isIos( 8 ), true );82 assert.strictEqual( iphone.isAndroid2(), false );83 // Check that the caches have been filled84 // NOTE: In the constructor isAndroid2 is called with empty85 // so account for that on the assertions:86 assert.strictEqual( keys( cache( ipad, 'isIos' ) ).length, 2, 'isIos on ipad cached as expected' );87 assert.strictEqual( keys( cache( ipad, 'isAndroid2' ) ).length, 1, 'isAndroid2 on ipad cached as expected' );88 assert.strictEqual( keys( cache( android2, 'isIos' ) ).length, 1, 'isIos on android cached as expected' );89 assert.strictEqual( keys( cache( android2, 'isAndroid2' ) ).length, 1, 'isAndroid2 on android2 cached as expected' );90 assert.strictEqual( keys( cache( iphone, 'isAndroid2' ) ).length, 1, 'isAndroid2 on iphone cached as expected' );91 assert.strictEqual( keys( cache( iphone, 'isIos' ) ).length, 2, 'isIos on iphone cached as expected' );92 // Mess up the cache and see if the objects return the correct value when93 // called again with the same arguments94 cache( ipad, 'isAndroid2' )[ '' ] = 'for sure';95 assert.strictEqual( ipad.isAndroid2(), 'for sure' );96 } );...
mobileDetector.js
Source:mobileDetector.js
1import mobileDetector from '../../../lib/helpers/mobileDetector'2describe('mobileDetector helper', () => {3 it('should not detect mobile app for browserName===undefined', function () {4 const {isMobile, isIOS, isAndroid} = mobileDetector({})5 expect(isMobile).to.be.false6 expect(isIOS).to.be.false7 expect(isAndroid).to.be.false8 })9 it('should not detect mobile app for browserName==="firefox"', function () {10 const {isMobile, isIOS, isAndroid} = mobileDetector({browserName: 'firefox'})11 expect(isMobile).to.be.false12 expect(isIOS).to.be.false13 expect(isAndroid).to.be.false14 })15 it('should not detect mobile app for browserName==="chrome"', function () {16 const {isMobile, isIOS, isAndroid} = mobileDetector({browserName: 'chrome'})17 expect(isMobile).to.be.false18 expect(isIOS).to.be.false19 expect(isAndroid).to.be.false20 })21 it('should detect mobile app for browserName===""', function () {22 const {isMobile, isIOS, isAndroid} = mobileDetector({browserName: ''})23 expect(isMobile).to.be.true24 expect(isIOS).to.be.false25 expect(isAndroid).to.be.false26 })27 it('should not detect mobile app for browser==="firefox"', function () {28 const {isMobile, isIOS, isAndroid} = mobileDetector({browser: 'firefox'})29 expect(isMobile).to.be.false30 expect(isIOS).to.be.false31 expect(isAndroid).to.be.false32 })33 it('should not detect mobile app for browser==="chrome"', function () {34 const {isMobile, isIOS, isAndroid} = mobileDetector({browser: 'chrome'})35 expect(isMobile).to.be.false36 expect(isIOS).to.be.false37 expect(isAndroid).to.be.false38 })39 it('should detect mobile app for browser===""', function () {40 const {isMobile, isIOS, isAndroid} = mobileDetector({browser: ''})41 expect(isMobile).to.be.true42 expect(isIOS).to.be.false43 expect(isAndroid).to.be.false44 })45 it('should detect Android mobile app', function () {46 const {isMobile, isIOS, isAndroid} = mobileDetector({47 platformName: 'Android',48 platformVersion: '4.4',49 deviceName: 'LGVS450PP2a16334',50 app: 'foo.apk'51 })52 expect(isMobile).to.be.true53 expect(isIOS).to.be.false54 expect(isAndroid).to.be.true55 })56 it('should detect Android mobile app', function () {57 const {isMobile, isIOS, isAndroid} = mobileDetector({58 platformName: 'Android',59 platformVersion: '4.4',60 device: 'Samsung Galaxy S5 Mini',61 app: 'foo.apk'62 })63 expect(isMobile).to.be.true64 expect(isIOS).to.be.false65 expect(isAndroid).to.be.true66 })67 it('should detect Android mobile app', function () {68 const {isMobile, isIOS, isAndroid} = mobileDetector({69 platformName: 'Android',70 platformVersion: '8.0',71 device: 'Google Pixel',72 app: 'foo.apk'73 })74 expect(isMobile).to.be.true75 expect(isIOS).to.be.false76 expect(isAndroid).to.be.true77 })78 it('should detect iOS mobile app', function () {79 const {isMobile, isIOS, isAndroid} = mobileDetector({80 platformName: 'iOS',81 platformVersion: '11.2',82 device: 'iPhone X',83 app: 'foo.ipa'84 })85 expect(isMobile).to.be.true86 expect(isIOS).to.be.true87 expect(isAndroid).to.be.false88 })89 it('should detect Android mobile app without upload', function () {90 const {isMobile, isIOS, isAndroid} = mobileDetector({91 platformName: 'Android',92 platformVersion: '4.4',93 deviceName: 'LGVS450PP2a16334',94 appPackage: 'com.example',95 appActivity: 'com.example.gui.LauncherActivity',96 noReset: true,97 appWaitActivity: 'com.example.gui.LauncherActivity'98 })99 expect(isMobile).to.be.true100 expect(isIOS).to.be.false101 expect(isAndroid).to.be.true102 })103 it('should detect Android mobile app without upload', function () {104 const {isMobile, isIOS, isAndroid} = mobileDetector({105 platformName: 'Android',106 platformVersion: '4.4',107 device: 'Motorola Moto X 2nd Gen',108 appPackage: 'com.example',109 appActivity: 'com.example.gui.LauncherActivity',110 noReset: true,111 appWaitActivity: 'com.example.gui.LauncherActivity'112 })113 expect(isMobile).to.be.true114 expect(isIOS).to.be.false115 expect(isAndroid).to.be.true116 })...
Browser.test.js
Source:Browser.test.js
1/* global $ */2const3 Browser = require( '../../../src/mobile.startup/Browser' ),4 dom = require( '../utils/dom' ),5 jQuery = require( '../utils/jQuery' ),6 sinon = require( 'sinon' ),7 mediawiki = require( '../utils/mw' );8let9 $html;10/** @type {sinon.SinonSandbox} */ let sandbox;11QUnit.module( 'MobileFrontend Browser.js', {12 beforeEach: function () {13 let tmpDOM;14 sandbox = sinon.sandbox.create();15 dom.setUp( sandbox, global );16 jQuery.setUp( sandbox, global );17 mediawiki.setUp( sandbox, global );18 $html = $( tmpDOM );19 },20 afterEach: function () {21 jQuery.tearDown();22 sandbox.restore();23 }24} );25QUnit.test( 'isIos()', function ( assert ) {26 const browser = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),27 browser4 = new Browser( 'Mozilla/5.0 (iPad; CPU OS 4_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),28 browser5 = new Browser( 'Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),29 browser2 = new Browser( 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/8.0 Mobile/11A465 Safari/9537.53', $html );30 assert.strictEqual( browser.isIos(), true );31 assert.strictEqual( browser.isIos( 8 ), false );32 assert.strictEqual( browser.isIos( 4 ), false );33 assert.strictEqual( browser.isIos( 5 ), false );34 assert.strictEqual( browser2.isIos(), true );35 assert.strictEqual( browser2.isIos( 8 ), true );36 assert.strictEqual( browser4.isIos( 4 ), true );37 assert.strictEqual( browser5.isIos( 5 ), true );38} );39QUnit.test( 'Methods are cached', function ( assert ) {40 const ipad = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html ),41 iphone = new Browser( 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/8.0 Mobile/11A465 Safari/9537.53', $html ),42 android2 = new Browser( 'Android 2', $html );43 function cache( obj, method ) {44 return obj[ '__cache' + obj[ method ].cacheId ];45 }46 // Check that the same methods across different instances have their own47 // cache and don't interfere with one another48 assert.strictEqual( ipad.isIos(), true );49 assert.strictEqual( ipad.isIos( 8 ), false );50 assert.strictEqual( android2.isIos( 8 ), false );51 assert.strictEqual( iphone.isIos(), true );52 assert.strictEqual( iphone.isIos( 8 ), true );53 // Check that the caches have been filled54 assert.strictEqual( Object.keys( cache( ipad, 'isIos' ) ).length, 2, 'isIos on ipad cached as expected' );55 assert.strictEqual( Object.keys( cache( android2, 'isIos' ) ).length, 1, 'isIos on android cached as expected' );56 assert.strictEqual( Object.keys( cache( iphone, 'isIos' ) ).length, 2, 'isIos on iphone cached as expected' );57} );58QUnit.test( 'isWideScreen()', function ( assert ) {59 const browser = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html );60 sandbox.stub( mw.config, 'get' ).callsFake( function () {61 return '720px';62 } );63 assert.strictEqual( browser.isWideScreen(), true );64} );65QUnit.test( 'supportsTouchEvents()', function ( assert ) {66 const browser = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html );67 window.ontouchstart = window.ontouchstart || undefined;68 assert.strictEqual( browser.supportsTouchEvents(), true );69} );70QUnit.test( 'supportsGeoLocation()', function ( assert ) {71 const browser = new Browser( 'Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko)', $html );72 window.navigator.geolocation = window.navigator.geolocation || undefined;73 assert.strictEqual( browser.supportsGeoLocation(), true );...
ProfileStats.js
Source:ProfileStats.js
1import React, {useContext, useEffect} from 'react';2import {Text} from 'components';3import {View} from '../../../widgets';4import {formatMoney, isIOS, loadOrder} from '../../../utils';5import {AuthContext} from "../../../contexts/AuthContext";6const Referral = () => {7 const {orders} = useContext(AuthContext).auth8 const all = [...orders.completed, ...orders.current];9 const completed = orders.completed;10 const pending = orders.current;11 const rejected = all.filter((orders) => orders.status_id === 4);12 const processing = all.filter((orders) => orders.status_id === 1);13 return (14 <View py={20}>15 <View row spaced>16 <View r={10} flex central card mr={8}>17 <Text info bold fs={isIOS ? 16 : 13} my={6}>Total Orders</Text>18 <Text title fs={isIOS ? 22 : 18} primary>{all.length}</Text>19 </View>20 <View r={10} flex central card ml={8}>21 <Text info bold fs={isIOS ? 16 : 13} my={6}>Pending Orders</Text>22 <Text title fs={isIOS ? 22 : 18} primary>{pending.length}</Text>23 </View>24 </View>25 <View mt={15} row spaced>26 <View r={10} flex central card mr={8}>27 <Text info bold fs={isIOS ? 16 : 13} my={6}>Completed Orders</Text>28 <Text title fs={isIOS ? 22 : 18} numberOfLines={completed.length}29 primary>0</Text>30 </View>31 <View r={10} flex central card ml={8}>32 <Text info bold fs={isIOS ? 16 : 13} my={6}>Cancelled Orders</Text>33 <Text title fs={isIOS ? 22 : 18} primary>{rejected.length}</Text>34 </View>35 </View>36 </View>37 );38}...
useIsIOS.js
Source:useIsIOS.js
1import { useEffect, useState } from 'react';2import dayjs from 'dayjs';3// import 'dayjs/locale/de-at';4// dayjs.locale('de-at');5export default function useIsIOS() {6 const [isIOS, setIsIOS] = useState({});7 useEffect(() => {8 setIsIOS(checkForIOS());9 return () => console.log('CLEANUP INSTALL PROMPT', isIOS);10 }, []);11 return isIOS;12}13function checkForIOS() {14 if (navigator.standalone) {15 return false;16 }17 const today = dayjs().toDate();18 const lastPrompt = dayjs(localStorage.getItem('installPrompt'));19 const days = dayjs(today).diff(lastPrompt, 'days');20 const ua = window.navigator.userAgent;21 // const isApple = ['iPhone', 'iPad', 'iPod'].includes(navigator.platform);22 const isIPad = !!ua.match(/iPad/i);23 const isIPhone = !!ua.match(/iPhone/i);24 const isIOS = isIPad || isIPhone;25 // const webkit = !!ua.match(/WebKit/i);26 // const isSafari = isIOS && webkit && !ua.match(/CriOS/i);27 const webkit = ua.indexOf('Safari') >= 1 && ua.indexOf('Chrome') === -1 ? true : false;28 const isSafari = isIOS && webkit;29 const prompt = (isNaN(days) || days > 14) && isIOS; //&& isSafari; //isIOS //(isIOS || isApple);30 if (prompt && 'localStorage' in window) {31 localStorage.setItem('installPrompt', today);32 }33 //return { isIOS, isSafari, prompt };34 return { isIOS, prompt, isSafari };35}36// const myDate = new Date();37// const fullDate = myDate.toLocaleDateString('de-AT');38// const time = myDate.toLocaleTimeString('de-AT');39// const [month, date, year] = myDate.toLocaleDateString('de-AT').split('.');...
Spacings.js
Source:Spacings.js
1/**2 * Copyright 2016 Reza (github.com/rghorbani)3 *4 * @flow5 */6'use strict';7const _ = require('lodash');8const { Constants } = require('../helpers');9class Spacings {10 s1 = Constants.isIOS ? 3 : 4;11 s2 = Constants.isIOS ? 6 : 8;12 s3 = Constants.isIOS ? 9 : 12;13 s4 = Constants.isIOS ? 12 : 16;14 s5 = Constants.isIOS ? 15 : 20;15 s6 = Constants.isIOS ? 18 : 24;16 s7 = Constants.isIOS ? 21 : 28;17 s8 = Constants.isIOS ? 24 : 32;18 s9 = Constants.isIOS ? 27 : 36;19 s10 = Constants.isIOS ? 30 : 40;20 loadSpacings(spacings) {21 _.forEach(spacings, (value, key) => {22 this[key] = value;23 });24 }25 getKeysPattern() {26 return new RegExp(27 _.chain(this)28 .keys()29 .join('|')30 .value(),31 );32 }33}...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .isIOS(function(err, isIOS) {9 })10 .end();11var webdriverio = require('webdriverio');12var options = {13 desiredCapabilities: {14 }15};16 .remote(options)17 .init()18 .isIOS(function(err, isIOS) {19 })20 .end();
Using AI Code Generation
1const assert = require('assert');2const { remote } = require('webdriverio');3(async () => {4 const browser = await remote({5 capabilities: {6 }7 })8 const title = await browser.getTitle()9 console.log('Title was: ' + title)10 assert.strictEqual(title, 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js')11 await browser.deleteSession()12})().catch((e) => console.error(e))
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getTitle().then(function(title) {9 console.log('Title was: ' + title);10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .getTitle().then(function(title) {20 console.log('Title was: ' + title);21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .getTitle().then(function(title) {31 console.log('Title was: ' + title);32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .getTitle().then(function(title) {42 console.log('Title was: ' + title);43 })44 .end();45var webdriverio = require('webdriverio');46var options = {47 desiredCapabilities: {48 }49};50 .remote(options)51 .init()52 .getTitle().then(function(title) {53 console.log('Title was: ' + title);54 })55 .end();56var webdriverio = require('webdriverio');57var options = {58 desiredCapabilities: {59 }60};
Using AI Code Generation
1const isIOS = require('webdriverio').isIOS;2if (isIOS) {3}4const isAndroid = require('webdriverio').isAndroid;5if (isAndroid) {6}7const isMobile = require('webdriverio').isMobile;8if (isMobile) {9}10const isIOSApp = require('webdriverio').isIOSApp;11if (isIOSApp) {12}13const isAndroidApp = require('webdriverio').isAndroidApp;14if (isAndroidApp) {15}16const isWeb = require('webdriverio').isWeb;17if (isWeb) {18}19const isMobileApp = require('webdriverio').isMobileApp;20if (isMobileApp) {21}22const isIOSWeb = require('webdriverio').isIOSWeb;23if (isIOSWeb) {24}25const isAndroidWeb = require('webdriverio').isAndroidWeb;26if (isAndroidWeb) {27}28const isAndroidWeb = require('webdriverio').isAndroidWeb;29if (isAndroidWeb) {30}31const isAndroidWeb = require('webdriverio').isAndroidWeb;32if (isAndroidWeb) {33}34const isAndroidWeb = require('webdriverio').isAndroidWeb;35if (isAndroidWeb) {36}37const isAndroidWeb = require('webdriverio').isAndroidWeb;38if (isAndroidWeb) {39}
Using AI Code Generation
1const wdio = require('webdriverio');2const iosOptions = {3};4const androidOptions = {5};6const isIOS = () => {7 return browser.desiredCapabilities.platformName === 'iOS';8};9const options = isIOS() ? iosOptions : androidOptions;10const client = wdio.remote(options);11client.end();
Using AI Code Generation
1describe('test', function() {2 it('should do something', function () {3 if (browser.isIOS) {4 browser.setValue('#lst-ib', 'WebdriverIO');5 } else {6 browser.setValue('#lst-ib', 'WebdriverIO');7 }8 });9});
Using AI Code Generation
1describe('Test', () => {2 it('should test', () => {3 console.log(browser.isIOS);4 browser.pause(3000);5 });6});7describe('Test', () => {8 it('should test', () => {9 console.log(browser.isMobile);10 browser.pause(3000);11 });12});13Your name to display (optional):
Using AI Code Generation
1if (isIOS) {2}3if (isIOS) {4}5if (isAndroid) {6}7if (isBrowserstack) {8}9if (isLocal) {10}11if (isSauceLabs) {12}13if (isTestingBot) {14}15if (isHeadless) {16}17if (isMobile) {18}19if (isDesktop) {20}21if (isMobileNative) {22}23if (isMobileWeb) {24}25if (isSafari) {26}27if (isChrome) {28}29if (isFirefox) {30}31if (isEdge) {
Wondering what could be a next-gen browser and mobile test automation framework that is also simple and concise? Yes, that’s right, it's WebdriverIO. Since the setup is very easy to follow compared to Selenium testing configuration, you can configure the features manually thereby being the center of attraction for automation testing. Therefore the testers adopt WedriverIO to fulfill their needs of browser testing.
Learn to run automation testing with WebdriverIO tutorial. Go from a beginner to a professional automation test expert with LambdaTest WebdriverIO tutorial.
Running Your First Automation Script - Learn the steps involved to execute your first Test Automation Script using WebdriverIO since the setup is very easy to follow and the features can be configured manually.
Selenium Automation With WebdriverIO - Read more about automation testing with WebdriverIO and how it supports both browsers and mobile devices.
Browser Commands For Selenium Testing - Understand more about the barriers faced while working on your Selenium Automation Scripts in WebdriverIO, the ‘browser’ object and how to use them?
Handling Alerts & Overlay In Selenium - Learn different types of alerts faced during automation, how to handle these alerts and pops and also overlay modal in WebdriverIO.
How To Use Selenium Locators? - Understand how Webdriver uses selenium locators in a most unique way since having to choose web elements very carefully for script execution is very important to get stable test results.
Deep Selectors In Selenium WebdriverIO - The most popular automation testing framework that is extensively adopted by all the testers at a global level is WebdriverIO. Learn how you can use Deep Selectors in Selenium WebdriverIO.
Handling Dropdown In Selenium - Learn more about handling dropdowns and how it's important while performing automated browser testing.
Automated Monkey Testing with Selenium & WebdriverIO - Understand how you can leverage the amazing quality of WebdriverIO along with selenium framework to automate monkey testing of your website or web applications.
JavaScript Testing with Selenium and WebdriverIO - Speed up your Javascript testing with Selenium and WebdriverIO.
Cross Browser Testing With WebdriverIO - Learn more with this step-by-step tutorial about WebdriverIO framework and how cross-browser testing is done with WebdriverIO.
Get 100 minutes of automation test minutes FREE!!