Skip to content
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]:(DataSourceComparison) Add unit tests #514

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BasicTreeSelect should render the not found content when loading is true 1`] = `
<div
class="css-1unimto"
data-testid="basic-tree-select-popup-menu-style-wrapper"
>
<div>
<div
class="ant-select-tree"
role="tree"
>
<div>
<input
aria-label="for screen reader"
disabled=""
style="width: 0px; height: 0px; display: flex; overflow: hidden; opacity: 0; border: 0px; padding: 0px; margin: 0px;"
value=""
/>
</div>
<div
aria-hidden="true"
class="ant-select-tree-treenode"
style="position: absolute; pointer-events: none; visibility: hidden; height: 0px; overflow: hidden; border: 0px; padding: 0px;"
>
<div
class="ant-select-tree-indent"
>
<div
class="ant-select-tree-indent-unit"
/>
</div>
</div>
<div
class="ant-select-tree-list"
style="position: relative;"
>
<div
class="ant-select-tree-list-holder"
style="max-height: 256px; overflow-y: hidden;"
>
<div>
<div
class="ant-select-tree-list-holder-inner"
style="display: flex; flex-direction: column;"
>
<div
aria-grabbed="false"
class="ant-select-tree-treenode ant-select-tree-treenode-switcher-close ant-select-tree-treenode-leaf-last"
draggable="false"
>
<span
aria-hidden="true"
class="ant-select-tree-indent"
/>
<span
class="ant-select-tree-switcher ant-select-tree-switcher_close"
>
<svg
class="ant-select-tree-switcher-icon"
height="16"
viewBox="0 0 14 14"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.684 7 4.796 4.112l.825-.824L9.334 7 5.62 10.712l-.825-.825z"
/>
</svg>
</span>
<span
class="ant-select-tree-node-content-wrapper ant-select-tree-node-content-wrapper-close"
title="parent 1"
>
<span
class="ant-select-tree-title"
>
parent 1
</span>
</span>
</div>
</div>
</div>
</div>
<div
class="ant-select-tree-list-scrollbar"
style="width: 8px; top: 0px; bottom: 0px; right: 0px; position: absolute; display: none;"
>
<div
class="ant-select-tree-list-scrollbar-thumb"
style="width: 100%; height: 128px; top: 0px; left: 0px; position: absolute; background: rgba(0, 0, 0, 0.5); border-radius: 99px; cursor: pointer; user-select: none;"
/>
</div>
</div>
</div>
</div>
</div>
`;
95 changes: 95 additions & 0 deletions packages/shared/lib/components/BasicTreeSelect/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { fireEvent, screen } from '@testing-library/dom';
import BasicTreeSelect from '.';
import { superRender } from '../../testUtil/customRender';
import { getBySelector } from '../../testUtil/customQuery';

describe('BasicTreeSelect', () => {
const mockProps = {
className: 'custom-class',
allowClear: true,
loading: false,
popupClassName: 'custom-popup-class',
treeData: [
{
value: 'parent 1',
title: 'parent 1',
children: [
{
value: 'parent 1-0',
title: 'parent 1-0',
children: [
{
value: 'leaf1',
title: 'leaf1'
},
{
value: 'leaf2',
title: 'leaf2'
},
{
value: 'leaf3',
title: 'leaf3'
},
{
value: 'leaf4',
title: 'leaf4'
},
{
value: 'leaf5',
title: 'leaf5'
},
{
value: 'leaf6',
title: 'leaf6'
}
]
},
{
value: 'parent 1-1',
title: 'parent 1-1',
children: [
{
value: 'leaf11',
title: <b style={{ color: '#08c' }}>leaf11</b>
}
]
}
]
}
]
};

it('should render the component with all elements', () => {
superRender(<BasicTreeSelect {...mockProps} />);

expect(screen.getByText('请选择{{name}}')).toBeInTheDocument();
expect(screen.getByRole('combobox')).toBeInTheDocument();
expect(getBySelector('.basic-tree-select-wrapper')).toHaveClass(
'custom-class'
);
});

it('should render the dropdown menu correctly', () => {
superRender(<BasicTreeSelect {...mockProps} />);

const treeSelect = screen.getByRole('combobox');
fireEvent.mouseDown(treeSelect);

const customMenu = screen.getByTestId(
'basic-tree-select-popup-menu-style-wrapper'
);
expect(customMenu).toBeInTheDocument();
});

it('should render the not found content when loading is true', () => {
superRender(<BasicTreeSelect {...mockProps} loading={true} />);

const treeSelect = screen.getByRole('combobox');
fireEvent.mouseDown(treeSelect);

const customMenu = screen.getByTestId(
'basic-tree-select-popup-menu-style-wrapper'
);
expect(customMenu).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion packages/shared/lib/components/BasicTreeSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BasicTreeSelect = <V extends string | number>(
const renderDropdown: TreeSelectProps['dropdownRender'] = (menu) => {
const customMenu = (
<>
<BasicTreeSelectPopupMenuStyleWrapper>
<BasicTreeSelectPopupMenuStyleWrapper data-testid="basic-tree-select-popup-menu-style-wrapper">
{menu}
</BasicTreeSelectPopupMenuStyleWrapper>
</>
Expand Down
Loading