|
@@ -1,22 +1,26 @@
|
|
|
import { expect } from 'chai'
|
|
import { expect } from 'chai'
|
|
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
|
-import { SubscriptionDashboardProvider } from '../../../../../../../../frontend/js/features/subscription/context/subscription-dashboard-context'
|
|
|
|
|
-import { ChangePlan } from '../../../../../../../../frontend/js/features/subscription/components/dashboard/states/active/change-plan'
|
|
|
|
|
-import { plans } from '../../../../fixtures/plans'
|
|
|
|
|
|
|
+import { SubscriptionDashboardProvider } from '../../../../../../../../../frontend/js/features/subscription/context/subscription-dashboard-context'
|
|
|
|
|
+import { ChangePlan } from '../../../../../../../../../frontend/js/features/subscription/components/dashboard/states/active/change-plan/change-plan'
|
|
|
|
|
+import { plans } from '../../../../../fixtures/plans'
|
|
|
import {
|
|
import {
|
|
|
annualActiveSubscription,
|
|
annualActiveSubscription,
|
|
|
pendingSubscriptionChange,
|
|
pendingSubscriptionChange,
|
|
|
-} from '../../../../fixtures/subscriptions'
|
|
|
|
|
-import { ActiveSubscription } from '../../../../../../../../frontend/js/features/subscription/components/dashboard/states/active/active'
|
|
|
|
|
|
|
+} from '../../../../../fixtures/subscriptions'
|
|
|
|
|
+import { ActiveSubscription } from '../../../../../../../../../frontend/js/features/subscription/components/dashboard/states/active/active'
|
|
|
|
|
|
|
|
describe('<ChangePlan />', function () {
|
|
describe('<ChangePlan />', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
window.metaAttributesCache = new Map()
|
|
window.metaAttributesCache = new Map()
|
|
|
window.metaAttributesCache.set('ol-plans', plans)
|
|
window.metaAttributesCache.set('ol-plans', plans)
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ window.recurly = {}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
afterEach(function () {
|
|
|
window.metaAttributesCache = new Map()
|
|
window.metaAttributesCache = new Map()
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ delete window.recurly
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('does not render the UI when showChangePersonalPlan is false', function () {
|
|
it('does not render the UI when showChangePersonalPlan is false', function () {
|
|
@@ -30,7 +34,7 @@ describe('<ChangePlan />', function () {
|
|
|
expect(container.firstChild).to.be.null
|
|
expect(container.firstChild).to.be.null
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('renders the table of plans', function () {
|
|
|
|
|
|
|
+ it('renders the individual plans table', function () {
|
|
|
window.metaAttributesCache.set('ol-subscription', annualActiveSubscription)
|
|
window.metaAttributesCache.set('ol-subscription', annualActiveSubscription)
|
|
|
render(
|
|
render(
|
|
|
<SubscriptionDashboardProvider>
|
|
<SubscriptionDashboardProvider>
|
|
@@ -45,7 +49,7 @@ describe('<ChangePlan />', function () {
|
|
|
name: 'Change to this plan',
|
|
name: 'Change to this plan',
|
|
|
})
|
|
})
|
|
|
expect(changeToPlanButtons.length).to.equal(plans.length - 1)
|
|
expect(changeToPlanButtons.length).to.equal(plans.length - 1)
|
|
|
- screen.getByRole('button', { name: 'Your plan' })
|
|
|
|
|
|
|
+ screen.getByText('Your plan')
|
|
|
|
|
|
|
|
const annualPlans = plans.filter(plan => plan.annual)
|
|
const annualPlans = plans.filter(plan => plan.annual)
|
|
|
expect(screen.getAllByText('/ year').length).to.equal(annualPlans.length)
|
|
expect(screen.getAllByText('/ year').length).to.equal(annualPlans.length)
|
|
@@ -54,6 +58,20 @@ describe('<ChangePlan />', function () {
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ it('renders the change to group plan UI', function () {
|
|
|
|
|
+ window.metaAttributesCache.set('ol-subscription', annualActiveSubscription)
|
|
|
|
|
+ render(
|
|
|
|
|
+ <SubscriptionDashboardProvider>
|
|
|
|
|
+ <ActiveSubscription subscription={annualActiveSubscription} />
|
|
|
|
|
+ </SubscriptionDashboardProvider>
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ const button = screen.getByRole('button', { name: 'Change plan' })
|
|
|
|
|
+ fireEvent.click(button)
|
|
|
|
|
+
|
|
|
|
|
+ screen.getByText('Looking for multiple licenses?')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
it('renders "Your new plan" and "Keep current plan" when there is a pending plan change', function () {
|
|
it('renders "Your new plan" and "Keep current plan" when there is a pending plan change', function () {
|
|
|
window.metaAttributesCache.set('ol-subscription', pendingSubscriptionChange)
|
|
window.metaAttributesCache.set('ol-subscription', pendingSubscriptionChange)
|
|
|
render(
|
|
render(
|
|
@@ -68,4 +86,15 @@ describe('<ChangePlan />', function () {
|
|
|
screen.getByText('Your new plan')
|
|
screen.getByText('Your new plan')
|
|
|
screen.getByRole('button', { name: 'Keep my current plan' })
|
|
screen.getByRole('button', { name: 'Keep my current plan' })
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ it('does not render when Recurly did not load', function () {
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ delete window.recurly
|
|
|
|
|
+ const { container } = render(
|
|
|
|
|
+ <SubscriptionDashboardProvider>
|
|
|
|
|
+ <ActiveSubscription subscription={annualActiveSubscription} />
|
|
|
|
|
+ </SubscriptionDashboardProvider>
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(container).not.to.be.null
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|