-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test]:(DataSourceComparison) Add unit tests
- Loading branch information
Showing
33 changed files
with
8,020 additions
and
32 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
packages/shared/lib/components/BasicTreeSelect/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
95
packages/shared/lib/components/BasicTreeSelect/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.