@@ -94,17 +94,18 @@ describe('SearchWithin', function () {
94
94
} ) ;
95
95
96
96
it ( 'searchfield and picker are labelled correctly' , function ( ) {
97
- let { getByRole, getAllByText} = renderSearchWithin ( ) ;
97
+ let { getByRole, getAllByText, getByText } = renderSearchWithin ( ) ;
98
98
99
99
let searchfield = getByRole ( 'searchbox' ) ;
100
100
let picker = getByRole ( 'button' ) ;
101
101
let group = getByRole ( 'group' ) ;
102
+ let hiddenLabel = getByText ( 'Search within' ) ;
102
103
triggerPress ( picker ) ;
103
104
104
105
let listbox = getByRole ( 'listbox' ) ;
105
106
let label = getAllByText ( 'Test' ) [ 0 ] ;
106
- expect ( listbox ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ picker . id } ` ) ;
107
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
107
+ expect ( listbox ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ hiddenLabel . id } ` ) ;
108
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ hiddenLabel . id } ${ picker . id } ` ) ;
108
109
expect ( group ) . toHaveAttribute ( 'aria-labelledby' , label . id ) ;
109
110
} ) ;
110
111
@@ -135,7 +136,7 @@ describe('SearchWithin', function () {
135
136
} ) ;
136
137
137
138
it ( 'slot props override props provided to children' , function ( ) {
138
- let { getByRole, getAllByText} = renderSearchWithin (
139
+ let { getByRole, getAllByText, getByText } = renderSearchWithin (
139
140
{ isDisabled : true , isRequired : false , label : 'Test1' } ,
140
141
{ isDisabled : false , isRequired : true , label : 'Test2' , isQuiet : true } ,
141
142
{ isDisabled : false , isRequired : true , label : 'Test3' , isQuiet : true }
@@ -144,6 +145,7 @@ describe('SearchWithin', function () {
144
145
let searchfield = getByRole ( 'searchbox' ) ;
145
146
let picker = getByRole ( 'button' ) ;
146
147
let group = getByRole ( 'group' ) ;
148
+ let hiddenLabel = getByText ( 'Search within' ) ;
147
149
triggerPress ( picker ) ;
148
150
let label = getAllByText ( 'Test1' ) [ 0 ] ;
149
151
@@ -152,7 +154,7 @@ describe('SearchWithin', function () {
152
154
153
155
expect ( searchfield ) . not . toHaveAttribute ( 'aria-required' ) ;
154
156
155
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
157
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ hiddenLabel . id } ${ picker . id } ` ) ;
156
158
expect ( group ) . toHaveAttribute ( 'aria-labelledby' , label . id ) ;
157
159
158
160
expect ( searchfield . classList . contains ( 'is-quiet' ) ) . toBeFalsy ( ) ;
@@ -162,17 +164,18 @@ describe('SearchWithin', function () {
162
164
163
165
describe ( 'SearchWithin labeling' , function ( ) {
164
166
it ( 'no label - default' , function ( ) {
165
- let { getByRole} = renderSearchWithin ( { label : undefined } ) ;
167
+ let { getByRole, getByText } = renderSearchWithin ( { label : undefined } ) ;
166
168
167
169
let group = getByRole ( 'group' ) ;
168
170
let searchfield = getByRole ( 'searchbox' ) ;
169
171
let picker = getByRole ( 'button' ) ;
172
+ let hiddenLabel = getByText ( 'Search within' ) ;
170
173
171
174
expect ( group ) . toHaveAttribute ( 'aria-label' , 'Search' ) ;
172
175
173
176
expect ( group ) . not . toHaveAttribute ( 'aria-labelledby' ) ;
174
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
175
- expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
177
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ hiddenLabel . id } ${ picker . id } ` ) ;
178
+ expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ hiddenLabel . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
176
179
} ) ;
177
180
178
181
it ( 'label = foo' , function ( ) {
@@ -182,32 +185,34 @@ describe('SearchWithin labeling', function () {
182
185
let searchfield = getByRole ( 'searchbox' ) ;
183
186
let picker = getByRole ( 'button' ) ;
184
187
let label = getByText ( 'foo' ) ;
188
+ let hiddenLabel = getByText ( 'Search within' ) ;
185
189
186
190
expect ( group ) . not . toHaveAttribute ( 'aria-label' ) ;
187
191
188
192
expect ( group ) . toHaveAttribute ( 'aria-labelledby' , label . id ) ;
189
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
190
- expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
193
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ hiddenLabel . id } ${ picker . id } ` ) ;
194
+ expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ label . id } ${ hiddenLabel . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
191
195
192
196
expect ( label ) . toHaveAttribute ( 'for' , searchfield . id ) ;
193
197
} ) ;
194
198
195
199
it ( 'aria-label = bar' , function ( ) {
196
- let { getByRole} = renderSearchWithin ( { 'aria-label' : 'bar' , label : undefined } ) ;
200
+ let { getByRole, getByText } = renderSearchWithin ( { 'aria-label' : 'bar' , label : undefined } ) ;
197
201
198
202
let group = getByRole ( 'group' ) ;
199
203
let searchfield = getByRole ( 'searchbox' ) ;
200
204
let picker = getByRole ( 'button' ) ;
205
+ let hiddenLabel = getByText ( 'Search within' ) ;
201
206
202
207
expect ( group ) . toHaveAttribute ( 'aria-label' , 'bar' ) ;
203
208
204
209
expect ( group ) . not . toHaveAttribute ( 'aria-labelledby' ) ;
205
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ group . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
206
- expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ group . id } ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
210
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `${ group . id } ${ hiddenLabel . id } ${ picker . id } ` ) ;
211
+ expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `${ group . id } ${ hiddenLabel . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
207
212
} ) ;
208
213
209
214
it ( 'aria-labelledby = {id}' , function ( ) {
210
- let { getByRole} = render (
215
+ let { getByRole, debug , getByText } = render (
211
216
< Provider theme = { theme } >
212
217
< label id = "id-foo-label" htmlFor = "id-searchfield" >
213
218
Foo
@@ -223,16 +228,18 @@ describe('SearchWithin labeling', function () {
223
228
</ SearchWithin >
224
229
</ Provider >
225
230
) ;
231
+ debug ( ) ;
226
232
227
233
let group = getByRole ( 'group' ) ;
228
234
let searchfield = getByRole ( 'searchbox' ) ;
229
235
let picker = getByRole ( 'button' ) ;
236
+ let hiddenLabel = getByText ( 'Search within' ) ;
230
237
231
238
expect ( group ) . not . toHaveAttribute ( 'aria-label' ) ;
232
239
233
240
expect ( group ) . toHaveAttribute ( 'aria-labelledby' , 'id-foo-label' ) ;
234
- expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `id-foo-label ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
241
+ expect ( searchfield ) . toHaveAttribute ( 'aria-labelledby' , `id-foo-label ${ hiddenLabel . id } ${ picker . id } ` ) ;
235
242
expect ( searchfield ) . toHaveAttribute ( 'id' , 'id-searchfield' ) ;
236
- expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `id-foo-label ${ picker . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
243
+ expect ( picker ) . toHaveAttribute ( 'aria-labelledby' , `id-foo-label ${ hiddenLabel . id } ${ picker . childNodes [ 0 ] . id } ` ) ;
237
244
} ) ;
238
245
} ) ;
0 commit comments