import React from 'react' ; import { act } from 'react-dom/test-utils' ; import { registerTestBed , TestBed , TestBedConfig } from '@kbn/test/jest' ; import { docLinksServiceMock } from 'src/core/public/mocks' ; import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public' ; import { createBreadcrumbsMock } from '../../../public/application/services/breadcrumbs.mock' ; import { licensingMock } from '../../../../licensing/public/mocks' ; import { App } from '../../../public/application/app' ; const breadcrumbService = createBreadcrumbsMock ( ) ; const AppWithContext = ( props ) => { return ( < KibanaContextProvider services = { { breadcrumbService , license : licensingMock . createLicense ( ) , docLinks : docLinksServiceMock . createStartContract ( ) , } } > < App { ... props } / > < /KibanaContextProvider>); } ; const getTestBedConfig = ( initialEntries ) : TestBedConfig => ( { memoryRouter : { initialEntries , } , defaultProps : { getUrlForApp : ( ) => { } , } , } ) ; const initTestBed = ( initialEntries ) => registerTestBed ( AppWithContext , getTestBedConfig ( initialEntries ) ) ( ) ; export interface AppTestBed extends TestBed { actions : { clickPolicyNameLink : ( ) => void ; clickCreatePolicyButton : ( ) => void ; } ; } export const setup = async ( initialEntries ) : Promise < AppTestBed > => { const testBed = await initTestBed ( initialEntries ) ; const clickPolicyNameLink = async ( ) => { const { component , find } = testBed ; await act ( async ( ) => { find ( 'policyTablePolicyNameLink' ) . simulate ( 'click' , { button : 0 } ) ; } ) ; component . update ( ) ; } ; const clickCreatePolicyButton = async ( ) => { const { component , find } = testBed ; await act ( async ( ) => { find ( 'createPolicyButton' ) . simulate ( 'click' , { button : 0 } ) ; } ) ; component . update ( ) ; } ; return { ... testBed , actions : { clickPolicyNameLink , clickCreatePolicyButton } , } ; } ; export const getEncodedPolicyEditPath = ( policyName ) : string => `/policies/edit/${ encodeURIComponent ( policyName ) }` ; export const getDoubleEncodedPolicyEditPath = ( policyName ) : string => encodeURI ( getEncodedPolicyEditPath ( policyName ) ) ;