Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 2e812bc

Browse files
committed
✅ test: 添加单测
1 parent fda5d6e commit 2e812bc

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

packages/sortable-list/src/container/Wrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FC } from 'react';
33

44
import { Provider, createStore, useStoreApi } from '../store';
55

6-
const SortableListWrapper: FC = ({ children }) => {
6+
const StoreWrapper: FC = ({ children }) => {
77
let isWrapped = true;
88

99
try {
@@ -21,4 +21,4 @@ const SortableListWrapper: FC = ({ children }) => {
2121
return <Provider createStore={createStore}>{children}</Provider>;
2222
};
2323

24-
export default SortableListWrapper;
24+
export default StoreWrapper;

packages/sortable-list/src/container/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import { Sortable } from './App';
1818
import type { SortableItemList, SortableListProps } from '../types';
19-
import SortableListWrapper from './Wrapper';
19+
import StoreWrapper from './Wrapper';
2020
import StoreUpdater from './StoreUpdater';
2121

2222
const defaultDropAnimationConfig: DropAnimation = {
@@ -77,7 +77,7 @@ function SortableList<T extends SortableItemList = SortableItemList>({
7777
}, [direction, getModifiers]);
7878

7979
return (
80-
<SortableListWrapper>
80+
<StoreWrapper>
8181
<Sortable
8282
direction={direction}
8383
dropAnimation={defaultDropAnimationConfig}
@@ -90,7 +90,7 @@ function SortableList<T extends SortableItemList = SortableItemList>({
9090
gap={gap}
9191
/>
9292
<StoreUpdater onDataChange={onChange} data={dataSource} />
93-
</SortableListWrapper>
93+
</StoreWrapper>
9494
);
9595
}
9696

packages/sortable-list/tests/__snapshots__/index.test.tsx.snap

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`SortableList 有数据 1`] = `
4+
<div>
5+
<div
6+
class="sc-bdvvtL jXutGz avx-sortable-list layoutkit-flexbox"
7+
>
8+
<li
9+
class="avx-sortable-item-container"
10+
>
11+
<div
12+
aria-describedby="DndDescribedBy-1"
13+
aria-roledescription="sortable"
14+
class="avx-sortable-item"
15+
data-id="1"
16+
data-index="0"
17+
role="button"
18+
tabindex="0"
19+
>
20+
1
21+
<span
22+
class="avx-sortable-action"
23+
>
24+
<button
25+
class="avx-sortable-action-remove"
26+
tabindex="0"
27+
>
28+
<svg
29+
viewBox="0 0 22 22"
30+
width="8"
31+
xmlns="http://www.w3.org/2000/svg"
32+
>
33+
<path
34+
d="M2.99998 -0.000206962C2.7441 -0.000206962 2.48794 0.0972617 2.29294 0.292762L0.292945 2.29276C-0.0980552 2.68376 -0.0980552 3.31682 0.292945 3.70682L7.58591 10.9998L0.292945 18.2928C-0.0980552 18.6838 -0.0980552 19.3168 0.292945 19.7068L2.29294 21.7068C2.68394 22.0978 3.31701 22.0978 3.70701 21.7068L11 14.4139L18.2929 21.7068C18.6829 22.0978 19.317 22.0978 19.707 21.7068L21.707 19.7068C22.098 19.3158 22.098 18.6828 21.707 18.2928L14.414 10.9998L21.707 3.70682C22.098 3.31682 22.098 2.68276 21.707 2.29276L19.707 0.292762C19.316 -0.0982383 18.6829 -0.0982383 18.2929 0.292762L11 7.58573L3.70701 0.292762C3.51151 0.0972617 3.25585 -0.000206962 2.99998 -0.000206962Z"
35+
/>
36+
</svg>
37+
</button>
38+
</span>
39+
</div>
40+
</li>
41+
<li
42+
class="avx-sortable-item-container"
43+
>
44+
<div
45+
aria-describedby="DndDescribedBy-1"
46+
aria-roledescription="sortable"
47+
class="avx-sortable-item"
48+
data-id="2"
49+
data-index="1"
50+
role="button"
51+
tabindex="0"
52+
>
53+
2
54+
<span
55+
class="avx-sortable-action"
56+
>
57+
<button
58+
class="avx-sortable-action-remove"
59+
tabindex="0"
60+
>
61+
<svg
62+
viewBox="0 0 22 22"
63+
width="8"
64+
xmlns="http://www.w3.org/2000/svg"
65+
>
66+
<path
67+
d="M2.99998 -0.000206962C2.7441 -0.000206962 2.48794 0.0972617 2.29294 0.292762L0.292945 2.29276C-0.0980552 2.68376 -0.0980552 3.31682 0.292945 3.70682L7.58591 10.9998L0.292945 18.2928C-0.0980552 18.6838 -0.0980552 19.3168 0.292945 19.7068L2.29294 21.7068C2.68394 22.0978 3.31701 22.0978 3.70701 21.7068L11 14.4139L18.2929 21.7068C18.6829 22.0978 19.317 22.0978 19.707 21.7068L21.707 19.7068C22.098 19.3158 22.098 18.6828 21.707 18.2928L14.414 10.9998L21.707 3.70682C22.098 3.31682 22.098 2.68276 21.707 2.29276L19.707 0.292762C19.316 -0.0982383 18.6829 -0.0982383 18.2929 0.292762L11 7.58573L3.70701 0.292762C3.51151 0.0972617 3.25585 -0.000206962 2.99998 -0.000206962Z"
68+
/>
69+
</svg>
70+
</button>
71+
</span>
72+
</div>
73+
</li>
74+
</div>
75+
</div>
76+
`;
77+
378
exports[`SortableList 默认状态 1`] = `
479
<div>
580
<div

packages/sortable-list/tests/index.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ describe('SortableList', () => {
88
const { container } = render(<SortableList />);
99
expect(container).toMatchSnapshot();
1010
});
11+
it('有数据', () => {
12+
const { container } = render(
13+
<SortableList dataSource={[{ id: '1' }, { id: '2' }]} />,
14+
);
15+
expect(container).toMatchSnapshot();
16+
});
1117
});

0 commit comments

Comments
 (0)