From 28ea1d8ebf8281e9dfd68d203c505c6118a70405 Mon Sep 17 00:00:00 2001 From: rdmclin2 Date: Mon, 11 Mar 2024 17:41:42 +0800 Subject: [PATCH] :bug: fix: sortablelist control error --- src/SortableList/__tests__/index.test.tsx | 43 +++++++++++++++++++++ src/SortableList/container/StoreUpdater.tsx | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/SortableList/__tests__/index.test.tsx diff --git a/src/SortableList/__tests__/index.test.tsx b/src/SortableList/__tests__/index.test.tsx new file mode 100644 index 00000000..d524508f --- /dev/null +++ b/src/SortableList/__tests__/index.test.tsx @@ -0,0 +1,43 @@ +import { act, fireEvent, render } from '@testing-library/react'; +import { Button } from 'antd'; +import { useState } from 'react'; +import { SortableList } from '../index'; + +const Demo = () => { + const [list, setList] = useState(['hello', 'world']); + + return ( + <> + { + console.log('change value', value); + setList(value); + }} + SHOW_STORE_IN_DEVTOOLS + /> + + + ); +}; + +describe('SortableList', () => { + it('toggleSetData', () => { + const { getByText } = render(); + const setDataButton = getByText('Set Data'); + act(() => { + fireEvent.click(setDataButton); + }); + expect(getByText('foo')).toBeInTheDocument(); + expect(getByText('bar')).toBeInTheDocument(); + expect(getByText('yes')).toBeInTheDocument(); + }); +}); diff --git a/src/SortableList/container/StoreUpdater.tsx b/src/SortableList/container/StoreUpdater.tsx index fee7861d..6a633a19 100644 --- a/src/SortableList/container/StoreUpdater.tsx +++ b/src/SortableList/container/StoreUpdater.tsx @@ -48,7 +48,7 @@ const StoreUpdater = forwardRef( useStoreUpdater('initialValues', initialValues, [], (state) => { KeyManagerUpdater(state, 'initialValues'); }); - useStoreUpdater('value', value, [], (state) => { + useStoreUpdater('value', value, [value], (state) => { KeyManagerUpdater(state, 'value'); }); useStoreUpdater('actions', actions);