Skip to content

Commit b0c0d84

Browse files
committed
Creating a progress bar
1 parent e9e9ac9 commit b0c0d84

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

app/components/Progress.jsx

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

test/components/Progress.js

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

0 commit comments

Comments
 (0)