1import React from 'react';
2import ReactDOM from 'react-dom';
3import ReactTestUtils from 'react-dom/test-utils';
4import ReactAudioPlayer from '../src/index.tsx';
5describe('ReactAudioPlayer', function() {
6 const song = './fixtures/turkish_march.ogg';
7 test('renders an audio element', function() {
8 const instance = ReactTestUtils.renderIntoDocument(
9 <ReactAudioPlayer />
10 );
11 const instanceEl = ReactDOM.findDOMNode(instance);
12 expect(instanceEl.tagName).toBe('AUDIO');
13 });
14 test('sets the loop attribute if provided', function() {
15 const instance = ReactTestUtils.renderIntoDocument(
16 <ReactAudioPlayer
17 src={song}
18 loop
19 />
20 );
21 const instanceEl = ReactDOM.findDOMNode(instance);
22 expect(instanceEl.getAttribute('loop')).not.toBe(null);
23 })
24 test('sets title', function() {
25 const instance = ReactTestUtils.renderIntoDocument(
26 <ReactAudioPlayer
27 src={song}
28 title="Turkish march"
29 />
30 );
31 const instanceEl = ReactDOM.findDOMNode(instance);
32 expect(instanceEl.getAttribute("title")).toBe("Turkish march");
33 })
34 test('receives all custom props', function() {
35 const instance = ReactTestUtils.renderIntoDocument(
36 <ReactAudioPlayer
37 src={song}
38 name="custom-name"
39 data-id="custom-data"
40 controlsList="nodownload"
41 />
42 );
43 const props = Object.keys(instance.props);
44 expect(props).toContain('name');
45 expect(props).toContain('data-id');
46 expect(props).toContain('controlsList');
47 });
48});