|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +jest |
| 13 | + .dontMock('../RCTVideoPlayer') |
| 14 | + .mock('../../Video/getSupportedFormats', () => () => ['mp4', 'mkv']); |
| 15 | + |
| 16 | +const RCTVideoPlayer = require('../RCTVideoPlayer').default; |
| 17 | +const rnctx = { |
| 18 | + VideoModule: { |
| 19 | + _addMediaEventListener: jest.fn(), |
| 20 | + addHandle: jest.fn(), |
| 21 | + setUrl: jest.fn(), |
| 22 | + setMetaData: jest.fn(), |
| 23 | + load: jest.fn(), |
| 24 | + unload: jest.fn(), |
| 25 | + setMuted: jest.fn(), |
| 26 | + setVolume: jest.fn(), |
| 27 | + }, |
| 28 | +}; |
| 29 | + |
| 30 | +describe('RCTVideoPlayer', () => { |
| 31 | + it('set source to null', () => { |
| 32 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 33 | + player.setSource({uri: '1.mp4'}); |
| 34 | + player.setSource(null); |
| 35 | + expect(player._source).toEqual(null); |
| 36 | + }); |
| 37 | + |
| 38 | + it('set source to an empty array', () => { |
| 39 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 40 | + player.setSource([]); |
| 41 | + expect(player._source).toEqual(null); |
| 42 | + }); |
| 43 | + |
| 44 | + it('set source to a valid source', () => { |
| 45 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 46 | + player.setSource({uri: '1.mp4'}); |
| 47 | + expect(player._source).toEqual({uri: '1.mp4'}); |
| 48 | + }); |
| 49 | + |
| 50 | + it('choose supported formats from source', () => { |
| 51 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 52 | + player.setSource([{uri: '1.webm', format: 'webm'}, null, {uri: '1.mp4', format: 'mp4'}]); |
| 53 | + expect(player._source).toEqual({uri: '1.mp4', format: 'mp4'}); |
| 54 | + }); |
| 55 | + |
| 56 | + it('order of choosing supported formats from source', () => { |
| 57 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 58 | + player.setSource([ |
| 59 | + {uri: '1.mkv', format: 'mkv', layout: 'SPHERE'}, |
| 60 | + {uri: '1.mp4', format: 'mp4'}, |
| 61 | + ]); |
| 62 | + expect(player._source).toEqual({uri: '1.mkv', format: 'mkv', layout: 'SPHERE'}); |
| 63 | + }); |
| 64 | + |
| 65 | + it('none of the formats from source is supported', () => { |
| 66 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 67 | + player.setSource([{uri: '1.webm', format: 'webm'}, {uri: '1.ogg', format: 'ogg'}]); |
| 68 | + expect(player._source).toEqual(null); |
| 69 | + }); |
| 70 | + |
| 71 | + it('one of the source has not specify the format', () => { |
| 72 | + const player = new RCTVideoPlayer(rnctx, ''); |
| 73 | + player.setSource([{uri: '1.webm', format: 'webm'}, {uri: '1.mov'}]); |
| 74 | + expect(player._source).toEqual({uri: '1.mov'}); |
| 75 | + }); |
| 76 | +}); |
0 commit comments