Skip to content

Commit 45c22cb

Browse files
committed
Merge pull request #15 from salesforce-ux/button
Add more button tests
2 parents a2bc9a7 + 63536c9 commit 45c22cb

File tree

1 file changed

+57
-23
lines changed

1 file changed

+57
-23
lines changed

tests/SLDSButton/button.test.jsx

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,72 @@ import {SLDSButton} from '../../components';
44

55
describe('SLDSButton: ', function(){
66

7-
let sandbox, reactCmp, button;
8-
let handleClick = function() {
9-
alert('Button Clicked');
7+
let generateButton = function(buttonInstance) {
8+
let reactCmp = TestUtils.renderIntoDocument(buttonInstance);
9+
return React.findDOMNode(reactCmp);
1010
};
1111

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);
12+
describe('component renders', function() {
13+
it('button renders', function() {
14+
let button = generateButton(<SLDSButton label='Test' />);
15+
expect(button).to.not.equal(undefined);
16+
});
1617
});
1718

18-
afterEach(function() {
19-
sandbox.restore();
20-
});
19+
describe('component basic props render', function() {
20+
it('renders label', function() {
21+
let button = generateButton(<SLDSButton label='Test' />);
22+
let label = button.innerText;
23+
expect(label).to.equal('Test');
24+
});
2125

22-
it('button renders', function() {
23-
expect(button).to.not.equal(null);
24-
});
26+
it('renders hidden label with icon only button', function() {
27+
let button = generateButton(<SLDSButton label='Settings' variant='icon' iconName='settings' />);
28+
let label = button.innerText;
29+
expect(label).to.equal('Settings');
30+
});
31+
32+
it('renders variant', function() {
33+
let button = TestUtils.renderIntoDocument(<SLDSButton label='Test' variant='brand' />);
34+
let brand = TestUtils.findRenderedDOMComponentWithClass(button, 'slds-button--brand');
35+
expect(brand).to.not.equal(undefined);
36+
});
37+
})
38+
39+
40+
describe('component icon props render', function() {
41+
it('renders icon svg', function() {
42+
let button = generateButton(<SLDSButton label='Test' iconName='download' />);
43+
let svg = button.getElementsByClassName("slds-button__icon")[0];
44+
expect(svg).to.not.equal(undefined);
45+
});
46+
47+
it('renders icon size', function() {
48+
let button = generateButton(<SLDSButton label='Test' iconName='download' iconSize='small' />);
49+
let size = button.getElementsByClassName("slds-button__icon--small")[0];
50+
expect(size).to.not.equal(undefined);
51+
});
52+
53+
it('without prop specified, renders icon position on left side', function() {
54+
let button = generateButton(<SLDSButton label='Test' iconName='download' />);
55+
let position = button.getElementsByClassName("slds-button__icon--left")[0];
56+
expect(position).to.not.equal(undefined);
57+
});
2558

26-
it('button renders label from props', function() {
27-
let label = button.innerText;
28-
expect(label).to.equal('Test');
59+
it('renders icon position', function() {
60+
let button = generateButton(<SLDSButton label='Test' iconName='download' iconPosition='right' />);
61+
let position = button.getElementsByClassName("slds-button__icon--right")[0];
62+
expect(position).to.not.equal(undefined);
63+
});
2964
});
3065

31-
it('button onClick invokes method from props', function() {
32-
let _savedAlert = window.alert;
33-
try {
34-
let spy = sinon.spy(window, 'alert');
66+
describe('component behavior works', function() {
67+
it('button onClick invokes method from props', function() {
68+
let onClick = sinon.spy();
69+
let button = generateButton(<SLDSButton label='Test' onClick={onClick} />);
3570
TestUtils.Simulate.click(button);
36-
sinon.assert.called(spy);
37-
}
38-
finally { window.alert = _savedAlert; }
71+
expect(onClick.calledOnce).to.be.true;
72+
});
3973
});
4074

4175
});

0 commit comments

Comments
 (0)