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