Skip to content

Commit

Permalink
🐛 fix: sortablelist control error
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Mar 11, 2024
1 parent d41ed46 commit 28ea1d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/SortableList/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<SortableList
value={list}
onChange={(value) => {
console.log('change value', value);
setList(value);
}}
SHOW_STORE_IN_DEVTOOLS
/>
<Button
type="primary"
onClick={() => {
setList(['foo', 'bar', 'yes']);
}}
style={{ marginTop: 8 }}
>
Set Data
</Button>
</>
);
};

describe('SortableList', () => {
it('toggleSetData', () => {
const { getByText } = render(<Demo />);
const setDataButton = getByText('Set Data');
act(() => {
fireEvent.click(setDataButton);
});
expect(getByText('foo')).toBeInTheDocument();
expect(getByText('bar')).toBeInTheDocument();
expect(getByText('yes')).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/SortableList/container/StoreUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 28ea1d8

Please sign in to comment.