[GH-ISSUE #4490] Add comprehensive tests for currencyToAmount in util.ts #8847

Closed
opened 2026-04-10 19:08:31 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @coderabbitai[bot] on GitHub (Mar 1, 2025).
Original GitHub issue: https://github.com/actualbudget/actual/issues/4490

Background

The currencyToAmount function in packages/loot-core/src/shared/util.ts has been the source of several bugs recently:

  • PR #4383 fixed an issue where the function expected a string in the current number format
  • PR #4489 fixed a regression related to parsing negative amounts

Currently, there are tests for looselyParseAmount and number formatting functions in util.test.ts, but none specifically for currencyToAmount. This is a critical utility function that handles currency string parsing throughout the application.

Objective

Add comprehensive unit tests for the currencyToAmount function covering:

  • Handling of different number formats (comma-dot, dot-comma, space-comma, apostrophe-dot, comma-dot-in)
  • Proper parsing of negative amounts (both with minus sign and parentheses)
  • Edge cases like leading zeros, only decimal part, etc.
  • Handling of invalid inputs

Suggested Test Cases

Test cases should include but not be limited to:

  • Basic positive amounts with various formats
  • Negative amounts (both with minus sign and parentheses)
  • Amount strings with no decimal part
  • Amount strings with only decimal part (e.g., .45)
  • Strings with incorrect format (e.g., using dot in dot-comma format)
  • Invalid inputs (non-numeric strings)

This will help prevent regressions and ensure consistent behavior across the application.

Originally created by @coderabbitai[bot] on GitHub (Mar 1, 2025). Original GitHub issue: https://github.com/actualbudget/actual/issues/4490 ## Background The `currencyToAmount` function in `packages/loot-core/src/shared/util.ts` has been the source of several bugs recently: - PR #4383 fixed an issue where the function expected a string in the current number format - PR #4489 fixed a regression related to parsing negative amounts Currently, there are tests for `looselyParseAmount` and number formatting functions in `util.test.ts`, but none specifically for `currencyToAmount`. This is a critical utility function that handles currency string parsing throughout the application. ## Objective Add comprehensive unit tests for the `currencyToAmount` function covering: - Handling of different number formats (comma-dot, dot-comma, space-comma, apostrophe-dot, comma-dot-in) - Proper parsing of negative amounts (both with minus sign and parentheses) - Edge cases like leading zeros, only decimal part, etc. - Handling of invalid inputs ## Related PRs and Issues - https://github.com/actualbudget/actual/pull/4383 - Original fix for currency conversion - https://github.com/actualbudget/actual/pull/4489 - Fix for negative amount parsing - https://github.com/actualbudget/actual/issues/4487 - Issue that revealed the negative amount parsing bug ## Suggested Test Cases Test cases should include but not be limited to: - Basic positive amounts with various formats - Negative amounts (both with minus sign and parentheses) - Amount strings with no decimal part - Amount strings with only decimal part (e.g., `.45`) - Strings with incorrect format (e.g., using dot in dot-comma format) - Invalid inputs (non-numeric strings) This will help prevent regressions and ensure consistent behavior across the application.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#8847