Skip to content
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

Add comprehensive tests for currencyToAmount in util.ts #4490

Closed
coderabbitai bot opened this issue Mar 1, 2025 · 0 comments · Fixed by #4503
Closed

Add comprehensive tests for currencyToAmount in util.ts #4490

coderabbitai bot opened this issue Mar 1, 2025 · 0 comments · Fixed by #4503
Assignees

Comments

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2025

Background

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

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

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 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 a pull request may close this issue.

1 participant