Skip to content

[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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ramprasadagarwal
Copy link
Collaborator

@ramprasadagarwal ramprasadagarwal commented May 8, 2025

What changes were proposed in this pull request?

  • Add tests for the file upload hooks

How was this patch tested?

  • Added unit tests

Please review Hue Contributing Guide before opening a pull request.

Copy link

github-actions bot commented May 8, 2025

✅ Test files were modified. Ensure that the tests cover all relevant changes. ✅

@ramprasadagarwal ramprasadagarwal self-assigned this May 8, 2025
Copy link

github-actions bot commented May 8, 2025

Python Code Coverage

Python Coverage Report •
FileStmtsMissCoverMissing
TOTAL537732702149% 
report-only-changed-files is enabled. No files were changed during this commit :)

Pytest Report

Tests Skipped Failures Errors Time
1097 106 💤 0 ❌ 0 🔥 5m 54s ⏱️

@ramprasadagarwal ramprasadagarwal requested a review from Copilot May 29, 2025 10:54
Copy link

@Copilot Copilot AI left a 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

@ramprasadagarwal ramprasadagarwal marked this pull request as ready for review May 29, 2025 10:57
Copy link
Collaborator

@bjornalm bjornalm left a 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));
Copy link
Collaborator

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) }]
Copy link
Collaborator

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 })
Copy link
Collaborator

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();
Copy link
Collaborator

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', () => {
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants