Skip to content

test: add comprehensive unit tests for formatting utilities and updat… - #276

Open
Unclebaffa wants to merge 1 commit into
RemitFlow:mainfrom
Unclebaffa:feature/unit-tests-format-utils
Open

test: add comprehensive unit tests for formatting utilities and updat…#276
Unclebaffa wants to merge 1 commit into
RemitFlow:mainfrom
Unclebaffa:feature/unit-tests-format-utils

Conversation

@Unclebaffa

Copy link
Copy Markdown
Contributor

📝 Comprehensive Summary of Implementation

1. Formatting Utilities Unit Test Suite (format.test.js)

Expanded unit test coverage from 3 basic functions to 26 unit tests covering all 7 functions exported by src/utils/format.js:

  • formatAmount:
    • Default en-US formatting ($1,234.50).
    • Custom locales (fr-FR decimal/grouping separators, en-GB pound symbol placement).
    • Fallback to $0.00 for non-numeric amounts ('not-a-number').
    • Numeric string inputs ('100.5' -> $100.50).
    • Defaulting omitted locale arguments.
  • formatDate:
    • Default en-US date formatting (Jul 15, 2026).
    • Custom locales (15 juil. 2026 for fr-FR).
    • Missing value placeholders ('-') for null, undefined, or empty string ''.
    • Date objects and numeric timestamps.
  • formatRate:
    • 4-decimal place rate formatting (1 USD = 294.6200 NGN).
    • Placeholder handling ('-') for null or undefined rates.
  • formatCurrencyInput:
    • Empty output ('') for null, undefined, empty string '', or single period '.'.
    • Stripping non-numeric characters and formatting to 2 decimal places ('1,234.5' -> '1234.50', '$100.5' -> '100.50').
    • Number and numeric string inputs.
    • Empty string output ('') for non-numeric input strings ('abc').
  • formatPercent:
    • Ratio to percentage conversion with 2 decimal places default (0.005 -> '0.50%').
    • Custom decimal places (formatPercent(0.005, 1) -> '0.5%').
    • Fallbacks to '0.00%' for invalid/missing inputs.
  • formatNumber:
    • Default en-US grouping (1,234.5).
    • Custom locale grouping and decimal separators (fr-FR).
    • Fallbacks to '0' for non-numeric inputs.
  • shortenAddress:
    • Default Stellar public key truncation (GBQAZ7...CDEF).
    • Custom head and tail lengths (shortenAddress(address, 4, 3) -> GBQA...DEF).
    • Preservation of strings where length $\le$ head + tail.
    • Placeholder ('-') for empty, null, or undefined inputs.

2. Documentation Updates (README.md)

  • Documented the unit test suite for formatting utilities under the Testing section in README.md.

3. Code Quality & Verification

  • Vitest Suite: All 26 unit tests in test/unit/format.test.js passed (and 144/144 tests passed across the complete test suite).
  • ESLint (npm run lint): 0 errors, 0 warnings.
  • Prettier (npm run format:check): 100% code style compliant.

Closes #9

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.

Add unit tests for the formatting utilities

1 participant