Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Commit 5b23d43

Browse files
larrylin28facebook-github-bot
authored andcommitted
Add unit test for setSource of Video
Summary: The logic of getting supported video format from video source is a little complicated, add a unit test for this. Reviewed By: mikearmstrong001 Differential Revision: D4954548 fbshipit-source-id: 2451bfb
1 parent 39852bc commit 5b23d43

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)