1import * as Application from 'expo-application'; 2import { isDevice } from 'expo-device'; 3import { Platform } from 'react-native'; 4 5import ExponentTest from '../ExponentTest'; 6 7export const name = 'Application'; 8export async function test({ describe, it, expect, jasmine }) { 9 describe(`Constants and methods common to Android and iOS`, () => { 10 describe('constants tests', () => { 11 it('gets Application.applicationName as a String', () => { 12 const applicationName = Application.applicationName; 13 expect(applicationName).toEqual(jasmine.any(String)); 14 }); 15 it('gets Application.applicationId as a String', () => { 16 //e.g. iOS: 'host.exp.Exponent', Android: 'host.exp.exponent' 17 const applicationId = Application.applicationId; 18 expect(applicationId).toBeDefined(); 19 expect(applicationId).toEqual(jasmine.any(String)); 20 }); 21 it('gets nativeApplicationVersion as a String', () => { 22 const nativeApplicationVersion = Application.nativeApplicationVersion; 23 expect(nativeApplicationVersion).toBeDefined(); 24 expect(nativeApplicationVersion).toEqual(jasmine.any(String)); 25 }); 26 it('gets Application.nativeBuildVersion as a String', () => { 27 //this will return a `number` on Android and a `string` on iOS 28 const nativeBuildVersion = Application.nativeBuildVersion; 29 expect(nativeBuildVersion).toBeDefined(); 30 expect(nativeBuildVersion).toEqual(jasmine.any(String)); 31 }); 32 }); 33 describe(`Application.getInstallationTimeAsync()`, () => { 34 it(`returns a Date object`, async () => { 35 const installationTime = await Application.getInstallationTimeAsync(); 36 expect(installationTime).toBeDefined(); 37 expect(installationTime).toEqual(jasmine.any(Date)); 38 }); 39 }); 40 }); 41 42 if (Platform.OS === 'ios') { 43 describe(`iOS device tests`, () => { 44 it(`Application.getIosIdForVendorAsync() returns String`, async () => { 45 let idfv; 46 let error = null; 47 try { 48 idfv = await Application.getIosIdForVendorAsync(); 49 } catch (e) { 50 error = e; 51 } 52 expect(idfv).toBeDefined(); 53 expect(idfv).toEqual(jasmine.any(String)); 54 expect(error).toBeNull(); 55 }); 56 57 it('Application.getIosApplicationReleaseTypeAsync() returns a number', async () => { 58 const appReleaseType = await Application.getIosApplicationReleaseTypeAsync(); 59 expect(appReleaseType).toBeDefined(); 60 expect(appReleaseType).toEqual(jasmine.any(Number)); 61 }); 62 63 it('Application.getIosPushNotificationServiceEnvironmentAsync() returns a string', async () => { 64 const apnsEnvironment = await Application.getIosPushNotificationServiceEnvironmentAsync(); 65 expect(apnsEnvironment).toBeDefined(); 66 if (isDevice) { 67 expect(apnsEnvironment).toEqual(jasmine.any(String)); 68 } else { 69 expect(apnsEnvironment).toBeNull(); 70 } 71 }); 72 73 describe(`doesn't get Android-only constants`, () => { 74 it('Application.androidId is null', () => { 75 expect(Application.androidId).toBeNull(); 76 }); 77 }); 78 79 describe(`doesn't call Android-only methods`, () => { 80 it(`Application.getLastUpdateTimeAsync() doesn't get called`, async () => { 81 let lastUpdateTime; 82 let error = null; 83 try { 84 lastUpdateTime = await Application.getLastUpdateTimeAsync(); 85 } catch (e) { 86 error = e; 87 } 88 expect(error).toBeDefined(); 89 expect(lastUpdateTime).toBeUndefined(); 90 }); 91 it(`Application.getInstallReferrerAsync() doesn't get called`, async () => { 92 let installReferrer; 93 let error = null; 94 try { 95 installReferrer = await Application.getInstallReferrerAsync(); 96 } catch (e) { 97 error = e; 98 } 99 expect(error).toBeDefined(); 100 expect(installReferrer).toBeUndefined(); 101 }); 102 }); 103 }); 104 } else if (Platform.OS === 'android') { 105 describe(`Android device tests`, () => { 106 it(`gets Application.androidId as a String`, () => { 107 const androidId = Application.androidId; 108 109 expect(androidId).toBeDefined(); 110 expect(androidId).toEqual(jasmine.any(String)); 111 }); 112 113 if (ExponentTest && !ExponentTest.isInCI) { 114 it(`Application.getInstallReferrerAsync() returns String`, async () => { 115 let error = null; 116 let installReferrer; 117 try { 118 installReferrer = await Application.getInstallReferrerAsync(); 119 } catch (e) { 120 error = e; 121 } 122 expect(installReferrer).toEqual(jasmine.any(String)); 123 expect(error).toBeNull(); 124 }); 125 } 126 it(`Application.getLastUpdateTimeAsync() returns String`, async () => { 127 let error = null; 128 let lastUpdateTime; 129 try { 130 lastUpdateTime = await Application.getLastUpdateTimeAsync(); 131 } catch (e) { 132 error = e; 133 } 134 expect(lastUpdateTime).toEqual(jasmine.any(Date)); 135 expect(error).toBeNull(); 136 }); 137 describe(`doesn't call iOS-only methods`, () => { 138 it(`Application.getIosIdForVendorAsync doesn't get called`, async () => { 139 let idfv; 140 let error = null; 141 try { 142 idfv = await Application.getIosIdForVendorAsync(); 143 } catch (e) { 144 error = e; 145 } 146 expect(error).toBeDefined(); 147 expect(idfv).toBeUndefined(); 148 }); 149 }); 150 }); 151 } 152} 153