-
Notifications
You must be signed in to change notification settings - Fork 34
[-]:feat/checkout little improves #1963
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8283456
feat: update renewal label
jaaaaavier d0ef7a4
updates for review
jaaaaavier f309b3d
Merge branch 'master' into feat/fix-checkout
jaaaaavier 81a7846
Merge branch 'master' into feat/fix-checkout
jaaaaavier 516220a
update test
jaaaaavier 86ef365
Update formatPrice.test.ts
jaaaaavier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,34 +1,34 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { describe, it, test, expect } from 'vitest'; | ||
| import { formatPrice } from './formatPrice'; | ||
|
|
||
| describe('Formatting the price to have 2 decimals', () => { | ||
| it('When the price does not have decimals, the function returns it without .00', () => { | ||
| expect(formatPrice(10)).toBe('10'); | ||
| }); | ||
|
|
||
| describe('The value has less or exactly 2 decimals', () => { | ||
| it('When the user has a price with 1 decimal, the function returns 2 decimals (100.5 -> 100.50)', () => { | ||
| expect(formatPrice(100.5)).toBe('100.50'); | ||
| }); | ||
| it('When the user has a price with 1 decimal, the function returns 2 decimals (100.5 -> 100.50)', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use test |
||
| expect(formatPrice(100.5)).toBe('100.50'); | ||
| }); | ||
|
|
||
| it('When the user has a price with 2 decimals, the function returns 2 decimals (99.99 -> 99.99)', () => { | ||
| expect(formatPrice(99.99)).toBe('99.99'); | ||
| }); | ||
| it('When the user has a price with 2 decimals, the function returns 2 decimals (99.99 -> 99.99)', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use test |
||
| expect(formatPrice(99.99)).toBe('99.99'); | ||
| }); | ||
|
|
||
| it('When the price is just 1 decimal and it is a 0, then the function returns without .00', () => { | ||
| expect(formatPrice(20.0)).toBe('20'); | ||
| }); | ||
|
|
||
| describe('The price has more than 2 decimals', () => { | ||
| it('When the price has more than 2 decimals, then the function returns the price with 2 decimals (truncated with high precision, 10.456 -> 10.45 - 10.001 -> 10 - 1.999 -> 1.99)', () => { | ||
| expect(formatPrice(10.456)).toBe('10.45'); | ||
| expect(formatPrice(10.001)).toBe('10'); | ||
| expect(formatPrice(1.999)).toBe('1.99'); | ||
| }); | ||
| test('When the price has more than 2 decimals, then the function returns the price rounded to 2 decimals (10.456 -> 10.46 - 10.001 -> 10 - 1.999 -> 2)', () => { | ||
| expect(formatPrice(10.456)).toBe('10.46'); | ||
| expect(formatPrice(10.001)).toBe('10'); | ||
| expect(formatPrice(1.999)).toBe('2'); | ||
| }); | ||
|
|
||
| it('Handles edge case where value is nearly integer due to float error', () => { | ||
| test('When the value is nearly integer due to float error, then it returns without decimals', () => { | ||
| expect(formatPrice(10.0000001)).toBe('10'); | ||
| }); | ||
|
|
||
| test('When there is a floating point precision error (19.99 * 100 = 1998.999... in JS), then it returns 2 decimals', () => { | ||
| expect(formatPrice(19.99)).toBe('19.99'); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| export const formatPrice = (price: number) => { | ||
| const truncated = Math.floor(Number(price.toFixed(8)) * 100) / 100; | ||
| const truncated = Math.round(Number(price.toFixed(8)) * 100) / 100; | ||
| const formatted = truncated.toFixed(2); | ||
| return formatted.endsWith('.00') ? String(truncated) : formatted; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the text for all languages.