/**
 * Components using the @osd/i18n module require access to the intl context.
 * This is not available when mounting single components in Enzyme.
 * These helper functions aim to address that and wrap a valid,
 * intl context around them.
 */ import { I18nProvider , InjectedIntl , intlShape , __IntlProvider } from '@osd/i18n/react' ; import { mount , ReactWrapper , render , shallow } from 'enzyme' ; import React , { ReactElement , ValidationMap } from 'react' ; import { IntlProvider } from 'react-intl' ; const { intl } = ( mount ( < I18nProvider > < br /> < /I18nProvider>).find('IntlProvider') as ReactWrapper<{}, {}, __IntlProvider>) . instance ( ) . getChildContext ( ) ; function getOptions ( context = { } , childContextTypes = { } , props = { } ) { return { context : { ... context , intl , } , childContextTypes : { ... childContextTypes , intl : intlShape , } , ... props , } ; } /**
 * When using @osd/i18n `injectI18n` on components, props.intl is required.
 */ export function nodeWithIntlProp < T > ( node ) { return React . cloneElement < any > ( node , { intl } ) ; } param node return export function wrapWithIntl < T > ( node ) { return < IntlProvider locale = "en" > { node } < /IntlProvider>; } param node param options return export function shallowWithIntl < T > ( node , { context , childContextTypes , ... props } = { } ) { const options = getOptions ( context , childContextTypes , props ) ; return shallow ( nodeWithIntlProp ( node ) , options ) ; } param node param options return export function mountWithIntl < T > ( node , { context , childContextTypes , ... props } = { } ) { const options = getOptions ( context , childContextTypes , props ) ; return mount ( nodeWithIntlProp ( node ) , options ) ; } param node param options return export function renderWithIntl < T > ( node , { context , childContextTypes , ... props } = { } ) { const options = getOptions ( context , childContextTypes , props ) ; return render ( nodeWithIntlProp ( node ) , options ) ; } export const nextTick = ( ) => new Promise ( ( res ) => process . nextTick ( res ) ) ; export function shallowWithI18nProvider < T > ( child ) { const wrapped = shallow ( < I18nProvider > { child } < /I18nProvider>); const name = typeof child . type === 'string' ? child . type : child . type . name ; return wrapped . find ( name ) . dive ( ) ; } export function mountWithI18nProvider < T > ( child ) { const wrapped = mount ( < I18nProvider > { child } < /I18nProvider>); const name = typeof child . type === 'string' ? child . type : child . type . name ; return wrapped . find ( name ) ; }