import { loginAndWaitForTimeline } from '../../tasks/login' ; import { attachTimelineToNewCase , attachTimelineToExistingCase , addNewCase , selectCase , } from '../../tasks/timeline' ; import { DESCRIPTION_INPUT , ADD_COMMENT_INPUT } from '../../screens/create_new_case' ; import { getCase1 } from '../../objects/case' ; import { getTimeline } from '../../objects/timeline' ; import { createTimeline } from '../../tasks/api_calls/timelines' ; import { cleanKibana } from '../../tasks/common' ; import { createCase } from '../../tasks/api_calls/cases' ; describe ( 'attach timeline to case' , ( ) => { context ( 'without cases created' , ( ) => { beforeEach ( ( ) => { cleanKibana ( ) ; createTimeline ( getTimeline ( ) ) . then ( ( response ) => { cy . wrap ( response . body . data . persistTimeline . timeline ) . as ( 'myTimeline' ) ; } ) ; } ) ; it ( 'attach timeline to a new case' , function ( ) { loginAndWaitForTimeline ( this . myTimeline . savedObjectId ) ; attachTimelineToNewCase ( ) ; cy . location ( 'origin' ) . then ( ( origin ) => { cy . get ( DESCRIPTION_INPUT ) . should ( 'have.text' , `[${ this . myTimeline . title }](${ origin }/app/security/timelines?timeline=(id:%27${ this . myTimeline . savedObjectId }%27,isOpen:!t))` ) ; } ) ; } ) ; it ( 'attach timeline to an existing case with no case' , function ( ) { loginAndWaitForTimeline ( this . myTimeline . savedObjectId ) ; attachTimelineToExistingCase ( ) ; addNewCase ( ) ; cy . location ( 'origin' ) . then ( ( origin ) => { cy . get ( DESCRIPTION_INPUT ) . should ( 'have.text' , `[${ this . myTimeline . title }](${ origin }/app/security/timelines?timeline=(id:%27${ this . myTimeline . savedObjectId }%27,isOpen:!t))` ) ; } ) ; } ) ; } ) ; context ( 'with cases created' , ( ) => { before ( ( ) => { cleanKibana ( ) ; createTimeline ( getTimeline ( ) ) . then ( ( response ) => cy . wrap ( response . body . data . persistTimeline . timeline . savedObjectId ) . as ( 'timelineId' ) ) ; createCase ( getCase1 ( ) ) . then ( ( response ) => cy . wrap ( response . body . id ) . as ( 'caseId' ) ) ; } ) ; it ( 'attach timeline to an existing case' , function ( ) { loginAndWaitForTimeline ( this . timelineId ) ; attachTimelineToExistingCase ( ) ; selectCase ( this . caseId ) ; cy . location ( 'origin' ) . then ( ( origin ) => { cy . get ( ADD_COMMENT_INPUT ) . should ( 'have.text' , `[${ getTimeline ( ) . title }](${ origin }/app/security/timelines?timeline=(id:%27${ this . timelineId }%27,isOpen:!t))` ) ; } ) ; } ) ; } ) ; } ) ;