forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chip.test.js
709 lines (584 loc) · 24.9 KB
/
Chip.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
import * as React from 'react';
import { expect } from 'chai';
import { spy, stub } from 'sinon';
import {
describeConformance,
act,
createRenderer,
fireEvent,
focusVisible,
simulatePointerDevice,
programmaticFocusTriggersFocusVisible,
} from 'test/utils';
import Avatar from '@mui/material/Avatar';
import Chip, { chipClasses as classes } from '@mui/material/Chip';
import { ThemeProvider, createTheme, hexToRgb } from '@mui/material/styles';
import CheckBox from '../internal/svg-icons/CheckBox';
import defaultTheme from '../styles/defaultTheme';
describe('<Chip />', () => {
const { render } = createRenderer();
describeConformance(<Chip />, () => ({
classes,
inheritComponent: 'div',
render,
muiName: 'MuiChip',
testDeepOverrides: { slotName: 'label', slotClassName: classes.label },
testVariantProps: { variant: 'outlined' },
testStatOverrides: { prop: 'size', value: 'small', styleKey: 'sizeSmall' },
refInstanceof: window.HTMLDivElement,
testComponentPropWith: 'span',
skip: ['componentsProp'],
}));
describe('text only', () => {
it('is not in tab order', () => {
const { container } = render(<Chip label="My text Chip" />);
expect(container.querySelectorAll('[tabindex]')).to.have.length(0);
});
it('should renders certain classes and contains a label', () => {
const { container } = render(<Chip label="My text Chip" />);
const chip = container.querySelector(`.${classes.root}`);
const label = container.querySelector(`.${classes.label}`);
expect(label).to.have.tagName('span');
expect(label).to.have.text('My text Chip');
expect(chip).to.have.class(classes.root);
expect(chip).not.to.have.class(classes.colorPrimary);
expect(chip).not.to.have.class(classes.colorSecondary);
expect(chip).not.to.have.class(classes.clickable);
expect(chip).not.to.have.class(classes.clickableColorPrimary);
expect(chip).not.to.have.class(classes.clickableColorSecondary);
expect(chip).not.to.have.class(classes.deletable);
expect(chip).not.to.have.class(classes.deletableColorPrimary);
expect(chip).not.to.have.class(classes.deletableColorSecondary);
});
it('should render with the color class name based on the color prop', () => {
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
['primary', 'secondary', 'info', 'error', 'warning', 'success'].forEach((color) => {
const { container } = render(<Chip color={color} />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes[`color${capitalize(color)}`]);
});
});
});
describe('clickable chip', () => {
it('renders as a button in taborder with the label as the accessible name', () => {
const { getByRole } = render(<Chip label="My Chip" onClick={() => {}} />);
const button = getByRole('button');
expect(button).to.have.property('tabIndex', 0);
expect(button).toHaveAccessibleName('My Chip');
});
it('should render link with the button base', () => {
const { container } = render(<Chip component="a" clickable label="My text Chip" />);
expect(container.firstChild).to.have.class('MuiButtonBase-root');
expect(container.firstChild).to.have.tagName('a');
expect(container.firstChild.querySelector('.MuiTouchRipple-root')).not.to.equal(null);
});
it('should disable ripple when MuiButtonBase has disableRipple in theme', () => {
const theme = createTheme({
components: {
MuiButtonBase: {
defaultProps: {
disableRipple: true,
},
},
},
});
const { container } = render(
<ThemeProvider theme={theme}>
<Chip clickable label="My Chip" />
</ThemeProvider>,
);
expect(container.firstChild).to.have.class('MuiButtonBase-root');
expect(container.firstChild.querySelector('.MuiTouchRipple-root')).to.equal(null);
});
it('should apply user value of tabIndex', () => {
const { getByRole } = render(<Chip label="My Chip" onClick={() => {}} tabIndex={5} />);
expect(getByRole('button')).to.have.property('tabIndex', 5);
});
it('should render with the root and clickable class', () => {
const { container } = render(<Chip label="My Chip" onClick={() => {}} />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.root);
expect(chip).to.have.class(classes.clickable);
});
it('should render with the root and clickable primary class', () => {
const { getByRole } = render(<Chip label="My Chip" onClick={() => {}} color="primary" />);
const button = getByRole('button');
expect(button).to.have.class(classes.root);
expect(button).to.have.class(classes.colorPrimary);
expect(button).to.have.class(classes.clickable);
expect(button).to.have.class(classes.clickableColorPrimary);
});
it('should render with the root and outlined clickable primary class', () => {
const { container } = render(
<Chip color="primary" label="My Chip" onClick={() => {}} variant="outlined" />,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.root);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.clickable);
expect(chip).to.have.class(classes.clickableColorPrimary);
expect(chip).to.have.class(classes.outlined);
expect(chip).to.have.class(classes.outlinedPrimary);
});
it('should render with the root and outlined clickable secondary class', () => {
const { getByRole } = render(
<Chip color="secondary" label="My Chip" onClick={() => {}} variant="outlined" />,
);
const button = getByRole('button');
expect(button).to.have.class(classes.root);
expect(button).to.have.class(classes.colorSecondary);
expect(button).to.have.class(classes.clickable);
expect(button).to.have.class(classes.clickableColorSecondary);
expect(button).to.have.class(classes.outlined);
expect(button).to.have.class(classes.outlinedSecondary);
});
it('should render with the root and filled clickable primary class', () => {
const { getByRole } = render(
<Chip color="primary" label="My Chip" onClick={() => {}} variant="filled" />,
);
const chip = getByRole('button');
expect(chip).to.have.class(classes.root);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.clickable);
expect(chip).to.have.class(classes.clickableColorPrimary);
expect(chip).to.have.class(classes.filled);
expect(chip).to.have.class(classes.filledPrimary);
});
it('should not be focused when chip is disabled', () => {
const { getByTestId } = render(<Chip label="My Chip" disabled data-testid="chip" />);
const chip = getByTestId('chip');
fireEvent.keyDown(document.body, { key: 'Tab' });
expect(chip).to.have.class(classes.root);
expect(chip).to.have.property('tabIndex', -1);
expect(chip).not.to.have.class(classes.focusVisible);
});
it('should render with the root and filled clickable secondary class', () => {
const { getByRole } = render(
<Chip color="secondary" label="My Chip" onClick={() => {}} variant="filled" />,
);
const chip = getByRole('button');
expect(chip).to.have.class(classes.root);
expect(chip).to.have.class(classes.colorSecondary);
expect(chip).to.have.class(classes.clickable);
expect(chip).to.have.class(classes.clickableColorSecondary);
expect(chip).to.have.class(classes.filled);
expect(chip).to.have.class(classes.filledSecondary);
});
});
describe('deletable Avatar chip', () => {
it('should render a button in tab order with the avatar', () => {
const { container, getByRole } = render(
<Chip
avatar={<Avatar id="avatar">MB</Avatar>}
label="Text Avatar Chip"
onDelete={() => {}}
/>,
);
expect(getByRole('button')).to.have.property('tabIndex', 0);
expect(container.querySelector('#avatar')).not.to.equal(null);
});
it('should not create ripples', () => {
const { container } = render(
<Chip avatar={<Avatar id="avatar">MB</Avatar>} onDelete={() => {}} />,
);
expect(container.firstChild.querySelector('.MuiTouchRipple-root')).to.equal(null);
});
it('should apply user value of tabIndex', () => {
const { container, getByRole } = render(
<Chip
avatar={<Avatar id="avatar">MB</Avatar>}
label="Text Avatar Chip"
onDelete={() => {}}
tabIndex={5}
/>,
);
expect(getByRole('button')).to.have.property('tabIndex', 5);
const elementsInTabOrder = Array.from(container.querySelectorAll('[tabIndex]')).filter(
(element) => element.tabIndex >= 0,
);
expect(elementsInTabOrder).to.have.length(1);
});
it('fires onDelete when clicking the delete icon', () => {
const handleDelete = spy();
const { getByTestId } = render(
<Chip
avatar={<Avatar id="avatar">MB</Avatar>}
label="Text Avatar Chip"
onDelete={handleDelete}
deleteIcon={<div data-testid="delete-icon" />}
/>,
);
const deleteIcon = getByTestId('delete-icon');
fireEvent.click(deleteIcon);
expect(handleDelete.callCount).to.equal(1);
});
it('should stop propagation when clicking the delete icon', () => {
const handleClick = spy();
const { getByTestId } = render(
<Chip
avatar={<Avatar id="avatar">MB</Avatar>}
label="Text Avatar Chip"
onClick={handleClick}
onDelete={() => {}}
deleteIcon={<div data-testid="delete-icon" />}
/>,
);
const deleteIcon = getByTestId('delete-icon');
fireEvent.click(deleteIcon);
expect(handleClick.callCount).to.equal(0);
});
it('should render with the root, deletable classes', () => {
const { container } = render(
<Chip
avatar={<Avatar id="avatar">MB</Avatar>}
label="Text Avatar Chip"
onDelete={() => {}}
/>,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.deletable);
});
it('should render with the root, deletable and avatar primary classes', () => {
const { container } = render(
<Chip
avatar={<Avatar className="my-Avatar">MB</Avatar>}
label="Text Avatar Chip"
onDelete={() => {}}
color="primary"
/>,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorPrimary);
const avatar = container.querySelector(`.${classes.avatar}`);
expect(avatar).to.have.class(classes.avatarColorPrimary);
});
it('should render with the root, deletable and avatar secondary classes', () => {
const { container } = render(
<Chip
avatar={<Avatar>MB</Avatar>}
label="Text Avatar Chip"
onDelete={() => {}}
color="secondary"
/>,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSecondary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorSecondary);
const avatar = container.querySelector(`.${classes.avatar}`);
expect(avatar).to.have.class(classes.avatarColorSecondary);
});
});
describe('prop: deleteIcon', () => {
it('should render a default icon with the root, deletable and deleteIcon classes', () => {
const { getByRole, getByTestId } = render(
<Chip label="Custom delete icon Chip" onDelete={() => {}} />,
);
const chip = getByRole('button');
const icon = getByTestId('CancelIcon');
expect(chip).to.have.class(classes.deletable);
expect(chip).to.contain(icon);
expect(icon).to.have.class(classes.deleteIcon);
});
it('should render default icon with the root, deletable and deleteIcon primary class', () => {
const { container, getByTestId } = render(
<Chip label="Custom delete icon Chip" onDelete={() => {}} color="primary" />,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorPrimary);
const icon = getByTestId('CancelIcon');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorPrimary);
});
it('should render a default icon with the root, deletable, deleteIcon secondary class', () => {
const { container, getByTestId } = render(
<Chip label="Custom delete icon Chip" onDelete={() => {}} color="secondary" />,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorSecondary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorSecondary);
const icon = getByTestId('CancelIcon');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorSecondary);
});
it('should render default icon with the root, deletable, deleteIcon primary class and deleteIcon filled primary class', () => {
const { container, getByTestId } = render(
<Chip
label="Custom delete icon Chip"
onDelete={() => {}}
color="primary"
variant="filled"
/>,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorPrimary);
const icon = getByTestId('CancelIcon');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorPrimary);
expect(icon).to.have.class(classes.deleteIconFilledColorPrimary);
});
it('should render default icon with the root, deletable, deleteIcon primary class and deleteIcon outlined primary class', () => {
const { container, getByTestId } = render(
<Chip
label="Custom delete icon Chip"
onDelete={() => {}}
color="primary"
variant="outlined"
/>,
);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.colorPrimary);
expect(chip).to.have.class(classes.deletable);
expect(chip).to.have.class(classes.deletableColorPrimary);
const icon = getByTestId('CancelIcon');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconColorPrimary);
expect(icon).to.have.class(classes.deleteIconOutlinedColorPrimary);
});
it('accepts a custom icon', () => {
const handleDelete = spy();
const { getByTestId } = render(
<Chip label="Custom delete icon Chip" onDelete={handleDelete} deleteIcon={<CheckBox />} />,
);
fireEvent.click(getByTestId('CheckBoxIcon'));
expect(handleDelete.callCount).to.equal(1);
});
});
describe('reacts to keyboard chip', () => {
it('should call onKeyDown when a key is pressed', () => {
const handleKeydown = stub().callsFake((event) => event.key);
const { getByRole } = render(<Chip onClick={() => {}} onKeyDown={handleKeydown} />);
const chip = getByRole('button');
act(() => {
chip.focus();
});
fireEvent.keyDown(chip, { key: 'p' });
expect(handleKeydown.callCount).to.equal(1);
expect(handleKeydown.firstCall.returnValue).to.equal('p');
});
it('should unfocus when a esc key is pressed', () => {
const handleBlur = spy();
const handleKeydown = spy();
const { getByRole } = render(
<Chip onBlur={handleBlur} onClick={() => {}} onKeyDown={handleKeydown} />,
);
const chip = getByRole('button');
act(() => {
chip.focus();
});
fireEvent.keyUp(chip, { key: 'Escape' });
expect(handleBlur.callCount).to.equal(1);
expect(chip).not.toHaveFocus();
});
it('should call onClick when `space` is released ', () => {
const handleClick = spy();
const { getByRole } = render(<Chip onClick={handleClick} />);
const chip = getByRole('button');
act(() => {
chip.focus();
});
fireEvent.keyUp(chip, { key: ' ' });
expect(handleClick.callCount).to.equal(1);
});
it('should call onClick when `enter` is pressed ', () => {
const handleClick = spy();
const { getByRole } = render(<Chip onClick={handleClick} />);
const chip = getByRole('button');
act(() => {
chip.focus();
});
fireEvent.keyDown(chip, { key: 'Enter' });
expect(handleClick.callCount).to.equal(1);
});
describe('prop: onDelete', () => {
['Backspace', 'Delete'].forEach((key) => {
it(`should call onDelete '${key}' is released`, () => {
const handleDelete = spy();
const handleKeyDown = spy();
const { getAllByRole } = render(
<Chip onClick={() => {}} onKeyDown={handleKeyDown} onDelete={handleDelete} />,
);
const chip = getAllByRole('button')[0];
act(() => {
chip.focus();
});
fireEvent.keyDown(chip, { key });
// defaultPrevented?
expect(handleKeyDown.callCount).to.equal(1);
expect(handleKeyDown.firstCall.args[0]).to.have.property('defaultPrevented', true);
expect(handleDelete.callCount).to.equal(0);
fireEvent.keyUp(chip, { key });
expect(handleDelete.callCount).to.equal(1);
});
});
it('should not prevent default on input', () => {
const handleKeyDown = spy();
const { container } = render(<Chip label={<input />} onKeyDown={handleKeyDown} />);
const input = container.querySelector('input');
act(() => {
input.focus();
});
fireEvent.keyDown(input, { key: 'Backspace' });
expect(handleKeyDown.callCount).to.equal(1);
expect(handleKeyDown.firstCall.args[0]).to.have.property('defaultPrevented', false);
});
});
describe('with children that generate events', () => {
['Backspace', 'Delete'].forEach((key) => {
it(`should not call onDelete for child keyup event when '${key}' is released`, () => {
const handleDelete = spy();
const handleKeyUp = spy();
render(
<Chip
onDelete={handleDelete}
label={<input autoFocus className="child-input" onKeyUp={handleKeyUp} />}
/>,
);
fireEvent.keyUp(document.querySelector('input'), { key });
expect(handleKeyUp.callCount).to.equal(1);
expect(handleDelete.callCount).to.equal(0);
});
});
it(`should not call onClick for child keyup event when 'Space' is released`, () => {
const handleClick = spy();
const handleKeyUp = spy();
render(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyUp={handleKeyUp} />}
/>,
);
fireEvent.keyUp(document.querySelector('input'), { key: ' ' });
expect(handleKeyUp.callCount).to.equal(1);
expect(handleClick.callCount).to.equal(0);
});
it(`should not call onClick for child keydown event when 'Enter' is pressed`, () => {
const handleClick = spy();
const handleKeyDown = spy();
render(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyDown={handleKeyDown} />}
/>,
);
fireEvent.keyDown(document.querySelector('input'), { key: 'Enter' });
expect(handleKeyDown.callCount).to.equal(1);
expect(handleClick.callCount).to.equal(0);
});
it('should not call onClick for child event when `space` is released', () => {
const handleClick = spy();
const handleKeyUp = spy();
render(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyUp={handleKeyUp} />}
/>,
);
fireEvent.keyUp(document.querySelector('input'), { key: ' ' });
expect(handleClick.callCount).to.equal(0);
expect(handleKeyUp.callCount).to.equal(1);
});
it('should not call onClick for child event when `enter` is pressed', () => {
const handleClick = spy();
const handleKeyDown = spy();
render(
<Chip
onClick={handleClick}
label={<input autoFocus className="child-input" onKeyDown={handleKeyDown} />}
/>,
);
fireEvent.keyDown(document.querySelector('input'), { key: 'Enter' });
expect(handleClick.callCount).to.equal(0);
expect(handleKeyDown.callCount).to.equal(1);
});
});
});
describe('prop: icon', () => {
it('should render the icon', () => {
const { getByTestId } = render(<Chip icon={<span data-testid="test-icon" />} />);
expect(getByTestId('test-icon')).to.have.class(classes.icon);
});
it("should not override the icon's custom color", () => {
const { getByTestId } = render(
<React.Fragment>
<Chip icon={<CheckBox data-testid="test-icon" color="success" />} />,
<Chip icon={<CheckBox data-testid="test-icon2" color="success" />} color="error" />,
</React.Fragment>,
);
expect(getByTestId('test-icon')).to.have.class('MuiChip-iconColorSuccess');
expect(getByTestId('test-icon2')).to.have.class('MuiChip-iconColorSuccess');
expect(getByTestId('test-icon')).toHaveComputedStyle({
color: hexToRgb(defaultTheme.palette.success.main),
});
expect(getByTestId('test-icon2')).toHaveComputedStyle({
color: hexToRgb(defaultTheme.palette.success.main),
});
});
});
describe('prop: size', () => {
it('should render with the sizeSmall class', () => {
const { container } = render(<Chip size="small" />);
const chip = container.querySelector(`.${classes.root}`);
expect(chip).to.have.class(classes.sizeSmall);
});
it('should render the label with the labelSmall class', () => {
const { container } = render(<Chip size="small" label="small chip" />);
const label = container.querySelector(`.${classes.label}`);
expect(label).to.have.class(classes.labelSmall);
});
it('should render an avatar with the avatarSmall class', () => {
const { container } = render(
<Chip size="small" avatar={<Avatar className="my-Avatar">MB</Avatar>} />,
);
const avatar = container.querySelector('.my-Avatar');
expect(avatar).to.have.class(classes.avatar);
expect(avatar).to.have.class(classes.avatarSmall);
});
it('should render an icon with the icon and iconSmall classes', () => {
const { container } = render(<Chip size="small" icon={<span id="test-icon" />} />);
const icon = container.querySelector('#test-icon');
expect(icon).to.have.class(classes.icon);
expect(icon).to.have.class(classes.iconSmall);
});
it('should render the delete icon with the deleteIcon and deleteIconSmall classes', () => {
const { getByTestId } = render(<Chip size="small" onDelete={() => {}} />);
const icon = getByTestId('CancelIcon');
expect(icon).to.have.class(classes.deleteIcon);
expect(icon).to.have.class(classes.deleteIconSmall);
});
});
describe('event: focus', () => {
it('has a focus-visible polyfill', () => {
const { container } = render(<Chip label="Test Chip" onClick={() => {}} />);
const chip = container.querySelector(`.${classes.root}`);
simulatePointerDevice();
expect(chip).not.to.have.class(classes.focusVisible);
act(() => {
chip.focus();
});
if (programmaticFocusTriggersFocusVisible()) {
expect(chip).to.have.class(classes.focusVisible);
} else {
expect(chip).not.to.have.class(classes.focusVisible);
}
focusVisible(chip);
expect(chip).to.have.class(classes.focusVisible);
});
it('should reset the focused state', () => {
const { container, setProps } = render(<Chip label="Test Chip" onClick={() => {}} />);
const chip = container.querySelector(`.${classes.root}`);
simulatePointerDevice();
focusVisible(chip);
expect(chip).to.have.class(classes.focusVisible);
setProps({ disabled: true });
expect(chip).not.to.have.class(classes.focusVisible);
});
});
});