xref: /expo/apps/test-suite/tests/Application.js (revision 191a2fb0)
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      describe(`doesn't get Android-only constants`, () => {
56        it('Application.androidId is null', () => {
57          expect(Application.androidId).toBeNull();
58        });
59      });
60
61      describe(`doesn't call Android-only methods`, () => {
62        it(`Application.getLastUpdateTimeAsync() doesn't get called`, async () => {
63          let lastUpdateTime;
64          let error = null;
65          try {
66            lastUpdateTime = await Application.getLastUpdateTimeAsync();
67          } catch (e) {
68            error = e;
69          }
70          expect(error).toBeDefined();
71          expect(lastUpdateTime).toBeUndefined();
72        });
73        it(`Application.getInstallReferrerAsync() doesn't get called`, async () => {
74          let installReferrer;
75          let error = null;
76          try {
77            installReferrer = await Application.getInstallReferrerAsync();
78          } catch (e) {
79            error = e;
80          }
81          expect(error).toBeDefined();
82          expect(installReferrer).toBeUndefined();
83        });
84      });
85    });
86  } else if (Platform.OS === 'android') {
87    describe(`Android device tests`, () => {
88      it(`gets Application.androidId as a String`, () => {
89        let androidId = Application.androidId;
90
91        expect(androidId).toBeDefined();
92        expect(androidId).toEqual(jasmine.any(String));
93      });
94
95      if (ExponentTest && !ExponentTest.isInCI) {
96        it(`Application.getInstallReferrerAsync() returns String`, async () => {
97          let error = null;
98          let installReferrer;
99          try {
100            installReferrer = await Application.getInstallReferrerAsync();
101          } catch (e) {
102            error = e;
103          }
104          expect(installReferrer).toEqual(jasmine.any(String));
105          expect(error).toBeNull();
106        });
107      }
108      it(`Application.getLastUpdateTimeAsync() returns String`, async () => {
109        let error = null;
110        let lastUpdateTime;
111        try {
112          lastUpdateTime = await Application.getLastUpdateTimeAsync();
113        } catch (e) {
114          error = e;
115        }
116        expect(lastUpdateTime).toEqual(jasmine.any(Date));
117        expect(error).toBeNull();
118      });
119      describe(`doesn't call iOS-only methods`, () => {
120        it(`Application.getIosIdForVendorAsync doesn't get called`, async () => {
121          let idfv;
122          let error = null;
123          try {
124            idfv = await Application.getIosIdForVendorAsync();
125          } catch (e) {
126            error = e;
127          }
128          expect(error).toBeDefined();
129          expect(idfv).toBeUndefined();
130        });
131      });
132    });
133  }
134}
135