Skip to content

Add unit tests for pure utility functions in useMobileUpload #16

Description

@kanweiwei

web/hooks/useMobileUpload.ts contains several pure utility functions that are easily testable without any React rendering:

Current exported functions (paths and line numbers verified 2026-09 after the Next.js App Router restructure):

  • formatFileSize() (line 39) — formats bytes to human-readable sizes
  • isFilePickerSupported() (line 46) — checks API support
  • isIOSSafari() (line 50) — browser detection
  • isMobileDevice() (line 55) — mobile detection

Internal helpers fileId(), selectWithInput(), and summarize() are worth covering indirectly through the hook's public behavior.

What to do:

  1. Create web/hooks/__tests__/useMobileUpload.test.ts
  2. Write tests for each exported function, covering edge cases:
    • formatFileSize(0), negative values, very large values
    • detection helpers under different user-agent mocks
  3. Run: cd web && pnpm test:run hooks/__tests__/useMobileUpload.test.ts

Skills needed: TypeScript, Vitest

Estimated time: 1-2 hours

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions