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