overleaf/services/web/test/frontend/features/subscription/helpers/render-with-subscription-dash-context.tsx
Jessica Lawshe d4057a7bcc Merge pull request #11602 from overleaf/jel-react-personal-subscription-dash-pt-6
[web] Continue migration of change plan UI to React

GitOrigin-RevId: 4f6176ac101ba3c57134cf5c86329e205f17ab23
2023-02-08 09:06:37 +00:00

38 lines
1,017 B
TypeScript

import { render } from '@testing-library/react'
import { SubscriptionDashboardProvider } from '../../../../../frontend/js/features/subscription/context/subscription-dashboard-context'
export function renderWithSubscriptionDashContext(
component: React.ReactElement,
options?: {
metaTags?: { name: string; value: string | object | Array<object> }[]
recurlyNotLoaded?: boolean
}
) {
const SubscriptionDashboardProviderWrapper = ({
children,
}: {
children: React.ReactNode
}) => (
<SubscriptionDashboardProvider>{children}</SubscriptionDashboardProvider>
)
window.metaAttributesCache = new Map()
options?.metaTags?.forEach(tag =>
window.metaAttributesCache.set(tag.name, tag.value)
)
if (!options?.recurlyNotLoaded) {
// @ts-ignore
window.recurly = {}
}
return render(component, {
wrapper: SubscriptionDashboardProviderWrapper,
})
}
export function cleanUpContext() {
// @ts-ignore
delete window.recurly
window.metaAttributesCache = new Map()
}