@@ -21,8 +21,10 @@ import {
2121 fatalErrorsServiceMock ,
2222} from '../../../../../src/core/public/mocks' ;
2323import { usageCollectionPluginMock } from '../../../../../src/plugins/usage_collection/public/mocks' ;
24+ import { CloudSetup } from '../../../cloud/public' ;
2425
2526import { EditPolicy } from '../../public/application/sections/edit_policy/edit_policy' ;
27+ import { KibanaContextProvider } from '../../public/shared_imports' ;
2628import { init as initHttp } from '../../public/application/services/http' ;
2729import { init as initUiMetric } from '../../public/application/services/ui_metric' ;
2830import { init as initNotification } from '../../public/application/services/notification' ;
@@ -148,7 +150,14 @@ const save = (rendered: ReactWrapper) => {
148150describe ( 'edit policy' , ( ) => {
149151 beforeEach ( ( ) => {
150152 component = (
151- < EditPolicy history = { history } getUrlForApp = { jest . fn ( ) } policies = { policies } policyName = { '' } />
153+ < KibanaContextProvider services = { { cloud : { isCloudEnabled : false } as CloudSetup } } >
154+ < EditPolicy
155+ history = { history }
156+ getUrlForApp = { jest . fn ( ) }
157+ policies = { policies }
158+ policyName = { '' }
159+ />
160+ </ KibanaContextProvider >
152161 ) ;
153162
154163 ( { http } = editPolicyHelpers . setup ( ) ) ;
@@ -447,6 +456,7 @@ describe('edit policy', () => {
447456 http . setupNodeListResponse ( {
448457 nodesByAttributes : { } ,
449458 nodesByRoles : { data : [ 'node1' ] } ,
459+ isUsingDeprecatedDataRoleConfig : false ,
450460 } ) ;
451461 const rendered = mountWithIntl ( component ) ;
452462 noRollover ( rendered ) ;
@@ -495,6 +505,7 @@ describe('edit policy', () => {
495505 http . setupNodeListResponse ( {
496506 nodesByAttributes : { } ,
497507 nodesByRoles : { } ,
508+ isUsingDeprecatedDataRoleConfig : false ,
498509 } ) ;
499510 const rendered = mountWithIntl ( component ) ;
500511 noRollover ( rendered ) ;
@@ -507,6 +518,7 @@ describe('edit policy', () => {
507518 http . setupNodeListResponse ( {
508519 nodesByAttributes : { } ,
509520 nodesByRoles : { data_hot : [ 'test' ] , data_cold : [ 'test' ] } ,
521+ isUsingDeprecatedDataRoleConfig : false ,
510522 } ) ;
511523 const rendered = mountWithIntl ( component ) ;
512524 noRollover ( rendered ) ;
@@ -519,6 +531,7 @@ describe('edit policy', () => {
519531 http . setupNodeListResponse ( {
520532 nodesByAttributes : { } ,
521533 nodesByRoles : { data : [ 'test' ] } ,
534+ isUsingDeprecatedDataRoleConfig : false ,
522535 } ) ;
523536 const rendered = mountWithIntl ( component ) ;
524537 noRollover ( rendered ) ;
@@ -568,6 +581,7 @@ describe('edit policy', () => {
568581 http . setupNodeListResponse ( {
569582 nodesByAttributes : { } ,
570583 nodesByRoles : { data : [ 'node1' ] } ,
584+ isUsingDeprecatedDataRoleConfig : false ,
571585 } ) ;
572586 const rendered = mountWithIntl ( component ) ;
573587 noRollover ( rendered ) ;
@@ -626,6 +640,7 @@ describe('edit policy', () => {
626640 http . setupNodeListResponse ( {
627641 nodesByAttributes : { } ,
628642 nodesByRoles : { } ,
643+ isUsingDeprecatedDataRoleConfig : false ,
629644 } ) ;
630645 const rendered = mountWithIntl ( component ) ;
631646 noRollover ( rendered ) ;
@@ -638,6 +653,7 @@ describe('edit policy', () => {
638653 http . setupNodeListResponse ( {
639654 nodesByAttributes : { } ,
640655 nodesByRoles : { data_hot : [ 'test' ] , data_warm : [ 'test' ] } ,
656+ isUsingDeprecatedDataRoleConfig : false ,
641657 } ) ;
642658 const rendered = mountWithIntl ( component ) ;
643659 noRollover ( rendered ) ;
@@ -650,6 +666,7 @@ describe('edit policy', () => {
650666 http . setupNodeListResponse ( {
651667 nodesByAttributes : { } ,
652668 nodesByRoles : { data : [ 'test' ] } ,
669+ isUsingDeprecatedDataRoleConfig : false ,
653670 } ) ;
654671 const rendered = mountWithIntl ( component ) ;
655672 noRollover ( rendered ) ;
@@ -679,4 +696,104 @@ describe('edit policy', () => {
679696 expectedErrorMessages ( rendered , [ positiveNumberRequiredMessage ] ) ;
680697 } ) ;
681698 } ) ;
699+ describe ( 'not on cloud' , ( ) => {
700+ beforeEach ( ( ) => {
701+ server . respondImmediately = true ;
702+ } ) ;
703+ test ( 'should show all allocation options, even if using legacy config' , async ( ) => {
704+ http . setupNodeListResponse ( {
705+ nodesByAttributes : { test : [ '123' ] } ,
706+ nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } ,
707+ isUsingDeprecatedDataRoleConfig : true ,
708+ } ) ;
709+ const rendered = mountWithIntl ( component ) ;
710+ noRollover ( rendered ) ;
711+ setPolicyName ( rendered , 'mypolicy' ) ;
712+ await activatePhase ( rendered , 'warm' ) ;
713+ expect ( rendered . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ;
714+
715+ // Assert that only the custom and off options exist
716+ findTestSubject ( rendered , 'dataTierSelect' ) . simulate ( 'click' ) ;
717+ expect ( findTestSubject ( rendered , 'defaultDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
718+ expect ( findTestSubject ( rendered , 'customDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
719+ expect ( findTestSubject ( rendered , 'noneDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
720+ } ) ;
721+ } ) ;
722+ describe ( 'on cloud' , ( ) => {
723+ beforeEach ( ( ) => {
724+ component = (
725+ < KibanaContextProvider services = { { cloud : { isCloudEnabled : true } as CloudSetup } } >
726+ < EditPolicy
727+ history = { history }
728+ getUrlForApp = { jest . fn ( ) }
729+ policies = { policies }
730+ policyName = "test"
731+ />
732+ </ KibanaContextProvider >
733+ ) ;
734+ ( { http } = editPolicyHelpers . setup ( ) ) ;
735+ ( { server, httpRequestsMockHelpers } = http ) ;
736+ server . respondImmediately = true ;
737+
738+ httpRequestsMockHelpers . setPoliciesResponse ( policies ) ;
739+ } ) ;
740+
741+ describe ( 'with legacy data role config' , ( ) => {
742+ test ( 'should hide data tier option on cloud using legacy node role configuration' , async ( ) => {
743+ http . setupNodeListResponse ( {
744+ nodesByAttributes : { test : [ '123' ] } ,
745+ nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } ,
746+ isUsingDeprecatedDataRoleConfig : true ,
747+ } ) ;
748+ const rendered = mountWithIntl ( component ) ;
749+ noRollover ( rendered ) ;
750+ setPolicyName ( rendered , 'mypolicy' ) ;
751+ await activatePhase ( rendered , 'warm' ) ;
752+ expect ( rendered . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ;
753+
754+ // Assert that only the custom and off options exist
755+ findTestSubject ( rendered , 'dataTierSelect' ) . simulate ( 'click' ) ;
756+ expect ( findTestSubject ( rendered , 'defaultDataAllocationOption' ) . exists ( ) ) . toBeFalsy ( ) ;
757+ expect ( findTestSubject ( rendered , 'customDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
758+ expect ( findTestSubject ( rendered , 'noneDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
759+ } ) ;
760+ } ) ;
761+
762+ describe ( 'with node role config' , ( ) => {
763+ test ( 'should show off, custom and data role options on cloud with data roles' , async ( ) => {
764+ http . setupNodeListResponse ( {
765+ nodesByAttributes : { test : [ '123' ] } ,
766+ nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } ,
767+ isUsingDeprecatedDataRoleConfig : false ,
768+ } ) ;
769+ const rendered = mountWithIntl ( component ) ;
770+ noRollover ( rendered ) ;
771+ setPolicyName ( rendered , 'mypolicy' ) ;
772+ await activatePhase ( rendered , 'warm' ) ;
773+ expect ( rendered . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ;
774+
775+ findTestSubject ( rendered , 'dataTierSelect' ) . simulate ( 'click' ) ;
776+ expect ( findTestSubject ( rendered , 'defaultDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
777+ expect ( findTestSubject ( rendered , 'customDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
778+ expect ( findTestSubject ( rendered , 'noneDataAllocationOption' ) . exists ( ) ) . toBeTruthy ( ) ;
779+ } ) ;
780+
781+ test ( 'should show cloud notice when cold tier nodes do not exist' , async ( ) => {
782+ http . setupNodeListResponse ( {
783+ nodesByAttributes : { } ,
784+ nodesByRoles : { data : [ 'test' ] , data_hot : [ 'test' ] , data_warm : [ 'test' ] } ,
785+ isUsingDeprecatedDataRoleConfig : false ,
786+ } ) ;
787+ const rendered = mountWithIntl ( component ) ;
788+ noRollover ( rendered ) ;
789+ setPolicyName ( rendered , 'mypolicy' ) ;
790+ await activatePhase ( rendered , 'cold' ) ;
791+ expect ( rendered . find ( '.euiLoadingSpinner' ) . exists ( ) ) . toBeFalsy ( ) ;
792+ expect ( findTestSubject ( rendered , 'cloudDataTierCallout' ) . exists ( ) ) . toBeTruthy ( ) ;
793+ // Assert that other notices are not showing
794+ expect ( findTestSubject ( rendered , 'defaultAllocationNotice' ) . exists ( ) ) . toBeFalsy ( ) ;
795+ expect ( findTestSubject ( rendered , 'noNodeAttributesWarning' ) . exists ( ) ) . toBeFalsy ( ) ;
796+ } ) ;
797+ } ) ;
798+ } ) ;
682799} ) ;
0 commit comments