import { setupEnvironment } from '../../helpers' ; import { OverviewTestBed , setupOverviewPage } from '../overview.helpers' ; const DEPLOYMENT_URL = 'https://cloud.elastic.co./deployments/bfdad4ef99a24212a06d387593686d63' ; const setupCloudOverviewPage = ( ) => { return setupOverviewPage ( { plugins : { cloud : { isCloudEnabled : true , deploymentUrl : DEPLOYMENT_URL , } , } , } ) ; } ; describe ( 'Overview - Upgrade Step' , ( ) => { let testBed ; const { server , httpRequestsMockHelpers , setServerAsync } = setupEnvironment ( ) ; afterAll ( ( ) => { server . restore ( ) ; } ) ; describe ( 'On-prem' , ( ) => { test ( 'Shows link to setup upgrade docs' , async ( ) => { testBed = await setupOverviewPage ( ) ; const { exists } = testBed ; expect ( exists ( 'upgradeSetupDocsLink' ) ) . toBe ( true ) ; expect ( exists ( 'upgradeSetupCloudLink' ) ) . toBe ( false ) ; } ) ; } ) ; describe ( 'On Cloud' , ( ) => { test ( 'When ready for upgrade, shows upgrade CTA and link to docs' , async ( ) => { httpRequestsMockHelpers . setGetUpgradeStatusResponse ( { readyForUpgrade : true , details : 'Ready for upgrade' , } ) ; testBed = await setupCloudOverviewPage ( ) ; const { exists , find , component } = testBed ; component . update ( ) ; expect ( exists ( 'upgradeSetupDocsLink' ) ) . toBe ( true ) ; expect ( exists ( 'upgradeSetupCloudLink' ) ) . toBe ( true ) ; expect ( find ( 'upgradeSetupCloudLink' ) . props ( ) . disabled ) . toBe ( false ) ; expect ( find ( 'upgradeSetupCloudLink' ) . props ( ) . href ) . toBe ( `${ DEPLOYMENT_URL }?show_upgrade=true` ) ; } ) ; test ( 'When not ready for upgrade, the CTA button is disabled' , async ( ) => { httpRequestsMockHelpers . setGetUpgradeStatusResponse ( { readyForUpgrade : false , details : 'Resolve critical deprecations first' , } ) ; testBed = await setupCloudOverviewPage ( ) ; const { exists , find , component } = testBed ; component . update ( ) ; expect ( exists ( 'upgradeSetupDocsLink' ) ) . toBe ( true ) ; expect ( exists ( 'upgradeSetupCloudLink' ) ) . toBe ( true ) ; expect ( find ( 'upgradeSetupCloudLink' ) . props ( ) . disabled ) . toBe ( true ) ; } ) ; test ( 'An error callout is displayed, if status check failed' , async ( ) => { httpRequestsMockHelpers . setGetUpgradeStatusResponse ( { } , { statusCode : 500 , message : 'Status check failed' } ) ; testBed = await setupCloudOverviewPage ( ) ; const { exists , component } = testBed ; component . update ( ) ; expect ( exists ( 'upgradeSetupDocsLink' ) ) . toBe ( false ) ; expect ( exists ( 'upgradeSetupCloudLink' ) ) . toBe ( false ) ; expect ( exists ( 'upgradeStatusErrorCallout' ) ) . toBe ( true ) ; } ) ; test ( 'The CTA button displays loading indicator' , async ( ) => { setServerAsync ( true ) ; testBed = await setupCloudOverviewPage ( ) ; const { exists , find } = testBed ; expect ( exists ( 'upgradeSetupDocsLink' ) ) . toBe ( true ) ; expect ( exists ( 'upgradeSetupCloudLink' ) ) . toBe ( true ) ; expect ( find ( 'upgradeSetupCloudLink' ) . childAt ( 0 ) . props ( ) . isLoading ) . toBe ( true ) ; } ) ; } ) ; } ) ;