import { act } from 'react-dom/test-utils' ; import { setupEnvironment } from '../helpers' ; import { ElasticsearchTestBed , setupElasticsearchPage } from './es_deprecations.helpers' ; import { esDeprecationsMockResponse , MOCK_SNAPSHOT_ID , MOCK_JOB_ID } from './mocked_responses' ; describe ( 'Index settings deprecation flyout' , ( ) => { let testBed ; const { server , httpRequestsMockHelpers } = setupEnvironment ( ) ; const indexSettingDeprecation = esDeprecationsMockResponse . deprecations [ 1 ] ; afterAll ( ( ) => { server . restore ( ) ; } ) ; beforeEach ( async ( ) => { httpRequestsMockHelpers . setLoadEsDeprecationsResponse ( esDeprecationsMockResponse ) ; httpRequestsMockHelpers . setUpgradeMlSnapshotStatusResponse ( { nodeId : 'my_node' , snapshotId : MOCK_SNAPSHOT_ID , jobId : MOCK_JOB_ID , status : 'idle' , } ) ; httpRequestsMockHelpers . setReindexStatusResponse ( { reindexOp : null , warnings : [ ] , hasRequiredPrivileges : true , meta : { indexName : 'foo' , reindexName : 'reindexed-foo' , aliases : [ ] , } , } ) ; await act ( async ( ) => { testBed = await setupElasticsearchPage ( { isReadOnlyMode : false } ) ; } ) ; const { actions , component } = testBed ; component . update ( ) ; await actions . table . clickDeprecationRowAt ( 'indexSetting' , 0 ) ; } ) ; test ( 'renders a flyout with deprecation details' , async ( ) => { const { find , exists } = testBed ; expect ( exists ( 'indexSettingsDetails' ) ) . toBe ( true ) ; expect ( find ( 'indexSettingsDetails.flyoutTitle' ) . text ( ) ) . toContain ( indexSettingDeprecation . message ) ; expect ( find ( 'indexSettingsDetails.documentationLink' ) . props ( ) . href ) . toBe ( indexSettingDeprecation . url ) ; expect ( exists ( 'removeSettingsPrompt' ) ) . toBe ( true ) ; } ) ; it ( 'removes deprecated index settings' , async ( ) => { const { find , actions , exists } = testBed ; httpRequestsMockHelpers . setUpdateIndexSettingsResponse ( { acknowledged : true , } ) ; expect ( exists ( 'indexSettingsDetails.warningDeprecationBadge' ) ) . toBe ( true ) ; await actions . indexSettingsDeprecationFlyout . clickDeleteSettingsButton ( ) ; const request = server . requests [ server . requests . length - 1 ] ; expect ( request . method ) . toBe ( 'POST' ) ; expect ( request . url ) . toBe ( `/api/upgrade_assistant/${ indexSettingDeprecation . index ! }/index_settings` ) ; expect ( request . status ) . toEqual ( 200 ) ; expect ( find ( 'indexSettingsResolutionStatusCell' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Deprecated settings removed' ) ; await actions . table . clickDeprecationRowAt ( 'indexSetting' , 0 ) ; expect ( find ( 'removeSettingsPrompt' ) . length ) . toEqual ( 0 ) ; expect ( find ( 'indexSettingsDetails.deleteSettingsButton' ) . length ) . toEqual ( 0 ) ; expect ( exists ( 'indexSettingsDetails.resolvedDeprecationBadge' ) ) . toBe ( true ) ; } ) ; it ( 'handles failure' , async ( ) => { const { find , actions } = testBed ; const error = { statusCode : 500 , error : 'Remove index settings error' , message : 'Remove index settings error' , } ; httpRequestsMockHelpers . setUpdateIndexSettingsResponse ( undefined , error ) ; await actions . indexSettingsDeprecationFlyout . clickDeleteSettingsButton ( ) ; const request = server . requests [ server . requests . length - 1 ] ; expect ( request . method ) . toBe ( 'POST' ) ; expect ( request . url ) . toBe ( `/api/upgrade_assistant/${ indexSettingDeprecation . index ! }/index_settings` ) ; expect ( request . status ) . toEqual ( 500 ) ; expect ( find ( 'indexSettingsResolutionStatusCell' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Settings removal failed' ) ; await actions . table . clickDeprecationRowAt ( 'indexSetting' , 0 ) ; expect ( find ( 'indexSettingsDetails.deleteSettingsError' ) . text ( ) ) . toContain ( 'Error deleting index settings' ) ; expect ( find ( 'indexSettingsDetails.deleteSettingsButton' ) . text ( ) ) . toEqual ( 'Retry removing deprecated settings' ) ; } ) ; } ) ;