-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix percentage render * add tests
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"web": patch | ||
--- | ||
|
||
Fix rendering of percentages that we don't lose a decimal place and mis-render any percentages" |
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,61 @@ | ||
import { test, expect } from '@playwright/experimental-ct-react17'; | ||
|
||
import { toHumanInterest } from './dineroUtils'; | ||
|
||
test.describe(`toHumaan`, () => { | ||
test.describe('toHumanInterest', () => { | ||
test(`leading zero on only decimals`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 100, | ||
scale: -5, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('0.1%'); | ||
}); | ||
|
||
test(`no dot on 10s`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 10000, | ||
scale: -5, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('10%'); | ||
}); | ||
|
||
test(`no dot on whole number`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 28000, | ||
scale: -5, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('28%'); | ||
}); | ||
|
||
test(`no dot on single whole number`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 1000, | ||
scale: -5, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('1%'); | ||
}); | ||
|
||
test(`works with larger decimals`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 875, | ||
scale: -5, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('0.875%'); | ||
}); | ||
|
||
test(`works with whole + decimals`, () => { | ||
const humanInterest = toHumanInterest({ | ||
amount: 87567, | ||
scale: -6, | ||
trailingSymbol: '%' | ||
}); | ||
expect(humanInterest).toBe('8.7567%'); | ||
}); | ||
}); | ||
}); |
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