import { act } from 'react-dom/test-utils' ; import { TestBedConfig , registerTestBed , TestBed } from '@kbn/test/jest' ; import { BASE_PATH } from '../../../public/application/constants' ; import { SnapshotList } from '../../../public/application/sections/home/snapshot_list' ; import { WithAppDependencies } from './setup_environment' ; const getTestBedConfig = ( query ? ) : TestBedConfig => ( { memoryRouter : { initialEntries : [ `${ BASE_PATH }/snapshots${ query ?? '' }` ] , componentRoutePath : `${ BASE_PATH }/snapshots/:repositoryName?/:snapshotId*` , } , } ) ; const initTestBed = ( query ? ) => registerTestBed ( WithAppDependencies ( SnapshotList ) , getTestBedConfig ( query ) ) ( ) ; export interface SnapshotListTestBed extends TestBed { actions : { setSearchText : ( value : string , advanceTime ? : boolean ) => void ; searchErrorExists : ( ) => boolean ; getSearchErrorText : ( ) => string ; } ; } const searchBarSelector = 'snapshotListSearch' ; const searchErrorSelector = 'snapshotListSearchError' ; export const setup = async ( query ? ) : Promise < SnapshotListTestBed > => { const testBed = await initTestBed ( query ) ; const { form , component , find , exists } = testBed ; const setSearchText = async ( value , advanceTime = true ) => { await act ( async ( ) => { form . setInputValue ( searchBarSelector , value ) ; } ) ; component . update ( ) ; if ( advanceTime ) { await act ( async ( ) => { jest . advanceTimersByTime ( 500 ) ; } ) ; component . update ( ) ; } } ; const searchErrorExists = ( ) : boolean => { return exists ( searchErrorSelector ) ; } ; const getSearchErrorText = ( ) : string => { return find ( searchErrorSelector ) . text ( ) ; } ; return { ... testBed , actions : { setSearchText , searchErrorExists , getSearchErrorText , } , } ; } ;