xref: /expo/apps/test-suite/tests/SMS.js (revision bb8f4f99)
1import * as SMS from 'expo-sms';
2import { Platform } from 'react-native';
3
4import { isInteractive } from '../utils/Environment';
5import {
6  loadAttachmentsAsync,
7  cleanupAttachmentsAsync,
8  testSMSComposeWithSingleImageAttachment,
9  testSMSComposeWithAudioAttachment,
10  testSMSComposeWithTwoImageAttachments,
11} from './SMSCommon';
12
13export const name = 'SMS';
14
15export function test({ describe, it, expect, beforeAll, afterAll }) {
16  describe('SMS', () => {
17    if (isInteractive()) {
18      describe(`sendSMSAsync()`, () => {
19        beforeAll(() => loadAttachmentsAsync(expect));
20
21        it(`opens an SMS composer`, async () => {
22          await SMS.sendSMSAsync(['0123456789', '9876543210'], 'test');
23        });
24
25        it(`opens an SMS composer with single image attachment`, async () => {
26          await testSMSComposeWithSingleImageAttachment(expect);
27        });
28
29        it(`opens an SMS composer with two image attachments. Only first one is used.`, async () => {
30          await testSMSComposeWithTwoImageAttachments(expect);
31        });
32
33        it(`opens an SMS composer with audio attachment`, async () => {
34          await testSMSComposeWithAudioAttachment(expect);
35        });
36
37        afterAll(() => cleanupAttachmentsAsync(expect));
38      });
39    }
40
41    describe(`isAvailableAsync()`, () => {
42      if (Platform.OS === 'android' && isInteractive()) {
43        // TODO(Bacon): Not sure if this works in an emulator or not
44        it(`has a telephony radio with data communication support`, async () => {
45          expect(await SMS.isAvailableAsync()).toBe(true);
46        });
47      } else {
48        it(`is not supported on ${Platform.OS}`, async () => {
49          expect(await SMS.isAvailableAsync()).toBe(false);
50        });
51      }
52    });
53  });
54}
55