import { act } from 'react-dom/test-utils' ; import { setupEnvironment } from '../../../helpers' ; import { CloudNodeAllocationTestBed , setupCloudNodeAllocation , } from './cloud_aware_behavior.helpers' ; describe ( '<EditPolicy /> node allocation cloud-aware behavior' , ( ) => { let testBed ; const { server , httpRequestsMockHelpers } = setupEnvironment ( ) ; beforeAll ( ( ) => { jest . useFakeTimers ( ) ; } ) ; afterAll ( ( ) => { jest . useRealTimers ( ) ; server . restore ( ) ; } ) ; const setup = async ( isOnCloud ? ) => { await act ( async ( ) => { if ( Boolean ( isOnCloud ) ) { testBed = await setupCloudNodeAllocation ( { appServicesContext : { cloud : { isCloudEnabled : true } } , } ) ; } else { testBed = await setupCloudNodeAllocation ( ) ; } } ) ; } ; beforeEach ( async ( ) => { server . respondImmediately = true ; httpRequestsMockHelpers . setLoadPolicies ( [ ] ) ; httpRequestsMockHelpers . setListNodes ( { nodesByRoles : { data : [ 'node1' ] } , nodesByAttributes : { 'attribute:true' : [ 'node1' ] } , isUsingDeprecatedDataRoleConfig : true , } ) ; httpRequestsMockHelpers . setNodesDetails ( 'attribute:true' , [ { nodeId : 'testNodeId' , stats : { name : 'testNodeName' , host : 'testHost' } } , ] ) ; await setup ( ) ; const { component } = testBed ; component . update ( ) ; } ) ; describe ( 'when not on cloud' , ( ) => { test ( 'shows all allocation options, even if using legacy config' , async ( ) => { httpRequestsMockHelpers . setListNodes ( { nodesByAttributes : { test : [ '123' ] } , nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } , isUsingDeprecatedDataRoleConfig : true , } ) ; await setup ( ) ; const { actions , component , exists } = testBed ; component . update ( ) ; await actions . togglePhase ( 'warm' ) ; expect ( component . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ; await actions . warm . openNodeAttributesSection ( ) ; expect ( exists ( 'defaultDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( exists ( 'customDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( exists ( 'noneDataAllocationOption' ) ) . toBeTruthy ( ) ; } ) ; } ) ; describe ( 'when on cloud' , ( ) => { describe ( 'using legacy data role config' , ( ) => { test ( 'should hide data tier option on cloud' , async ( ) => { httpRequestsMockHelpers . setListNodes ( { nodesByAttributes : { test : [ '123' ] } , nodesByRoles : { data : [ 'test' ] } , isUsingDeprecatedDataRoleConfig : true , } ) ; await setup ( true ) ; const { actions , component , exists , find } = testBed ; component . update ( ) ; await actions . togglePhase ( 'warm' ) ; expect ( component . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ; await actions . warm . openNodeAttributesSection ( ) ; expect ( exists ( 'defaultDataAllocationOption' ) ) . toBeFalsy ( ) ; expect ( exists ( 'customDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( exists ( 'noneDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( find ( 'cloudDataTierCallout' ) . exists ( ) ) . toBeTruthy ( ) ; } ) ; } ) ; describe ( 'using node role config' , ( ) => { test ( 'shows recommended, custom and "off" options on cloud with data roles' , async ( ) => { httpRequestsMockHelpers . setListNodes ( { nodesByAttributes : { test : [ '123' ] } , nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } , isUsingDeprecatedDataRoleConfig : false , } ) ; await setup ( true ) ; testBed . component . update ( ) ; const { actions , component , exists , find } = testBed ; await actions . togglePhase ( 'warm' ) ; expect ( component . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ; await actions . warm . openNodeAttributesSection ( ) ; expect ( exists ( 'defaultDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( exists ( 'customDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( exists ( 'noneDataAllocationOption' ) ) . toBeTruthy ( ) ; expect ( find ( 'cloudDataTierCallout' ) . exists ( ) ) . toBeFalsy ( ) ; } ) ; test ( 'do not show node allocation specific warnings on cloud' , async ( ) => { httpRequestsMockHelpers . setListNodes ( { nodesByAttributes : { test : [ '123' ] } , nodesByRoles : { } , isUsingDeprecatedDataRoleConfig : false , } ) ; await setup ( true ) ; testBed . component . update ( ) ; const { actions , component , exists } = testBed ; await actions . togglePhase ( 'warm' ) ; await actions . togglePhase ( 'cold' ) ; expect ( component . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ; expect ( exists ( 'cloudDataTierCallout' ) ) . toBeFalsy ( ) ; expect ( actions . warm . hasWillUseFallbackTierNotice ( ) || actions . cold . hasWillUseFallbackTierNotice ( ) ) . toBeFalsy ( ) ; expect ( actions . warm . hasNoTiersAvailableNotice ( ) || actions . cold . hasNoTiersAvailableNotice ( ) ) . toBeFalsy ( ) ; } ) ; } ) ; } ) ; } ) ;