Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
},
"apply": "Apply",
"taxes": "Taxes",
"annualBillingTemplate": "Annual plan, billed monthly at {{price}}{{currency}}/month for 12 months"
"annualBillingTemplate": "Annual plan, billed at {{currency}}{{priceNow}} for the first month, then renews at {{currency}}{{price}}/month"
Copy link
Copy Markdown
Contributor

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.

},
"confirmCryptoPayment": {
"title": "Confirm the payment",
Expand Down
2 changes: 1 addition & 1 deletion src/views/Checkout/components/CheckoutProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const CheckoutProductCard = ({
</div>
</div>
{priceData.interval === 'month' && (
<p className="text-gray-60">
<p className="text-gray-60 text-sm">
{translate('checkout.productCard.annualBillingTemplate', {
priceNow: totalAmountFormatted,
price: normalPriceAmount,
Expand Down
10 changes: 7 additions & 3 deletions src/views/Checkout/utils/formatPrice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ describe('Formatting the price to have 2 decimals', () => {
});

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');
it('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)', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use test instead.

expect(formatPrice(10.456)).toBe('10.46');
expect(formatPrice(10.001)).toBe('10');
expect(formatPrice(1.999)).toBe('1.99');
expect(formatPrice(1.999)).toBe('2');
});
});

it('Handles edge case where value is nearly integer due to float error', () => {
expect(formatPrice(10.0000001)).toBe('10');
});

it('Handles floating point precision error (19.99 * 100 = 1998.999... in JS)', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use when..., then...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and change it from "it" to "test".

the "it" tests are like: it('should do .... when doing ....')
the "test" tests are like: test('When doing .... then it does .....')

expect(formatPrice(19.99)).toBe('19.99');
});
});
2 changes: 1 addition & 1 deletion src/views/Checkout/utils/formatPrice.ts
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;
};
Loading