-
Notifications
You must be signed in to change notification settings - Fork 395
[ui-sb] add test for file upload hooks #4138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
✅ Test files were modified. Ensure that the tests cover all relevant changes. ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds tests for file upload hooks to improve coverage for both regular and chunked uploads while refining some test naming for clarity. Key changes include:
- Updates to the useSaveData and useLoadData test files to improve error and state handling tests.
- Addition of new test suites for useRegularUpload, useFileUpload, and useChunkUpload.
- A minor refactor in the useChunkUpload hook to correct an import for GET_TASKS_URL.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
desktop/core/src/desktop/js/utils/hooks/useSaveData/useSaveData.test.tsx | Updated test naming and moved mockPost initialization |
desktop/core/src/desktop/js/utils/hooks/useLoadData/useLoadData.test.tsx | Added tests for reload behavior and polling intervals |
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useRegularUpload.test.tsx | Added tests for regular file upload handling and state updates |
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useFileUpload.test.tsx | Added tests for file upload type selection and cancellation |
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useChunkUpload.ts | Refactored GET_TASKS_URL import |
desktop/core/src/desktop/js/utils/hooks/useFileUpload/useChunkUpload.test.tsx | Added tests to validate chunk upload processing and error handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, see comments for some smaller improvements
|
||
result.current.addFiles([mockFile]); | ||
|
||
expect(mockSave).toHaveBeenCalledWith(expect.any(FormData), expect.any(Object)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use any, why not make sure it is called with the actual data?
expect(mockUpdateFileVariables.mock.calls).toEqual( | ||
expect.arrayContaining([ | ||
[mockFile.uuid, { status: FileStatus.Uploading }], | ||
[mockFile.uuid, { status: FileStatus.Failed, error: expect.any(Error) }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Check that it is the expected error
'Upload server ran out of space. Try again later.'
it('returns isLoading as true if either upload method is loading', () => { | ||
mockLoading.mockReturnValue(true); | ||
const { result } = renderHook(() => | ||
useFileUpload({ isChunkUpload: false, onComplete: mockOnComplete }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test state "either upload method" but only non chunked method is tested here
})); | ||
|
||
describe('useFileUpload', () => { | ||
const mockOnComplete = jest.fn(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never test that this mock is actually called. Shouldn't we?
})) | ||
})); | ||
|
||
describe('useFileUpload', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about tests for failing uploads?
What changes were proposed in this pull request?
How was this patch tested?
Please review Hue Contributing Guide before opening a pull request.