@@ -4,38 +4,72 @@ import {SLDSButton} from '../../components';
4
4
5
5
describe ( 'SLDSButton: ' , function ( ) {
6
6
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 ) ;
10
10
} ;
11
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 ) ;
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
+ } ) ;
16
17
} ) ;
17
18
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
+ } ) ;
21
25
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
+ } ) ;
25
58
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
+ } ) ;
29
64
} ) ;
30
65
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 } /> ) ;
35
70
TestUtils . Simulate . click ( button ) ;
36
- sinon . assert . called ( spy ) ;
37
- }
38
- finally { window . alert = _savedAlert ; }
71
+ expect ( onClick . calledOnce ) . to . be . true ;
72
+ } ) ;
39
73
} ) ;
40
74
41
75
} ) ;
0 commit comments