Skip to content

test(image-uploader): add unit tests - #288

Merged
Komoszek merged 1 commit into
mainfrom
test/image-uploader
Jun 25, 2026
Merged

Komoszek merged 1 commit into
mainfrom
test/image-uploader

Conversation

@claude

@claude claude Bot commented Jun 25, 2026

Copy link
Copy Markdown

Requested by Sebastian Konowrocki · Slack thread

Before / After

The @leancodepl/image-uploader package previously had no tests. This PR adds 47 unit tests (6 spec files) covering the package's real runtime logic:

  • mapFileRejectionsToErrorCode / ErrorCode — code mapping, priority ordering (FileTooLarge > FileTooSmall > FileInvalidType > TooManyFiles), empty/unknown rejections, multi-rejection flattening.
  • isExactFile — name/size/lastModified equality across matching and differing inputs.
  • getImagePreviewData — base64 data URL output, MIME-type prefix preservation, empty input, and FileReader error rejection.
  • tryUploadWithUploadParams — already-uploaded short-circuit, missing file, successful fetch upload, and the error paths (null params, non-ok response, fetch rejection, getUploadParams rejection).
  • useUploadImages — accept defaulting/pass-through, add/dedup/remove/clear file flows, drop handling with generated ids, rejection-to-error mapping, optional-callback safety, and cropper config exposure.
  • useCropper — queue/open state, FileReader-driven editorImage loading, close-and-advance vs close-and-empty, acceptImage append behavior, and crop/zoom/rotation setters.

How

Vitest + jsdom following sibling-package conventions (@testing-library/react renderHook/act, vi.mock for react-dropzone/uuid); fetch and FileReader are stubbed where needed. Added @testing-library/react, react, and vitest to the package's devDependencies to satisfy the import lint rule.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR


Generated by Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@claude
claude Bot marked this pull request as ready for review June 25, 2026 09:35
@Komoszek
Komoszek merged commit 246ee1b into main Jun 25, 2026
1 check passed
@Komoszek
Komoszek deleted the test/image-uploader branch June 25, 2026 12:45
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