Skip to content

Commit a4016ad

Browse files
committed
Add tests for Button and modify README
1 parent d8c62fc commit a4016ad

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,44 @@ open http://localhost:3000
1313

1414
## Components
1515

16-
### Accessible [PickList Base](http://www.lightningdesignsystem.com/components/picklists#base&role=regular&status=all) Component
16+
### [Button](https://www.lightningdesignsystem.com/components/buttons#neutral)
17+
18+
```jsx
19+
20+
<SLDSButton
21+
label='Test Button'
22+
variant='neutral'
23+
iconName='download'
24+
iconSize='small'
25+
iconPosition='left'
26+
onClick={this.handleButtonClick} />
27+
28+
Required Prop:
29+
* Only label is required
30+
31+
Optional Props:
32+
* variant must be neutral, brand, or icon (inverse, stateful, icon more, and hint coming soon)
33+
* iconSize must be small, medium, or large
34+
* iconPosition must be left or right
35+
36+
```
37+
38+
### [PickList Base](http://www.lightningdesignsystem.com/components/picklists#base&role=regular&status=all)
1739

1840
```jsx
1941

2042
import {SLDSPicklistBase} from 'design-system-react';
2143

2244
...
2345

24-
<SLDSPicklistBase
46+
<SLDSPicklistBase
2547
options={[
2648
{label:'A Option',value:'A0'},
2749
{label:'B Option',value:'B0'},
2850
{label:'C Option',value:'C0'},
2951
{label:'D Option',value:'D0'},
3052
]}
31-
value='A0'
53+
value='A0'
3254
label='Contacts'
3355
onSelect={(value)=>{
3456
console.log('selected: ',value);
@@ -42,7 +64,7 @@ import {SLDSPicklistBase} from 'design-system-react';
4264

4365
### Work in progress
4466

45-
### Accessible [DatePicker Base](http://www.lightningdesignsystem.com/components/datepickers#base) Component
67+
### [DatePicker Base](http://www.lightningdesignsystem.com/components/datepickers#base)
4668

4769
[![browser support](/readme-assets/SLDSDatePickerBase.gif)](/readme-assets/SLDSDatePickerBase.gif)
4870

@@ -58,6 +80,4 @@ npm test
5880
### Future Pipeline
5981
* Lookups
6082
* Modals
61-
* Buttons
62-
6383

components/SLDSButton/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class Button extends React.Component {
7979
return (
8080
<button className={this.getClassName()} {...props} onClick={click}>
8181

82-
<span>{this.props.iconPosition === 'right' ? this.props.label : null}</span>
82+
{this.props.iconPosition === 'right' ? this.props.label : null}
8383

8484
{this.renderIcon()}
8585

86-
<span>{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}</span>
86+
{(this.props.iconPosition === 'left' || !this.props.iconPosition) ? this.props.label : null}
8787

8888
</button>
8989
);

demo/code-snippets/SLDSButton.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

2-
3-
<SLDSButton label='Test Button' variant='neutral' iconName='download' iconSize='small' iconPosition='left' onClick={this.handleButtonClick} />
2+
<SLDSButton
3+
label='Test Button'
4+
variant='neutral'
5+
iconName='download'
6+
iconSize='small'
7+
iconPosition='left'
8+
onClick={this.handleButtonClick} />
49

510
* Only label is required
611
* variant must be neutral, brand, or icon
712
* iconSize must be small, medium, or large
813
* iconPosition must be left or right
9-

tests/SLDSButton/button.test.jsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,39 @@ const TestUtils = React.addons.TestUtils;
33
import {SLDSButton} from '../../components';
44

55
describe('SLDSButton: ', function(){
6+
7+
let sandbox, reactCmp, button;
8+
let handleClick = function() {
9+
alert('Button Clicked');
10+
};
11+
12+
beforeEach(function() {
13+
sandbox = sinon.sandbox.create();
14+
reactCmp = TestUtils.renderIntoDocument(<SLDSButton label='Test' variant='brand' icon='download' onClick={handleClick} />);
15+
button = React.findDOMNode(reactCmp);
16+
});
17+
18+
afterEach(function() {
19+
sandbox.restore();
20+
});
21+
22+
it('button renders', function() {
23+
expect(button).to.not.equal(null);
24+
});
25+
26+
it('button renders label from props', function() {
27+
let label = button.innerText;
28+
expect(label).to.equal('Test');
29+
});
30+
31+
it('button onClick invokes method from props', function() {
32+
let _savedAlert = window.alert;
33+
try {
34+
let spy = sinon.spy(window, 'alert');
35+
TestUtils.Simulate.click(button);
36+
sinon.assert.called(spy);
37+
}
38+
finally { window.alert = _savedAlert; }
39+
});
40+
641
});

0 commit comments

Comments
 (0)