'use strict'; import { Asset } from 'expo-asset'; import { Video, VideoFullscreenUpdate } from 'expo-av'; import { forEach } from 'lodash'; import React from 'react'; import { Platform } from 'react-native'; import { waitFor, retryForStatus, mountAndWaitFor as originalMountAndWaitFor } from './helpers'; export const name = 'Video'; const imageRemoteSource = { uri: 'http://via.placeholder.com/350x150' }; const videoRemoteSource = { uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4' }; const redirectingVideoRemoteSource = { uri: 'http://bit.ly/2mcW40Q' }; const mp4Source = require('../assets/big_buck_bunny.mp4'); const hlsStreamUri = 'http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8'; const hlsStreamUriWithRedirect = 'http://bit.ly/1iy90bn'; let source = null; // Local URI of the downloaded default source is set in a beforeAll callback. let portraitVideoSource = null; let imageSource = null; let webmSource = null; const style = { width: 200, height: 200 }; export function test(t, { setPortalChild, cleanupPortal }) { t.describe('Video', () => { t.beforeAll(async () => { const mp4Asset = Asset.fromModule(mp4Source); await mp4Asset.downloadAsync(); source = { uri: mp4Asset.localUri }; const portraitAsset = Asset.fromModule(require('../assets/portrait_video.mp4')); await portraitAsset.downloadAsync(); portraitVideoSource = { uri: portraitAsset.localUri }; const imageAsset = Asset.fromModule(require('../assets/black-128x256.png')); await imageAsset.downloadAsync(); imageSource = { uri: imageAsset.localUri }; const webmAsset = Asset.fromModule(require('../assets/unsupported_bunny.webm')); await webmAsset.downloadAsync(); webmSource = { uri: webmAsset.localUri }; }); let instance = null; const refSetter = (ref) => { instance = ref; }; t.afterEach(async () => { instance = null; await cleanupPortal(); }); const mountAndWaitFor = (child, propName = 'onLoad') => originalMountAndWaitFor(child, propName, setPortalChild); const testPropValues = (propName, values, moreTests) => t.describe(`Video.props.${propName}`, () => { forEach(values, (value) => t.it(`sets it to \`${value}\``, async () => { let instance = null; const refSetter = (ref) => { instance = ref; }; const element = React.createElement(Video, { style, source, ref: refSetter, [propName]: value, }); await mountAndWaitFor(element, 'onLoad'); await retryForStatus(instance, { [propName]: value }); }) ); if (moreTests) { moreTests(); } }); const testNoCrash = (propName, values) => t.describe(`Video.props.${propName}`, () => { forEach(values, (value) => t.it(`setting to \`${value}\` doesn't crash`, async () => { const element = React.createElement(Video, { style, source, [propName]: value }); await mountAndWaitFor(element, 'onLoad'); }) ); }); const testPropSetter = (propName, propSetter, values, moreTests) => t.describe(`Video.${propSetter}`, () => { forEach(values, (value) => t.it(`sets it to \`${value}\``, async () => { let instance = null; const refSetter = (ref) => { instance = ref; }; const element = React.createElement(Video, { style, source, ref: refSetter, [propName]: value, }); await mountAndWaitFor(element); await instance[propSetter](value); const status = await instance.getStatusAsync(); t.expect(status).toEqual(t.jasmine.objectContaining({ [propName]: value })); }) ); if (moreTests) { moreTests(); } }); t.describe('Video.props.onLoadStart', () => { t.it('gets called when the source starts loading', async () => { await mountAndWaitFor(