@@ -5,13 +5,7 @@ import userEvent from '@testing-library/user-event';
5
5
6
6
import { DataList } from '../DataList' ;
7
7
import { DataListItem } from '../DataListItem' ;
8
- import { DataListAction } from '../DataListAction' ;
9
- import { DataListCell } from '../DataListCell' ;
10
- import { DataListToggle } from '../DataListToggle' ;
11
- import { DataListItemCells } from '../DataListItemCells' ;
12
8
import { DataListItemRow } from '../DataListItemRow' ;
13
- import { DataListContent } from '../DataListContent' ;
14
- import { Button } from '../../Button' ;
15
9
16
10
import styles from '@patternfly/react-styles/css/components/DataList/data-list' ;
17
11
@@ -43,17 +37,17 @@ const gridBreakpointClasses = {
43
37
} ) ;
44
38
} ) ;
45
39
46
- test ( `Has breakpoint - 2xl when gridBreakpoint is pased ` , ( ) => {
47
- render ( < DataList aria-label = "list" gridBreakpoint = "2xl " /> ) ;
48
- expect ( screen . getByLabelText ( 'list' ) ) . toHaveClass ( styles . modifiers [ 'grid_2xl' ] ) ;
40
+ test ( `Renders default class ${ styles . dataList } ` , ( ) => {
41
+ render ( < DataList key = "list-id-1" aria-label = "list " /> ) ;
42
+ expect ( screen . getByLabelText ( 'list' ) ) . toHaveClass ( styles . dataList ) ;
49
43
} ) ;
50
44
51
45
test ( 'Renders custom class when passed' , ( ) => {
52
46
render ( < DataList key = "list-id-1" className = "data-list-custom" aria-label = "list" /> ) ;
53
47
expect ( screen . getByLabelText ( 'list' ) ) . toHaveClass ( 'data-list-custom' ) ;
54
48
} ) ;
55
49
56
- test ( 'List renders with a hidden input to improve a11y when selectableRow is passed' , ( ) => {
50
+ test ( 'Renders with a hidden input to improve a11y when onSelectableRowChange is passed' , ( ) => {
57
51
render (
58
52
< DataList aria-label = "this is a simple list" onSelectableRowChange = { ( ) => { } } >
59
53
< DataListItem >
@@ -69,7 +63,7 @@ test('List renders with a hidden input to improve a11y when selectableRow is pas
69
63
expect ( selectableInput ) . toBeInTheDocument ( ) ;
70
64
} ) ;
71
65
72
- test ( 'List does not render with a hidden input to improve a11y when selectableRow is not passed' , ( ) => {
66
+ test ( 'Does not render with a hidden input to improve a11y when onSelectableRowChange is not passed' , ( ) => {
73
67
render (
74
68
< DataList aria-label = "this is a simple list" >
75
69
< DataListItem >
@@ -85,7 +79,7 @@ test('List does not render with a hidden input to improve a11y when selectableRo
85
79
expect ( selectableInput ) . not . toBeInTheDocument ( ) ;
86
80
} ) ;
87
81
88
- test ( 'List calls selectableRow .onChange when the selectable input changes' , async ( ) => {
82
+ test ( 'Calls onSelectableRowChange .onChange when the selectable input changes' , async ( ) => {
89
83
const mock = jest . fn ( ) ;
90
84
const user = userEvent . setup ( ) ;
91
85
@@ -105,7 +99,7 @@ test('List calls selectableRow.onChange when the selectable input changes', asyn
105
99
expect ( mock ) . toHaveBeenCalled ( ) ;
106
100
} ) ;
107
101
108
- test ( 'List does not call selectableRow .onChange when the selectable input is not changed' , ( ) => {
102
+ test ( 'Does not call onSelectableRowChange .onChange when the selectable input is not changed' , ( ) => {
109
103
const mock = jest . fn ( ) ;
110
104
111
105
render (
@@ -121,7 +115,7 @@ test('List does not call selectableRow.onChange when the selectable input is not
121
115
expect ( mock ) . not . toHaveBeenCalled ( ) ;
122
116
} ) ;
123
117
124
- test ( 'Item applies selectableInputAriaLabel to the hidden input' , ( ) => {
118
+ test ( 'Applies selectableInputAriaLabel to the hidden input' , ( ) => {
125
119
render (
126
120
< DataList aria-label = "this is a simple list" onSelectableRowChange = { ( ) => { } } >
127
121
< DataListItem selectableInputAriaLabel = "Data list item label test" >
@@ -137,7 +131,7 @@ test('Item applies selectableInputAriaLabel to the hidden input', () => {
137
131
expect ( selectableInput ) . toHaveAccessibleName ( 'Data list item label test' ) ;
138
132
} ) ;
139
133
140
- test ( 'Item defaults to labelling its input using its aria-labelledby prop' , ( ) => {
134
+ test ( 'Defaults to labelling its input using its aria-labelledby prop' , ( ) => {
141
135
render (
142
136
< DataList aria-label = "this is a simple list" onSelectableRowChange = { ( ) => { } } >
143
137
< DataListItem aria-labelledby = "test-id" >
@@ -151,7 +145,7 @@ test('Item defaults to labelling its input using its aria-labelledby prop', () =
151
145
expect ( selectableInput ) . toHaveAccessibleName ( 'Test cell content' ) ;
152
146
} ) ;
153
147
154
- test ( 'Item prioritizes selectableInputAriaLabel over aria-labelledby prop' , ( ) => {
148
+ test ( 'Prioritizes selectableInputAriaLabel over aria-labelledby prop' , ( ) => {
155
149
render (
156
150
< DataList aria-label = "this is a simple list" onSelectableRowChange = { ( ) => { } } >
157
151
< DataListItem aria-labelledby = "test-id" selectableInputAriaLabel = "Data list item label test" >
@@ -164,233 +158,3 @@ test('Item prioritizes selectableInputAriaLabel over aria-labelledby prop', () =
164
158
165
159
expect ( selectableInput ) . toHaveAccessibleName ( 'Data list item label test' ) ;
166
160
} ) ;
167
-
168
- test ( 'Item renders to match snapshot' , ( ) => {
169
- const { asFragment } = render (
170
- < DataListItem key = "item-id-1" aria-labelledby = "item-1" >
171
- test
172
- </ DataListItem >
173
- ) ;
174
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
175
- } ) ;
176
-
177
- test ( `Item has ${ styles . modifiers . expanded } when isExpanded is passed` , ( ) => {
178
- render (
179
- < DataListItem aria-labelledby = "item-1" isExpanded >
180
- test
181
- </ DataListItem >
182
- ) ;
183
- expect ( screen . getByRole ( 'listitem' ) ) . toHaveClass ( styles . modifiers . expanded ) ;
184
- } ) ;
185
-
186
- test ( 'Item renders with custom class name' , ( ) => {
187
- render (
188
- < DataListItem className = "data-list-item-custom" aria-labelledby = "item-1" >
189
- test
190
- </ DataListItem >
191
- ) ;
192
- expect ( screen . getByRole ( 'listitem' ) ) . toHaveClass ( 'data-list-item-custom' ) ;
193
- } ) ;
194
-
195
- test ( 'Item row renders to match snapshot' , ( ) => {
196
- const { asFragment } = render ( < DataListItemRow > test</ DataListItemRow > ) ;
197
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
198
- } ) ;
199
-
200
- test ( 'Cell renders to match snapshot' , ( ) => {
201
- const { asFragment } = render ( < DataListCell > Secondary</ DataListCell > ) ;
202
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
203
- } ) ;
204
-
205
- test ( 'Cells renders to match snapshot' , ( ) => {
206
- const { asFragment } = render (
207
- < DataListItemCells
208
- dataListCells = { [
209
- < DataListCell key = "list-id-1" id = "primary-item" className = "data-list-custom" >
210
- Primary Id
211
- </ DataListCell > ,
212
- < DataListCell key = "list-id-2" id = "primary-item" className = "data-list-custom" >
213
- Primary Id 2
214
- </ DataListCell >
215
- ] }
216
- />
217
- ) ;
218
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
219
- } ) ;
220
-
221
- test ( 'Cell has width modifier when width is passed' , ( ) => {
222
- [
223
- { width : 1 , class : '' } ,
224
- { width : 2 , class : 'pf-m-flex-2' } ,
225
- { width : 3 , class : 'pf-m-flex-3' } ,
226
- { width : 4 , class : 'pf-m-flex-4' } ,
227
- { width : 5 , class : 'pf-m-flex-5' }
228
- ] . forEach ( ( testCase , index ) => {
229
- const testId = `cell-test-id-${ index } ` ;
230
-
231
- render (
232
- < DataListCell data-testid = { testId } width = { testCase . width as any } key = { index } >
233
- Primary Id
234
- </ DataListCell >
235
- ) ;
236
-
237
- const dataListCell = screen . getByTestId ( testId ) ;
238
-
239
- testCase . class === ''
240
- ? expect ( dataListCell ) . toHaveClass ( 'pf-v5-c-data-list__cell' )
241
- : expect ( dataListCell ) . toHaveClass ( `pf-v5-c-data-list__cell ${ testCase . class } ` ) ;
242
- } ) ;
243
- } ) ;
244
-
245
- test ( 'Cell has text wrap modifiers when wrapModifier is passed' , ( ) => {
246
- [
247
- { wrapModifier : null as any , class : '' } ,
248
- { wrapModifier : 'breakWord' , class : 'pf-m-break-word' } ,
249
- { wrapModifier : 'nowrap' , class : 'pf-m-nowrap' } ,
250
- { wrapModifier : 'truncate' , class : 'pf-m-truncate' }
251
- ] . forEach ( ( testCase , index ) => {
252
- const testId = `cell-test-id-${ index } ` ;
253
-
254
- render (
255
- < DataListCell data-testid = { testId } wrapModifier = { testCase . wrapModifier } key = { index } >
256
- Primary Id
257
- </ DataListCell >
258
- ) ;
259
-
260
- const dataListCell = screen . getByTestId ( testId ) ;
261
-
262
- testCase . class === ''
263
- ? expect ( dataListCell ) . toHaveClass ( 'pf-v5-c-data-list__cell' )
264
- : expect ( dataListCell ) . toHaveClass ( `pf-v5-c-data-list__cell ${ testCase . class } ` ) ;
265
- } ) ;
266
- } ) ;
267
-
268
- test ( `Cell has custom class when className is passed` , ( ) => {
269
- render (
270
- < DataListCell data-testid = "test" key = { 0 } className = "test-class" >
271
- Primary Id
272
- </ DataListCell >
273
- ) ;
274
- expect ( screen . getByTestId ( 'test' ) ) . toHaveClass ( 'test-class' ) ;
275
- } ) ;
276
-
277
- test ( `Cell has ${ styles . modifiers . alignRight } when alignRight is passed` , ( ) => {
278
- render (
279
- < DataListCell data-testid = "test" key = { 0 } alignRight >
280
- Primary Id
281
- </ DataListCell >
282
- ) ;
283
- expect ( screen . getByTestId ( 'test' ) ) . toHaveClass ( styles . modifiers . alignRight ) ;
284
- } ) ;
285
-
286
- test ( `Cell has ${ styles . modifiers . icon } when isIcon is passed` , ( ) => {
287
- render (
288
- < DataListCell data-testid = "test" key = { 0 } isIcon >
289
- Primary Id
290
- </ DataListCell >
291
- ) ;
292
- expect ( screen . getByTestId ( 'test' ) ) . toHaveClass ( styles . modifiers . icon ) ;
293
- } ) ;
294
-
295
- test ( `Cell has ${ styles . modifiers . noFill } when isFilled = false` , ( ) => {
296
- render (
297
- < DataListCell data-testid = "test" key = { 0 } isFilled = { false } >
298
- Primary Id
299
- </ DataListCell >
300
- ) ;
301
- expect ( screen . getByTestId ( 'test' ) ) . toHaveClass ( styles . modifiers . noFill ) ;
302
- } ) ;
303
-
304
- test ( 'Toggle has aria label' , ( ) => {
305
- render ( < DataListToggle aria-label = "Toggle details for" id = "ex-toggle2" /> ) ;
306
-
307
- expect ( screen . getByRole ( 'button' ) ) . not . toHaveAttribute ( 'aria-labelledby' ) ;
308
- expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-label' , 'Toggle details for' ) ;
309
- expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
310
- } ) ;
311
-
312
- test ( 'Toggle has aria-expanded set when isExpanded is passed' , ( ) => {
313
- render ( < DataListToggle aria-label = "Toggle details for" id = "ex-toggle2" isExpanded /> ) ;
314
- expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
315
- } ) ;
316
-
317
- test ( 'DataListAction renders to match snapshot' , ( ) => {
318
- const { asFragment } = render (
319
- < DataListAction aria-label = "Actions" aria-labelledby = "ex-action" id = "ex-action" >
320
- < Button id = "delete-item-1" > Delete</ Button >
321
- </ DataListAction >
322
- ) ;
323
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
324
- } ) ;
325
-
326
- test ( `DataListAction has custom class when className is passed` , ( ) => {
327
- render (
328
- < DataListAction aria-label = "Actions" aria-labelledby = "ex-action" id = "ex-action" className = "test-class" >
329
- < Button id = "delete-item-1" > Delete</ Button >
330
- </ DataListAction >
331
- ) ;
332
- expect ( screen . getByRole ( 'button' ) . parentElement ) . toHaveClass ( 'test-class' ) ;
333
- } ) ;
334
-
335
- test ( 'DataListAction shows button with visibliity breakpoint set' , ( ) => {
336
- render (
337
- < DataListAction
338
- visibility = { { default : 'hidden' , lg : 'visible' } }
339
- aria-labelledby = "check-action-item2 check-action-action2"
340
- id = "check-action-action2"
341
- aria-label = "Actions"
342
- >
343
- < Button variant = "primary" > Primary</ Button >
344
- </ DataListAction >
345
- ) ;
346
-
347
- expect ( screen . getByRole ( 'button' ) . parentElement ) . toHaveClass ( 'pf-m-hidden' ) ;
348
- expect ( screen . getByRole ( 'button' ) . parentElement ) . toHaveClass ( 'pf-m-visible-on-lg' ) ;
349
- } ) ;
350
-
351
- test ( 'DataListAction hides button with visibility breakpoint set' , ( ) => {
352
- render (
353
- < DataListAction
354
- visibility = { { '2xl' : 'hidden' } }
355
- aria-labelledby = "check-action-item2 check-action-action2"
356
- id = "check-action-action2"
357
- aria-label = "Actions"
358
- >
359
- < Button variant = "primary" > Primary</ Button >
360
- </ DataListAction >
361
- ) ;
362
-
363
- expect ( screen . getByRole ( 'button' ) . parentElement ) . toHaveClass ( 'pf-m-hidden-on-2xl' ) ;
364
- } ) ;
365
-
366
- test ( 'DataListContent renders to match snapshot' , ( ) => {
367
- const { asFragment } = render ( < DataListContent aria-label = "Primary Content Details" > test</ DataListContent > ) ;
368
- expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
369
- } ) ;
370
-
371
- test ( `DataListContent has ${ styles . modifiers . noPadding } when hasNoPadding is passed` , ( ) => {
372
- render (
373
- < DataListContent aria-label = "Primary Content Details" hidden hasNoPadding >
374
- test
375
- </ DataListContent >
376
- ) ;
377
- expect ( screen . getByText ( 'test' ) ) . toHaveClass ( styles . modifiers . noPadding ) ;
378
- } ) ;
379
-
380
- test ( `DataListContent has hidden property when isHidden is passed` , ( ) => {
381
- render (
382
- < DataListContent data-testid = "test-id" aria-label = "Primary Content Details" isHidden >
383
- test
384
- </ DataListContent >
385
- ) ;
386
- expect ( screen . getByTestId ( 'test-id' ) ) . toHaveAttribute ( 'hidden' ) ;
387
- } ) ;
388
-
389
- test ( `DataListContent has custom class when className is passed` , ( ) => {
390
- render (
391
- < DataListContent data-testid = "test-id" aria-label = "Primary Content Details" className = "test-class" >
392
- test
393
- </ DataListContent >
394
- ) ;
395
- expect ( screen . getByTestId ( 'test-id' ) ) . toHaveClass ( 'test-class' ) ;
396
- } ) ;
0 commit comments