-
Notifications
You must be signed in to change notification settings - Fork 200
test: Fix test case #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Fix test case #650
Changes from all commits
fe51563
6a7246c
6de0b20
e90494a
c0f3d56
7d9fa17
e4ba16d
f5ed7f3
a7ebb12
5f3fed4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,22 @@ | ||||||||||||||||||||||||
| /* eslint-disable no-undef */ | ||||||||||||||||||||||||
| import { render, fireEvent, within } from '@testing-library/react'; | ||||||||||||||||||||||||
| import { render, fireEvent, within, screen } from '@testing-library/react'; | ||||||||||||||||||||||||
| import { mount } from 'enzyme'; | ||||||||||||||||||||||||
| import KeyCode from '@rc-component/util/lib/KeyCode'; | ||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||
| import TreeSelect, { TreeNode } from '../src'; | ||||||||||||||||||||||||
| import focusTest from './shared/focusTest'; | ||||||||||||||||||||||||
| import { selectNode, clearSelection, search, expectOpen, triggerOpen } from './util'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| describe('TreeSelect.multiple', () => { | ||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||
| jest.useFakeTimers(); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| afterEach(() => { | ||||||||||||||||||||||||
| jest.clearAllTimers(); | ||||||||||||||||||||||||
| jest.useRealTimers(); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
Comment on lines
+11
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's great that you're using
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| focusTest(true); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const treeData = [ | ||||||||||||||||||||||||
|
|
@@ -129,14 +139,29 @@ describe('TreeSelect.multiple', () => { | |||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it('do not open tree when close button click', () => { | ||||||||||||||||||||||||
| const wrapper = mount(createSelect()); | ||||||||||||||||||||||||
| wrapper.openSelect(); | ||||||||||||||||||||||||
| wrapper.selectNode(0); | ||||||||||||||||||||||||
| wrapper.selectNode(1); | ||||||||||||||||||||||||
| wrapper.openSelect(); | ||||||||||||||||||||||||
| wrapper.clearSelection(0); | ||||||||||||||||||||||||
| expect(wrapper.isOpen()).toBeFalsy(); | ||||||||||||||||||||||||
| expect(wrapper.getSelection()).toHaveLength(1); | ||||||||||||||||||||||||
| const { container } = render(createSelect()); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Open the select dropdown | ||||||||||||||||||||||||
| triggerOpen(container); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Select two nodes | ||||||||||||||||||||||||
| selectNode(0); | ||||||||||||||||||||||||
| selectNode(1); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Check selections exist | ||||||||||||||||||||||||
| expect(container.querySelectorAll('.rc-tree-select-selection-item')).toHaveLength(2); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Open again to ensure dropdown is open | ||||||||||||||||||||||||
| triggerOpen(container); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Clear one selection - this should NOT open the dropdown | ||||||||||||||||||||||||
| clearSelection(container, 0); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Check that only one selection remains | ||||||||||||||||||||||||
| expect(container.querySelectorAll('.rc-tree-select-selection-item')).toHaveLength(1); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Check that dropdown is closed after clearing | ||||||||||||||||||||||||
| expectOpen(container, false); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| describe('maxTagCount', () => { | ||||||||||||||||||||||||
|
|
@@ -239,8 +264,8 @@ describe('TreeSelect.multiple', () => { | |||||||||||||||||||||||
| // https://github.com/ant-design/ant-design/issues/12315 | ||||||||||||||||||||||||
| it('select searched node', () => { | ||||||||||||||||||||||||
| const onChange = jest.fn(); | ||||||||||||||||||||||||
| const wrapper = mount( | ||||||||||||||||||||||||
| <TreeSelect value={['leaf1']} multiple onChange={onChange}> | ||||||||||||||||||||||||
| const { container } = render( | ||||||||||||||||||||||||
| <TreeSelect value={['leaf1']} multiple onChange={onChange} open> | ||||||||||||||||||||||||
| <TreeNode value="parent 1" title="parent 1" key="0-1"> | ||||||||||||||||||||||||
| <TreeNode value="parent 1-0" title="parent 1-0" key="0-1-1"> | ||||||||||||||||||||||||
| <TreeNode value="leaf1" title="my leaf" key="random" /> | ||||||||||||||||||||||||
|
|
@@ -252,8 +277,12 @@ describe('TreeSelect.multiple', () => { | |||||||||||||||||||||||
| </TreeSelect>, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| wrapper.search('sss'); | ||||||||||||||||||||||||
| wrapper.selectNode(2); | ||||||||||||||||||||||||
| // Search for 'sss' | ||||||||||||||||||||||||
| search(container, 'sss'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Find and click on the searched node - use selectNode from util with correct index | ||||||||||||||||||||||||
| selectNode(2); // The sss node should be at index 2 after search filtering | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| expect(onChange).toHaveBeenCalledWith(['leaf1', 'sss'], expect.anything(), expect.anything()); | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding fake timers here is correct for this test, several other tests in this file are also being refactored to use utilities like
searchandtriggerOpenwhich rely on fake timers. Some of them are missing the timer setup (e.g., the 'remove in filtered tree' test). To ensure consistency and prevent future errors, it would be better to manage timers at thedescribeblock level usingbeforeEachandafterEach, as done intests/Select.multiple.spec.js.This would involve:
beforeEach(() => { jest.useFakeTimers(); });andafterEach(() => { jest.useRealTimers(); });at the top of thedescribe('TreeSelect.checkable', ...)block.jest.useFakeTimers()andjest.useRealTimers()calls from this test and others.