xref: /expo/apps/test-suite/tests/Application.js (revision 0dde25e8)
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 call Android-only methods`, () => {
74        it(`Application.getAndroidId() doesn't get called`, () => {
75          let androidId;
76          let error = null;
77          try {
78            androidId = Application.getAndroidId();
79          } catch (e) {
80            error = e;
81          }
82          expect(error).toBeDefined();
83          expect(androidId).toBeUndefined();
84        });
85        it(`Application.getLastUpdateTimeAsync() doesn't get called`, async () => {
86          let lastUpdateTime;
87          let error = null;
88          try {
89            lastUpdateTime = await Application.getLastUpdateTimeAsync();
90          } catch (e) {
91            error = e;
92          }
93          expect(error).toBeDefined();
94          expect(lastUpdateTime).toBeUndefined();
95        });
96        it(`Application.getInstallReferrerAsync() doesn't get called`, async () => {
97          let installReferrer;
98          let error = null;
99          try {
100            installReferrer = await Application.getInstallReferrerAsync();
101          } catch (e) {
102            error = e;
103          }
104          expect(error).toBeDefined();
105          expect(installReferrer).toBeUndefined();
106        });
107      });
108    });
109  } else if (Platform.OS === 'android') {
110    describe(`Android device tests`, () => {
111      it(`Application.getAndroidId() returns String`, () => {
112        let error = null;
113        let androidId;
114        try {
115          androidId = Application.getAndroidId();
116        } catch (e) {
117          error = e;
118        }
119        expect(androidId).toEqual(jasmine.any(String));
120        expect(error).toBeNull();
121      });
122
123      if (ExponentTest && !ExponentTest.isInCI) {
124        it(`Application.getInstallReferrerAsync() returns String`, async () => {
125          let error = null;
126          let installReferrer;
127          try {
128            installReferrer = await Application.getInstallReferrerAsync();
129          } catch (e) {
130            error = e;
131          }
132          expect(installReferrer).toEqual(jasmine.any(String));
133          expect(error).toBeNull();
134        });
135      }
136      it(`Application.getLastUpdateTimeAsync() returns String`, async () => {
137        let error = null;
138        let lastUpdateTime;
139        try {
140          lastUpdateTime = await Application.getLastUpdateTimeAsync();
141        } catch (e) {
142          error = e;
143        }
144        expect(lastUpdateTime).toEqual(jasmine.any(Date));
145        expect(error).toBeNull();
146      });
147      describe(`doesn't call iOS-only methods`, () => {
148        it(`Application.getIosIdForVendorAsync doesn't get called`, async () => {
149          let idfv;
150          let error = null;
151          try {
152            idfv = await Application.getIosIdForVendorAsync();
153          } catch (e) {
154            error = e;
155          }
156          expect(error).toBeDefined();
157          expect(idfv).toBeUndefined();
158        });
159      });
160    });
161  }
162}
163