xref: /expo/apps/test-suite/tests/SMS.ios.js (revision 8a424beb)
1import * as Device from 'expo-device';
2import * as SMS from 'expo-sms';
3
4import {
5  loadAttachmentsAsync,
6  cleanupAttachmentsAsync,
7  testSMSComposeWithSingleImageAttachment,
8  testSMSComposeWithTwoImageAttachments,
9  testSMSComposeWithAudioAttachment,
10  testSMSComposeWithNullRecipient,
11  testSMSComposeWithUndefinedRecipient,
12} from './SMSCommon';
13import { expectMethodToThrowAsync } from '../TestUtils';
14import { isInteractive } from '../utils/Environment';
15
16export const name = 'SMS';
17
18export function test({ describe, it, expect, beforeAll, afterAll }) {
19  describe('SMS', () => {
20    describe(`sendSMSAsync()`, () => {
21      if (Device.isDevice) {
22        if (isInteractive()) {
23          beforeAll(() => loadAttachmentsAsync(expect));
24
25          it(`opens an SMS composer`, async () => {
26            // TODO: Bacon: Build an API to close the UI Controller
27            await SMS.sendSMSAsync(['0123456789', '9876543210'], 'test');
28          });
29
30          it(`opens an SMS composer with single image attachment`, async () => {
31            await testSMSComposeWithSingleImageAttachment(expect);
32          });
33
34          it(`opens an SMS composer with two image attachments`, async () => {
35            await testSMSComposeWithTwoImageAttachments(expect);
36          });
37
38          it(`opens an SMS composer with audio attachment`, async () => {
39            await testSMSComposeWithAudioAttachment(expect);
40          });
41
42          it(`throws when provided with undefined recipient`, async () => {
43            const error = await expectMethodToThrowAsync(testSMSComposeWithUndefinedRecipient);
44            expect(error.message).toBe('undefined or null address');
45          });
46
47          it(`throws when provided with null recipient`, async () => {
48            const error = await expectMethodToThrowAsync(testSMSComposeWithNullRecipient);
49            expect(error.message).toBe('undefined or null address');
50          });
51
52          afterAll(() => cleanupAttachmentsAsync(expect));
53        }
54      } else {
55        it(`is unavailable`, async () => {
56          expect(await SMS.isAvailableAsync()).toBe(false);
57        });
58      }
59    });
60
61    describe(`isAvailableAsync()`, () => {
62      if (Device.isDevice) {
63        it(`has access to iOS SMS API`, async () => {
64          expect(await SMS.isAvailableAsync()).toBe(true);
65        });
66      } else {
67        it(`cannot be used in the iOS simulator`, async () => {
68          expect(await SMS.isAvailableAsync()).toBe(false);
69        });
70      }
71    });
72  });
73}
74