import React from 'react' ; import axios from 'axios' ; import SemVer from 'semver/classes/semver' ; import { merge } from 'lodash' ; import axiosXhrAdapter from 'axios/lib/adapters/xhr' ; import { HttpSetup } from 'src/core/public' ; import { MAJOR_VERSION } from '../../../common/constants' ; import { AuthorizationContext , Authorization , Privileges } from '../../../public/shared_imports' ; import { AppContextProvider } from '../../../public/application/app_context' ; import { apiService } from '../../../public/application/lib/api' ; import { breadcrumbService } from '../../../public/application/lib/breadcrumbs' ; import { GlobalFlyout } from '../../../public/shared_imports' ; import { AppDependencies } from '../../../public/types' ; import { getAppContextMock } from './app_context.mock' ; import { init as initHttpRequests } from './http_requests' ; const { GlobalFlyoutProvider } = GlobalFlyout ; const mockHttpClient = axios . create ( { adapter : axiosXhrAdapter } ) ; export const kibanaVersion = new SemVer ( MAJOR_VERSION ) ; const createAuthorizationContextValue = ( privileges ) => { return { isLoading : false , privileges : privileges ?? { hasAllPrivileges : false , missingPrivileges : { } } , } as Authorization ; } ; export const WithAppDependencies = ( Comp , { privileges , ... overrides } = { } ) => ( props ) => { apiService . setup ( mockHttpClient as unknown as HttpSetup ) ; breadcrumbService . setup ( ( ) => '' ) ; const appContextMock = getAppContextMock ( kibanaVersion ) as unknown as AppDependencies ; return ( < AuthorizationContext . Provider value = { createAuthorizationContextValue ( privileges as Privileges ) } > < AppContextProvider value = { merge ( appContextMock , overrides ) } > < GlobalFlyoutProvider > < Comp { ... props } / > < /GlobalFlyoutProvider> < /AppContextProvider> < /AuthorizationContext.Provider>); } ; export const setupEnvironment = ( ) => { const { server , setServerAsync , httpRequestsMockHelpers } = initHttpRequests ( ) ; return { server , setServerAsync , httpRequestsMockHelpers , } ; } ;