overleaf/services/web/test/frontend/shared/utils/group-plan-pricing.test.js
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

86 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect } from 'chai'
import { createLocalizedGroupPlanPrice } from '../../../../frontend/js/features/plans/utils/group-plan-pricing'
import { formatCurrencyLocalized } from '@/shared/utils/currency'
describe('group-plan-pricing', function () {
beforeEach(function () {
window.metaAttributesCache.set('ol-groupPlans', {
enterprise: {
professional: {
CHF: {
2: {
price_in_cents: 10000,
},
},
DKK: {
2: {
price_in_cents: 20000,
},
},
USD: {
2: {
price_in_cents: 30000,
},
},
},
},
})
window.metaAttributesCache.set('ol-currencySymbols', {
CHF: 'Fr',
DKK: 'kr',
USD: '$',
})
window.metaAttributesCache.set('ol-i18n', { currentLangCode: 'en' })
})
describe('createLocalizedGroupPlanPrice', function () {
describe('CHF currency', function () {
it('should return the correct localized price', function () {
const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
plan: 'professional',
currency: 'CHF',
licenseSize: '2',
usage: 'enterprise',
formatCurrency: formatCurrencyLocalized,
})
expect(localizedGroupPlanPrice).to.deep.equal({
localizedPrice: 'CHF 100',
localizedPerUserPrice: 'CHF 50',
})
})
})
describe('DKK currency', function () {
it('should return the correct localized price', function () {
const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
plan: 'professional',
currency: 'DKK',
licenseSize: '2',
usage: 'enterprise',
formatCurrency: formatCurrencyLocalized,
})
expect(localizedGroupPlanPrice).to.deep.equal({
localizedPrice: 'kr 200',
localizedPerUserPrice: 'kr 100',
})
})
})
describe('other supported currencies', function () {
it('should return the correct localized price', function () {
const localizedGroupPlanPrice = createLocalizedGroupPlanPrice({
plan: 'professional',
currency: 'USD',
licenseSize: '2',
usage: 'enterprise',
formatCurrency: formatCurrencyLocalized,
})
expect(localizedGroupPlanPrice).to.deep.equal({
localizedPrice: '$300',
localizedPerUserPrice: '$150',
})
})
})
})
})