Skip to content

Commit

Permalink
test: fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 23, 2024
1 parent 04f3e57 commit 752ca5f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"rc-dialog": "^7.5.7",
"rc-field-form": "^1.0.0",
"rc-test": "^7.0.4",
"rc-virtual-list": "^1.1.0",
"rc-virtual-list": "^3.0.0",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"typescript": "^5.0.0"
Expand Down
55 changes: 18 additions & 37 deletions tests/Select.props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { mount } from 'enzyme';
import Tree, { TreeNode } from 'rc-tree';
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { render, fireEvent } from '@testing-library/react';

import TreeSelect, { SHOW_ALL, SHOW_CHILD, SHOW_PARENT, TreeNode as SelectNode } from '../src';

Expand Down Expand Up @@ -245,45 +244,27 @@ describe('TreeSelect.props', () => {
});

it('onPopupScroll', async () => {
const handleScroll = jest.fn();
// act(() => {
const onPopupScroll = jest.fn();
render(
<TreeSelect open treeDefaultExpandAll onPopupScroll={handleScroll}>
<SelectNode value="Value 0" title="Title 0">
<SelectNode value="Value 0-0" title="Title 0-0" />
<SelectNode value="Value 0-1" title="Title 0-1" />
<SelectNode value="Value 0-2" title="Title 0-2" />
</SelectNode>

<SelectNode value="Value 1" title="Title 1">
<SelectNode value="Value 1-0" title="Title 1-0" />
<SelectNode value="Value 1-1" title="Title 1-1" />
<SelectNode value="Value 1-2" title="Title 1-2" />
</SelectNode>

<SelectNode value="Value 2" title="Title 2">
<SelectNode value="Value 2-0" title="Title 2-0" />
<SelectNode value="Value 2-1" title="Title 2-1" />
<SelectNode value="Value 2-2" title="Title 2-2" />
</SelectNode>

<SelectNode value="Value 3" title="Title 3">
<SelectNode value="Value 3-0" title="Title 3-0" />
<SelectNode value="Value 3-1" title="Title 3-1" />
<SelectNode value="Value 3-2" title="Title 3-2" />
</SelectNode>
</TreeSelect>,
<TreeSelect
open
treeDefaultExpandAll
onPopupScroll={onPopupScroll}
treeData={new Array(10).fill(0).map((_, index) => ({
title: `Title ${index}`,
value: index,
}))}
/>,
);
// });

await waitFor(
() =>
expect(document.body.querySelector('.rc-tree-select-tree-list')).toBeTruthy(),
// expect(document.body.querySelector('.rc-tree-select-tree-list-holder')).toBeTruthy(),
{ timeout: 2000 },
);
fireEvent.scroll(document.querySelector('.rc-tree-select-tree-list-holder'), {
scrollY: 100,
});

expect(document.body).toMatchSnapshot();
expect(onPopupScroll).toHaveBeenCalled();
expect(onPopupScroll.mock.calls[0][0].target).toBe(
document.querySelector('.rc-tree-select-tree-list-holder'),
);
});

it('showArrow', () => {
Expand Down

0 comments on commit 752ca5f

Please sign in to comment.