|
1 | 1 | /* eslint-disable max-classes-per-file */
|
2 | 2 |
|
3 | 3 | import '@testing-library/jest-dom';
|
4 |
| -import { fireEvent, render } from '@testing-library/react'; |
| 4 | +import { createEvent, fireEvent, render } from '@testing-library/react'; |
5 | 5 | import KeyCode from 'rc-util/lib/KeyCode';
|
6 | 6 | import { resetWarned } from 'rc-util/lib/warning';
|
7 | 7 | import React, { act } from 'react';
|
@@ -604,4 +604,42 @@ describe('Select.Combobox', () => {
|
604 | 604 | const { container } = render(<Select mode="combobox" value={0} />);
|
605 | 605 | expect(container.querySelector('input')!.value).toBe('0');
|
606 | 606 | });
|
| 607 | + |
| 608 | + // https://github.com/ant-design/ant-design/issues/48281 |
| 609 | + describe('combobox mode onMouseDown event default behavior', () => { |
| 610 | + it('should prevent default behavior when mode is combobox', () => { |
| 611 | + const preventDefault = jest.fn(); |
| 612 | + const { container } = render( |
| 613 | + <Select mode="combobox" value="1"> |
| 614 | + <Option value="1">1</Option> |
| 615 | + <Option value="2">2</Option> |
| 616 | + </Select>, |
| 617 | + ); |
| 618 | + |
| 619 | + const selectorEle = container.querySelector('.rc-select-selector'); |
| 620 | + |
| 621 | + const mouseDownEvent = createEvent.mouseDown(selectorEle); |
| 622 | + mouseDownEvent.preventDefault = preventDefault; |
| 623 | + fireEvent(selectorEle, mouseDownEvent); |
| 624 | + expect(preventDefault).toHaveBeenCalled(); |
| 625 | + }) |
| 626 | + |
| 627 | + it('should not prevent default behavior when mode is combobox and it is disabled', () => { |
| 628 | + const preventDefault = jest.fn(); |
| 629 | + const { container } = render( |
| 630 | + <Select mode="combobox" value="1" disabled> |
| 631 | + <Option value="1">1</Option> |
| 632 | + <Option value="2">2</Option> |
| 633 | + </Select>, |
| 634 | + ); |
| 635 | + |
| 636 | + const selectorEle = container.querySelector('.rc-select-selector'); |
| 637 | + |
| 638 | + const mouseDownEvent = createEvent.mouseDown(selectorEle); |
| 639 | + mouseDownEvent.preventDefault = preventDefault; |
| 640 | + fireEvent(selectorEle, mouseDownEvent); |
| 641 | + expect(preventDefault).not.toHaveBeenCalled(); |
| 642 | + }) |
| 643 | + }); |
| 644 | + |
607 | 645 | });
|
0 commit comments