Skip to content

Commit e09ed0e

Browse files
committed
Time control
1 parent 52498ba commit e09ed0e

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

src/DefaultPlayer/DefaultPlayer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import PlayPause from './PlayPause/PlayPause';
1313
import Seek from './Seek/Seek';
1414
import Volume from './Volume/Volume';
1515
import ErrorMessage from './ErrorMessage/ErrorMessage';
16+
import Time from './Time/Time';
1617

1718
const DefaultPlayer = ({
1819
video,
@@ -49,6 +50,7 @@ const DefaultPlayer = ({
4950
className={styles.seek}
5051
setCurrentTime={setCurrentTime}
5152
{...video} />
53+
<Time {...video} />
5254
<Volume
5355
setVolume={setVolume}
5456
toggleMute={toggleMute}

src/DefaultPlayer/Time/Time.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.component {
22
padding: 0 10px 0 10px;
3-
line-height: 34px;
3+
line-height: 35px;
44
color: #fff;
55
}
66

src/DefaultPlayer/Time/Time.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from './Time.css';
33

44
const formatTime = (seconds) => {
55
const date = new Date(Date.UTC(1970,1,1,0,0,0,0));
6-
seconds = isNaN(seconds)
6+
seconds = isNaN(seconds) || seconds > 86400
77
? 0
88
: Math.floor(seconds);
99
date.setSeconds(seconds);

src/DefaultPlayer/Time/Time.test.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import Time from './Time';
4+
import styles from './Time.css';
5+
6+
describe('Time', () => {
7+
let component;
8+
9+
beforeAll(() => {
10+
component = shallow(<Time />);
11+
});
12+
13+
it('should accept a className prop and append it to the components class', () => {
14+
const newClassNameString = 'a new className';
15+
expect(component.prop('className'))
16+
.toContain(styles.component);
17+
component.setProps({
18+
className: newClassNameString
19+
});
20+
expect(component.prop('className'))
21+
.toContain(styles.component);
22+
expect(component.prop('className'))
23+
.toContain(newClassNameString);
24+
});
25+
26+
it('shows video duration', () => {
27+
component.setProps({
28+
duration: 10
29+
});
30+
expect(component.find(`.${styles.duration}`).text())
31+
.toEqual('00:00:10');
32+
});
33+
34+
it('shows current video elapsed time', () => {
35+
component.setProps({
36+
currentTime: 10
37+
});
38+
expect(component.find(`.${styles.current}`).text())
39+
.toEqual('00:00:10');
40+
});
41+
42+
it('can handle minutes, hours and seconds', () => {
43+
component.setProps({
44+
currentTime: 60 * 2
45+
});
46+
expect(component.find(`.${styles.current}`).text())
47+
.toEqual('00:02:00');
48+
49+
component.setProps({
50+
currentTime: 60 * 60 * 3
51+
});
52+
expect(component.find(`.${styles.current}`).text())
53+
.toEqual('03:00:00');
54+
55+
component.setProps({
56+
currentTime: 60 * 60 * 3 + 72
57+
});
58+
expect(component.find(`.${styles.current}`).text())
59+
.toEqual('03:01:12');
60+
});
61+
62+
it('fails gracefully and shows 00:00:00 when video is greater than 24 hours', () => {
63+
// Who has a video longer than 24 hours? If this ever occurs then we
64+
// should consider adding it.
65+
component.setProps({
66+
currentTime: 86401
67+
});
68+
expect(component.find(`.${styles.current}`).text())
69+
.toEqual('00:00:00');
70+
71+
component.setProps({
72+
currentTime: 86400
73+
});
74+
expect(component.find(`.${styles.current}`).text())
75+
.toEqual('00:00:00');
76+
});
77+
78+
it('fails gracefully and shows 00:00:00 when not given a number', () => {
79+
component.setProps({
80+
currentTime: null
81+
});
82+
expect(component.find(`.${styles.current}`).text())
83+
.toEqual('00:00:00');
84+
85+
component.setProps({
86+
currentTime: undefined
87+
});
88+
expect(component.find(`.${styles.current}`).text())
89+
.toEqual('00:00:00');
90+
});
91+
});

0 commit comments

Comments
 (0)