Skip to content

Commit 7d9fa17

Browse files
committed
test: part of test
1 parent c0f3d56 commit 7d9fa17

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

tests/Select.checkable.spec.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent, render } from '@testing-library/react';
33
import { mount } from 'enzyme';
44
import React from 'react';
55
import TreeSelect, { SHOW_ALL, SHOW_PARENT, TreeNode } from '../src';
6-
import { clearSelection, search, selectNode } from './util';
6+
import { clearSelection, search, selectNode, triggerOpen } from './util';
77

88
describe('TreeSelect.checkable', () => {
99
it('allow clear when controlled', () => {
@@ -210,7 +210,9 @@ describe('TreeSelect.checkable', () => {
210210
expect(wrapper.getSelection()).toHaveLength(0);
211211
});
212212

213-
it('clear selected value and input value', async () => {
213+
it('clear selected value and input value', () => {
214+
jest.useFakeTimers();
215+
214216
const treeData = [
215217
{
216218
key: '0',
@@ -228,12 +230,23 @@ describe('TreeSelect.checkable', () => {
228230
showCheckedStrategy={SHOW_PARENT}
229231
/>,
230232
);
231-
wrapper.openSelect();
232-
wrapper.selectNode(0);
233-
wrapper.search('foo');
234-
wrapper.clearAll();
235-
expect(wrapper.getSelection()).toHaveLength(0);
236-
expect(wrapper.find('input').first().props().value).toBe('');
233+
234+
triggerOpen(container);
235+
selectNode(0);
236+
search(container, 'foo');
237+
238+
// Clear all using mouseDown (same as wrapper.clearAll())
239+
const clearButton = container.querySelector('.rc-tree-select-clear')!;
240+
fireEvent.mouseDown(clearButton);
241+
242+
// Check that no items are selected
243+
expect(container.querySelectorAll('.rc-tree-select-selection-item')).toHaveLength(0);
244+
245+
// Check that input value is cleared
246+
const input = container.querySelector('input') as HTMLInputElement;
247+
expect(input.value).toBe('');
248+
249+
jest.useRealTimers();
237250
});
238251

239252
describe('uncheck', () => {

0 commit comments

Comments
 (0)