import { act } from 'react-dom/test-utils' ; import { deprecationsServiceMock } from 'src/core/public/mocks' ; import type { DeprecationsServiceStart } from 'kibana/public' ; import { setupEnvironment } from '../../helpers' ; import { kibanaDeprecationsServiceHelpers } from '../service.mock' ; import { KibanaTestBed , setupKibanaPage } from '../kibana_deprecations.helpers' ; describe ( 'Kibana deprecations - Deprecations table' , ( ) => { let testBed ; let deprecationService ; const { server } = setupEnvironment ( ) ; const { mockedKibanaDeprecations , mockedCriticalKibanaDeprecations , mockedWarningKibanaDeprecations , mockedConfigKibanaDeprecations , } = kibanaDeprecationsServiceHelpers . defaultMockedResponses ; afterAll ( ( ) => { server . restore ( ) ; } ) ; beforeEach ( async ( ) => { deprecationService = deprecationsServiceMock . createStartContract ( ) ; await act ( async ( ) => { kibanaDeprecationsServiceHelpers . setLoadDeprecations ( { deprecationService } ) ; testBed = await setupKibanaPage ( { services : { core : { deprecations : deprecationService , } , } , } ) ; } ) ; testBed . component . update ( ) ; } ) ; test ( 'renders deprecations' , ( ) => { const { exists , table } = testBed ; expect ( exists ( 'kibanaDeprecations' ) ) . toBe ( true ) ; const { tableCellsValues } = table . getMetaData ( 'kibanaDeprecationsTable' ) ; expect ( tableCellsValues . length ) . toEqual ( mockedKibanaDeprecations . length ) ; } ) ; it ( 'refreshes deprecation data' , async ( ) => { const { actions } = testBed ; expect ( deprecationService . getAllDeprecations ) . toHaveBeenCalledTimes ( 1 ) ; await actions . table . clickRefreshButton ( ) ; expect ( deprecationService . getAllDeprecations ) . toHaveBeenCalledTimes ( 2 ) ; } ) ; it ( 'shows critical and warning deprecations count' , ( ) => { const { find } = testBed ; expect ( find ( 'criticalDeprecationsCount' ) . text ( ) ) . toContain ( mockedCriticalKibanaDeprecations . length ) ; expect ( find ( 'warningDeprecationsCount' ) . text ( ) ) . toContain ( mockedWarningKibanaDeprecations . length ) ; } ) ; describe ( 'Search bar' , ( ) => { it ( 'filters by "critical" status' , async ( ) => { const { actions , table } = testBed ; await actions . searchBar . clickCriticalFilterButton ( ) ; const { rows : criticalRows } = table . getMetaData ( 'kibanaDeprecationsTable' ) ; expect ( criticalRows . length ) . toEqual ( mockedCriticalKibanaDeprecations . length ) ; await actions . searchBar . clickCriticalFilterButton ( ) ; const { rows : allRows } = table . getMetaData ( 'kibanaDeprecationsTable' ) ; expect ( allRows . length ) . toEqual ( mockedKibanaDeprecations . length ) ; } ) ; it ( 'filters by type' , async ( ) => { const { table , actions } = testBed ; await actions . searchBar . openTypeFilterDropdown ( ) ; await actions . searchBar . filterByConfigType ( ) ; const { rows : configRows } = table . getMetaData ( 'kibanaDeprecationsTable' ) ; expect ( configRows . length ) . toEqual ( mockedConfigKibanaDeprecations . length ) ; } ) ; } ) ; describe ( 'No deprecations' , ( ) => { beforeEach ( async ( ) => { await act ( async ( ) => { testBed = await setupKibanaPage ( { isReadOnlyMode : false } ) ; } ) ; const { component } = testBed ; component . update ( ) ; } ) ; test ( 'renders prompt' , ( ) => { const { exists , find } = testBed ; expect ( exists ( 'noDeprecationsPrompt' ) ) . toBe ( true ) ; expect ( find ( 'noDeprecationsPrompt' ) . text ( ) ) . toContain ( 'Your Kibana configuration is up to date' ) ; } ) ; } ) ; } ) ;