File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ import React , { Component } from 'react' ;
4
+
5
+ function workOutProgressValue ( duration , currentTime ) {
6
+ const difference = ( duration - currentTime ) ;
7
+ const remainingTime = ( duration - difference ) ;
8
+ const progressPercentage = ( remainingTime / duration ) * 100 ;
9
+
10
+ return Math . ceil ( progressPercentage ) ;
11
+ }
12
+
13
+ class Progress extends Component {
14
+
15
+ render ( ) {
16
+ const progress = workOutProgressValue ( this . props . duration , this . props . currentTime ) ;
17
+
18
+ return ( < progress value = { progress } max = { this . props . max } > </ progress > ) ;
19
+ }
20
+ }
21
+
22
+ Progress . defaultProps = {
23
+ max : 100
24
+ } ;
25
+
26
+ Progress . propTypes = {
27
+ duration : React . PropTypes . number ,
28
+ currentTime : React . PropTypes . number ,
29
+ max : React . PropTypes . number
30
+ } ;
31
+
32
+ export default Progress ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ import React from 'react' ;
4
+ import assert from 'assert' ;
5
+ import { shallow } from 'enzyme' ;
6
+
7
+ import Progress from '../../app/components/Progress.jsx' ;
8
+
9
+ describe ( '<Progress />' , ( ) => {
10
+ it ( 'adds 100 as the max value on the progress element' , ( ) => {
11
+ const wrapper = shallow (
12
+ < Progress />
13
+ ) ;
14
+
15
+ assert . equal ( wrapper . find ( 'progress' ) . prop ( 'max' ) , 100 ) ;
16
+ } ) ;
17
+
18
+ it ( 'adds 35 as the value on the progress tag' , ( ) => {
19
+ const currentTime = 666 ;
20
+ const duration = 2000 ;
21
+ const wrapper = shallow (
22
+ < Progress currentTime = { currentTime } duration = { duration } />
23
+ ) ;
24
+
25
+ assert . equal ( wrapper . find ( 'progress' ) . prop ( 'value' ) , 34 ) ;
26
+ } ) ;
27
+ } ) ;
You can’t perform that action at this time.
0 commit comments