import { act } from 'react-dom/test-utils' ; import { setupEnvironment } from '../helpers' ; import { AppTestBed , setupAppPage } from './app.helpers' ; describe ( 'Cluster upgrade' , ( ) => { let testBed ; let server ; let httpRequestsMockHelpers ; beforeEach ( ( ) => { ( { server , httpRequestsMockHelpers } = setupEnvironment ( ) ) ; } ) ; afterEach ( ( ) => { server . restore ( ) ; } ) ; describe ( 'when user is still preparing for upgrade' , ( ) => { beforeEach ( async ( ) => { testBed = await setupAppPage ( ) ; } ) ; test ( 'renders overview' , ( ) => { const { exists } = testBed ; expect ( exists ( 'overview' ) ) . toBe ( true ) ; expect ( exists ( 'isUpgradingMessage' ) ) . toBe ( false ) ; expect ( exists ( 'isUpgradeCompleteMessage' ) ) . toBe ( false ) ; } ) ; } ) ; describe ( 'when cluster is in the process of a rolling upgrade' , ( ) => { beforeEach ( async ( ) => { httpRequestsMockHelpers . setLoadEsDeprecationsResponse ( undefined , { statusCode : 426 , message : '' , attributes : { allNodesUpgraded : false , } , } ) ; await act ( async ( ) => { testBed = await setupAppPage ( ) ; } ) ; } ) ; test ( 'renders rolling upgrade message' , async ( ) => { const { component , exists } = testBed ; component . update ( ) ; expect ( exists ( 'overview' ) ) . toBe ( false ) ; expect ( exists ( 'isUpgradingMessage' ) ) . toBe ( true ) ; expect ( exists ( 'isUpgradeCompleteMessage' ) ) . toBe ( false ) ; } ) ; } ) ; describe ( 'when cluster has been upgraded' , ( ) => { beforeEach ( async ( ) => { httpRequestsMockHelpers . setLoadEsDeprecationsResponse ( undefined , { statusCode : 426 , message : '' , attributes : { allNodesUpgraded : true , } , } ) ; await act ( async ( ) => { testBed = await setupAppPage ( ) ; } ) ; } ) ; test ( 'renders upgrade complete message' , ( ) => { const { component , exists } = testBed ; component . update ( ) ; expect ( exists ( 'overview' ) ) . toBe ( false ) ; expect ( exists ( 'isUpgradingMessage' ) ) . toBe ( false ) ; expect ( exists ( 'isUpgradeCompleteMessage' ) ) . toBe ( true ) ; } ) ; } ) ; } ) ;