overleaf/services/web/test/frontend/features/subscription/util/recurly-pricing.test.ts
Jessica Lawshe ebc04e4a9d Merge pull request #11888 from overleaf/jel-subscription-dash-cancel-plan
[web] Migrate cancel subscription to React

GitOrigin-RevId: 8482fd61894c8011b4c980263ae1d41f396233c6
2023-02-24 09:05:12 +00:00

44 lines
1.2 KiB
TypeScript

import { expect } from 'chai'
import { formatPriceForDisplayData } from '../../../../../frontend/js/features/subscription/util/recurly-pricing'
describe('formatPriceForDisplayData', function () {
beforeEach(function () {
window.metaAttributesCache = new Map()
})
afterEach(function () {
window.metaAttributesCache = new Map()
})
it('should handle no tax rate', function () {
const data = formatPriceForDisplayData('1000', 0, 'USD')
expect(data).to.deep.equal({
totalForDisplay: '$1000',
totalAsNumber: 1000,
subtotal: '$1000.00',
tax: '$0.00',
includesTax: false,
})
window.metaAttributesCache = new Map()
})
it('should handle a tax rate', function () {
const data = formatPriceForDisplayData('380', 0.2, 'EUR')
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')
expect(data).to.deep.equal({
totalForDisplay: '€9.60',
totalAsNumber: 9.6,
subtotal: '€8.00',
tax: '€1.60',
includesTax: true,
})
})
})