1import * as SMS from 'expo-sms'; 2import { Platform } from 'react-native'; 3 4import { 5 loadAttachmentsAsync, 6 cleanupAttachmentsAsync, 7 testSMSComposeWithSingleImageAttachment, 8 testSMSComposeWithAudioAttachment, 9 testSMSComposeWithTwoImageAttachments, 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 if (isInteractive()) { 21 describe(`sendSMSAsync()`, () => { 22 beforeAll(() => loadAttachmentsAsync(expect)); 23 24 it(`opens an SMS composer`, async () => { 25 await SMS.sendSMSAsync(['0123456789', '9876543210'], 'test'); 26 }); 27 28 it(`opens an SMS composer with single image attachment`, async () => { 29 await testSMSComposeWithSingleImageAttachment(expect); 30 }); 31 32 it(`opens an SMS composer with two image attachments. Only first one is used.`, async () => { 33 await testSMSComposeWithTwoImageAttachments(expect); 34 }); 35 36 it(`opens an SMS composer with audio attachment`, async () => { 37 await testSMSComposeWithAudioAttachment(expect); 38 }); 39 40 it(`throws when provided with undefined recipient`, async () => { 41 const error = await expectMethodToThrowAsync(testSMSComposeWithUndefinedRecipient); 42 expect(error.message).toBe('undefined or null address'); 43 }); 44 45 it(`throws when provided with null recipient`, async () => { 46 const error = await expectMethodToThrowAsync(testSMSComposeWithNullRecipient); 47 expect(error.message).toBe('undefined or null address'); 48 }); 49 50 afterAll(() => cleanupAttachmentsAsync(expect)); 51 }); 52 } 53 54 describe(`isAvailableAsync()`, () => { 55 if (Platform.OS === 'android' && isInteractive()) { 56 // TODO(Bacon): Not sure if this works in an emulator or not 57 it(`has a telephony radio with data communication support`, async () => { 58 expect(await SMS.isAvailableAsync()).toBe(true); 59 }); 60 } else { 61 it(`is not supported on ${Platform.OS}`, async () => { 62 expect(await SMS.isAvailableAsync()).toBe(false); 63 }); 64 } 65 }); 66 }); 67} 68