@@ -13,29 +13,39 @@ describe('SLDSLookup: ', function(){
13
13
{ label :'Acme Construction' }
14
14
] ;
15
15
16
- let generateLookup = function ( lookupInstance ) {
16
+ const generateLookup = function ( lookupInstance ) {
17
17
let reactCmp = TestUtils . renderIntoDocument ( lookupInstance ) ;
18
18
return React . findDOMNode ( reactCmp ) ;
19
19
} ;
20
20
21
+ const getLookup = function ( withHeader ) {
22
+ return < SLDSLookup
23
+ items = { items }
24
+ label = "Leads"
25
+ type = "lead"
26
+ headerRenderer = { withHeader ?SLDSLookup . DefaultHeader :null }
27
+ footerRenderer = { SLDSLookup . DefaultFooter }
28
+ /> ;
29
+ } ;
30
+
21
31
describe ( 'component renders' , function ( ) {
22
32
it ( 'lookup renders' , function ( ) {
23
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
33
+ let lookup = generateLookup ( getLookup ( ) ) ;
24
34
expect ( lookup ) . to . not . equal ( undefined ) ;
25
35
} ) ;
26
36
} ) ;
27
37
28
38
describe ( 'component basic props render' , function ( ) {
29
39
it ( 'renders label' , function ( ) {
30
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
40
+ let lookup = generateLookup ( getLookup ( ) ) ;
31
41
let label = lookup . getElementsByTagName ( "label" ) [ 0 ] ;
32
42
expect ( label . innerText ) . to . equal ( 'Leads' ) ;
33
43
} ) ;
34
44
} ) ;
35
45
36
46
describe ( 'accessibility markup passes' , function ( ) {
37
47
it ( 'label for matches input id' , function ( ) {
38
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
48
+ let lookup = generateLookup ( getLookup ( ) ) ;
39
49
let labelFor = lookup . getElementsByTagName ( "label" ) [ 0 ] . getAttribute ( "for" ) ;
40
50
let inputId = lookup . getElementsByTagName ( "input" ) [ 0 ] . getAttribute ( "id" ) ;
41
51
expect ( labelFor ) . to . equal ( inputId ) ;
@@ -45,18 +55,18 @@ describe('SLDSLookup: ', function(){
45
55
46
56
describe ( 'accessibility aria attributes pass' , function ( ) {
47
57
it ( 'aria-haspopup is true' , function ( ) {
48
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
58
+ let lookup = generateLookup ( getLookup ( ) ) ;
49
59
let ariaHaspopup = lookup . getElementsByTagName ( "input" ) [ 0 ] . getAttribute ( "aria-haspopup" ) ;
50
60
expect ( ariaHaspopup ) . to . equal ( 'true' ) ;
51
61
} ) ;
52
62
it ( 'aria-expanded is false initally' , function ( ) {
53
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
63
+ let lookup = generateLookup ( getLookup ( ) ) ;
54
64
let ariaExpanded = lookup . getElementsByTagName ( "input" ) [ 0 ] . getAttribute ( "aria-expanded" ) ;
55
65
expect ( ariaExpanded ) . to . equal ( 'false' ) ;
56
66
} ) ;
57
67
58
68
it ( 'aria-expanded is true when clicking on input field' , function ( ) {
59
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
69
+ let lookup = generateLookup ( getLookup ( ) ) ;
60
70
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
61
71
TestUtils . Simulate . click ( input ) ;
62
72
let ariaExpanded = lookup . getElementsByTagName ( "input" ) [ 0 ] . getAttribute ( "aria-expanded" ) ;
@@ -68,7 +78,7 @@ describe('SLDSLookup: ', function(){
68
78
describe ( 'selecting item works' , function ( ) {
69
79
70
80
it ( 'no fixed header: focuses correct item' , function ( ) {
71
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
81
+ let lookup = generateLookup ( getLookup ( ) ) ;
72
82
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
73
83
TestUtils . Simulate . click ( input ) ;
74
84
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
@@ -78,7 +88,7 @@ describe('SLDSLookup: ', function(){
78
88
} ) ;
79
89
80
90
it ( 'with fixed header: focuses correct item' , function ( ) {
81
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" header = { < div > header </ div > } /> ) ;
91
+ let lookup = generateLookup ( getLookup ( true ) ) ;
82
92
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
83
93
TestUtils . Simulate . click ( input ) ;
84
94
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
@@ -88,7 +98,7 @@ describe('SLDSLookup: ', function(){
88
98
} ) ;
89
99
90
100
it ( 'selects correct item' , function ( ) {
91
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
101
+ let lookup = generateLookup ( getLookup ( ) ) ;
92
102
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
93
103
TestUtils . Simulate . click ( input ) ;
94
104
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
@@ -100,7 +110,7 @@ describe('SLDSLookup: ', function(){
100
110
} ) ;
101
111
102
112
it ( 'closes lookup menu on esc' , function ( ) {
103
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
113
+ let lookup = generateLookup ( getLookup ( ) ) ;
104
114
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
105
115
TestUtils . Simulate . click ( input ) ;
106
116
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
@@ -110,7 +120,7 @@ describe('SLDSLookup: ', function(){
110
120
} ) ;
111
121
112
122
it ( 'aria-expanded is false after selecting item' , function ( ) {
113
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
123
+ let lookup = generateLookup ( getLookup ( ) ) ;
114
124
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
115
125
TestUtils . Simulate . click ( input ) ;
116
126
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
@@ -119,13 +129,14 @@ describe('SLDSLookup: ', function(){
119
129
} ) ;
120
130
121
131
it ( 'aria-expanded is false after selecting item' , function ( ) {
122
- let lookup = generateLookup ( < SLDSLookup items = { items } label = "Leads" type = "lead" /> ) ;
132
+ let lookup = generateLookup ( getLookup ( ) ) ;
123
133
let input = lookup . getElementsByTagName ( "input" ) [ 0 ] ;
124
134
TestUtils . Simulate . click ( input ) ;
125
135
TestUtils . Simulate . keyDown ( input , { key : "Down" , keyCode : 40 , which : 40 } ) ;
126
136
let focusedItem = lookup . getElementsByTagName ( "ul" ) [ 0 ] . getElementsByTagName ( 'li' ) [ 0 ] ;
127
137
expect ( focusedItem . className ) . to . have . string ( 'slds-theme--shade' ) ;
128
138
} ) ;
139
+
129
140
} ) ;
130
141
131
142
} ) ;
0 commit comments