-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Steven Locke <slocke@pivotal.io>
- Loading branch information
Ming Xiao
authored and
Steven Locke
committed
May 7, 2018
1 parent
aa7e081
commit 7a17c25
Showing
5 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import '../spec_helper'; | ||
import {ProgressBar} from '../../../src/react/progress-bar'; | ||
|
||
describe('ProgressBar', () => { | ||
let subject; | ||
|
||
beforeEach(() => { | ||
subject = ReactDOM.render(<ProgressBar/>, root); | ||
}); | ||
|
||
it('renders a progress background div', () => { | ||
expect('.pui-progress').toExist(); | ||
}); | ||
|
||
it('renders a progress foreground div', () => { | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('role', 'progressbar'); | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('aria-valuemax', '100'); | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('aria-valuemin', '0'); | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('aria-valuenow', '0'); | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('style', 'width: 0%;'); | ||
}); | ||
|
||
describe('when given a className', () => { | ||
beforeEach(() => { | ||
subject::setProps({className: 'custom-class'}); | ||
}); | ||
|
||
it('applies the class to the outer div', () => { | ||
expect('.pui-progress').toHaveClass('custom-class'); | ||
}); | ||
}); | ||
|
||
describe('when given a barClassName', () => { | ||
beforeEach(() => { | ||
subject::setProps({barClassName: 'custom-bar-class'}); | ||
}); | ||
|
||
it('applies the class to the progress bar', () => { | ||
expect('.pui-progress .pui-progress-bar').toHaveClass('custom-bar-class'); | ||
}); | ||
}); | ||
|
||
describe('when given a value', () => { | ||
beforeEach(() => { | ||
subject::setProps({value: 78}); | ||
}); | ||
|
||
it('sets the attributes of the progress bar accordingly', () => { | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('aria-valuenow', '78'); | ||
expect('.pui-progress .pui-progress-bar').toHaveAttr('style', 'width: 78%;'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
try { | ||
require('../common'); | ||
require('./progress-bars.css'); | ||
} catch(e) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {ProgressBar} from './progress-bar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export class ProgressBar extends React.Component { | ||
static propTypes = { | ||
barClassName: PropTypes.string, | ||
value: PropTypes.number.isRequired | ||
}; | ||
|
||
static defaultProps = { | ||
value: 0 | ||
}; | ||
|
||
componentDidMount() { | ||
require('../../css/progress-bars'); | ||
} | ||
|
||
render() { | ||
const {barClassName, className, value} = this.props; | ||
return ( | ||
<div {...{className: classnames('pui-progress', className)}}> | ||
<div {...{ | ||
className: classnames('pui-progress-bar', barClassName), | ||
role: 'progressbar', | ||
'aria-valuemax': 100, | ||
'aria-valuemin': 0, | ||
'aria-valuenow': value, | ||
style: {width: `${value}%`} | ||
}}/> | ||
</div> | ||
); | ||
} | ||
} |