Skip to content

Commit

Permalink
fix(storagemanager): upload action now displays state properly (#4666)
Browse files Browse the repository at this point in the history
Co-authored-by: Caleb Pollman <[email protected]>
  • Loading branch information
dbanksdesign and calebpollman authored Nov 16, 2023
1 parent 7f887f5 commit d4b3ca5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function StorageManagerExample() {
acceptedFileTypes={['image/*']}
accessLevel="guest"
autoUpload={false}
maxFileCount={1}
maxFileCount={10}
showThumbnails
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,59 @@ describe('storageManagerStateReducer', () => {

expect(result.current.state.files).toEqual([file]);
});

it('should only change added files to queued in QUEUE_FILES action', () => {
const { result } = renderHook(() => {
const [state, dispatch] = useReducer(storageManagerStateReducer, {
files: [
{
id: imageFile.name,
file: imageFile,
error: '',
key: imageFile.name,
status: FileStatus.ADDED,
isImage: true,
progress: -1,
},
{
id: imageFile.name,
file: imageFile,
error: '',
key: imageFile.name,
status: FileStatus.UPLOADED,
isImage: true,
progress: 100,
},
],
});
return { state, dispatch };
});

const queueFilesAction: Action = {
type: StorageManagerActionTypes.QUEUE_FILES,
};

act(() => result.current.dispatch(queueFilesAction));

expect(result.current.state.files).toEqual([
{
id: imageFile.name,
file: imageFile,
error: '',
key: imageFile.name,
status: FileStatus.QUEUED,
isImage: true,
progress: -1,
},
{
id: imageFile.name,
file: imageFile,
error: '',
key: imageFile.name,
status: FileStatus.UPLOADED,
isImage: true,
progress: 100,
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export function storageManagerStateReducer(
...files,
{
...currentFile,
status: FileStatus.QUEUED,
...(currentFile.status === FileStatus.ADDED
? { status: FileStatus.QUEUED }
: {}),
},
];
}, []);
Expand Down

0 comments on commit d4b3ca5

Please sign in to comment.