overleaf/services/web/test/frontend/features/subscription/util/recurly-pricing.test.ts
Jakob Ackermann aa480a2663 Merge pull request #18898 from overleaf/jpa-no-window
[web] migrate from window attributes to getMeta

GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
2024-06-19 08:04:21 +00:00

56 lines
1.3 KiB
TypeScript

import { expect } from 'chai'
import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
import { formatCurrencyLocalized } from '@/shared/utils/currency'
describe('formatPriceForDisplayData', function () {
it('should handle no tax rate', function () {
const data = formatPriceForDisplayData(
'1000',
0,
'USD',
'en',
formatCurrencyLocalized
)
expect(data).to.deep.equal({
totalForDisplay: '$1,000',
totalAsNumber: 1000,
subtotal: '$1,000.00',
tax: '$0.00',
includesTax: false,
})
})
it('should handle a tax rate', function () {
const data = formatPriceForDisplayData(
'380',
0.2,
'EUR',
'en',
formatCurrencyLocalized
)
expect(data).to.deep.equal({
totalForDisplay: '€456',
totalAsNumber: 456,
subtotal: '€380.00',
tax: '€76.00',
includesTax: true,
})
})
it('should handle total with cents', function () {
const data = formatPriceForDisplayData(
'8',
0.2,
'EUR',
'en',
formatCurrencyLocalized
)
expect(data).to.deep.equal({
totalForDisplay: '€9.60',
totalAsNumber: 9.6,
subtotal: '€8.00',
tax: '€1.60',
includesTax: true,
})
})
})