import { act } from 'react-dom/test-utils' ; import { registerTestBed , TestBed , AsyncTestBedConfig , findTestSubject } from '@kbn/test/jest' ; import { KibanaDeprecations } from '../../../public/application/components' ; import { WithAppDependencies } from '../helpers' ; const testBedConfig = { memoryRouter : { initialEntries : [ '/kibana_deprecations' ] , componentRoutePath : '/kibana_deprecations' , } , doMountAsync : true , } ; export type KibanaTestBed = TestBed & { actions : ReturnType < typeof createActions > ; } ; const createActions = ( testBed ) => { const { component , find , table } = testBed ; /**
     * User Actions
     */ const tableActions = { clickRefreshButton : async ( ) => { await act ( async ( ) => { find ( 'refreshButton' ) . simulate ( 'click' ) ; } ) ; component . update ( ) ; } , clickDeprecationAt : async ( index ) => { const { rows } = table . getMetaData ( 'kibanaDeprecationsTable' ) ; const deprecationDetailsLink = findTestSubject ( rows [ index ] . reactWrapper , 'deprecationDetailsLink' ) ; await act ( async ( ) => { deprecationDetailsLink . simulate ( 'click' ) ; } ) ; component . update ( ) ; } , } ; const searchBarActions = { openTypeFilterDropdown : async ( ) => { await act ( async ( ) => { find ( 'kibanaDeprecations' ) . find ( '.euiSearchBar__filtersHolder' ) . find ( '.euiPopover' ) . find ( '.euiFilterButton' ) . at ( 0 ) . simulate ( 'click' ) ; } ) ; component . update ( ) ; } , clickCriticalFilterButton : async ( ) => { await act ( async ( ) => { find ( 'kibanaDeprecations' ) . find ( '.euiSearchBar__filtersHolder' ) . find ( '.euiFilterButton' ) . at ( 0 ) . simulate ( 'click' ) ; } ) ; component . update ( ) ; } , filterByConfigType : async ( ) => { const configTypeFilterButton = document . body . querySelector ( '.euiFilterSelect__items .euiFilterSelectItem' ) ; await act ( async ( ) => { configTypeFilterButton ! . click ( ) ; } ) ; component . update ( ) ; } , } ; const flyoutActions = { clickResolveButton : async ( ) => { await act ( async ( ) => { find ( 'resolveButton' ) . simulate ( 'click' ) ; } ) ; component . update ( ) ; } , } ; return { table : tableActions , flyout : flyoutActions , searchBar : searchBarActions , } ; } ; export const setupKibanaPage = async ( overrides ? ) : Promise < KibanaTestBed > => { const initTestBed = registerTestBed ( WithAppDependencies ( KibanaDeprecations , overrides ) , testBedConfig ) ; const testBed = await initTestBed ( ) ; return { ... testBed , actions : createActions ( testBed ) , } ; } ;