-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatting fixes to Grant Details page (#2734)
* Add currency formatting helper * Utilize new formatCurrency helper * Titleize the opportunity status * Fix agency code name
- Loading branch information
1 parent
95e29f4
commit 8eb4fa6
Showing
4 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const currencyFormatter = new Intl.NumberFormat('en-US', { | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
style: 'currency', | ||
currency: 'USD', | ||
currencyDisplay: 'narrowSymbol', | ||
}); | ||
|
||
export function formatCurrency(value) { | ||
if (value === undefined || value === null) { | ||
return ''; | ||
} | ||
return currencyFormatter.format(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { expect } from 'chai'; | ||
import { formatCurrency } from '@/helpers/currency'; | ||
|
||
describe('currency helpers', () => { | ||
describe('formatCurrency', () => { | ||
it('formats basic currency value', () => { | ||
expect(formatCurrency(1.23)).equals('$1.23'); | ||
}); | ||
it('formats large currency value', () => { | ||
expect(formatCurrency(123456789.00)).equals('$123,456,789.00'); | ||
}); | ||
it('formats whole numbers with cents', () => { | ||
expect(formatCurrency(1)).equals('$1.00'); | ||
}); | ||
it('formats sub-cent values to the cent', () => { | ||
expect(formatCurrency(1.23456)).equals('$1.23'); | ||
}); | ||
it('formats negative values', () => { | ||
expect(formatCurrency(-1.23)).equals('-$1.23'); | ||
}); | ||
it('formats zero', () => { | ||
expect(formatCurrency(0)).equals('$0.00'); | ||
}); | ||
it('formats undefined/null values', () => { | ||
expect(formatCurrency(null)).equals(''); | ||
expect(formatCurrency(undefined)).equals(''); | ||
}); | ||
}); | ||
}); |