import { setMockValues , setMockActions } from '../../../__mocks__/kea_logic' ; import React from 'react' ; import { shallow } from 'enzyme' ; import { EuiFlyout } from '@elastic/eui' ; import { ShowCreationModes , ApiCodeExample , PasteJsonText , UploadJsonFile , } from './creation_mode_components' ; import { Summary } from './creation_response_components' ; import { DocumentCreationFlyout , FlyoutContent } from './document_creation_flyout' ; import { DocumentCreationStep } from './types' ; describe ( 'DocumentCreationFlyout' , ( ) => { const values = { isDocumentCreationOpen : true , creationMode : 'text' , creationStep : DocumentCreationStep . AddDocuments , } ; const actions = { closeDocumentCreation : jest . fn ( ) , } ; beforeEach ( ( ) => { jest . clearAllMocks ( ) ; setMockValues ( values ) ; setMockActions ( actions ) ; } ) ; it ( 'renders a closeable flyout' , ( ) => { const wrapper = shallow ( < DocumentCreationFlyout />); expect ( wrapper . find ( EuiFlyout ) ) . toHaveLength ( 1 ) ; wrapper . find ( EuiFlyout ) . prop ( 'onClose' ) ( ) ; expect ( actions . closeDocumentCreation ) . toHaveBeenCalled ( ) ; } ) ; it ( 'does not render if isDocumentCreationOpen is false' , ( ) => { setMockValues ( { ... values , isDocumentCreationOpen : false } ) ; const wrapper = shallow ( < DocumentCreationFlyout />); expect ( wrapper . isEmptyRender ( ) ) . toBe ( true ) ; } ) ; describe ( 'FlyoutContent' , ( ) => { it ( 'renders ShowCreationModes' , ( ) => { setMockValues ( { ... values , creationStep : DocumentCreationStep . ShowCreationModes } ) ; const wrapper = shallow ( < FlyoutContent />); expect ( wrapper . find ( ShowCreationModes ) ) . toHaveLength ( 1 ) ; } ) ; describe ( 'creation modes' , ( ) => { it ( 'renders ApiCodeExample' , ( ) => { setMockValues ( { ... values , creationMode : 'api' } ) ; const wrapper = shallow ( < FlyoutContent />); expect ( wrapper . find ( ApiCodeExample ) ) . toHaveLength ( 1 ) ; } ) ; it ( 'renders PasteJsonText' , ( ) => { setMockValues ( { ... values , creationMode : 'text' } ) ; const wrapper = shallow ( < FlyoutContent />); expect ( wrapper . find ( PasteJsonText ) ) . toHaveLength ( 1 ) ; } ) ; it ( 'renders UploadJsonFile' , ( ) => { setMockValues ( { ... values , creationMode : 'file' } ) ; const wrapper = shallow ( < FlyoutContent />); expect ( wrapper . find ( UploadJsonFile ) ) . toHaveLength ( 1 ) ; } ) ; } ) ; it ( 'renders a summary' , ( ) => { setMockValues ( { ... values , creationStep : DocumentCreationStep . ShowSummary } ) ; const wrapper = shallow ( < FlyoutContent />); expect ( wrapper . find ( Summary ) ) . toHaveLength ( 1 ) ; } ) ; } ) ; } ) ;