import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export default function canvasCustomElementTest ( { getService , getPageObjects , } ) { const testSubjects = getService ( 'testSubjects' ) ; const browser = getService ( 'browser' ) ; const retry = getService ( 'retry' ) ; const PageObjects = getPageObjects ( [ 'canvas' , 'common' ] ) ; const find = getService ( 'find' ) ; const kibanaServer = getService ( 'kibanaServer' ) ; const archive = 'x-pack/test/functional/fixtures/kbn_archiver/canvas/default' ; describe ( 'custom elements' , function ( ) { this . tags ( 'skipFirefox' ) ; before ( async ( ) => { await kibanaServer . importExport . load ( archive ) ; await PageObjects . common . navigateToApp ( 'canvas' ) ; await PageObjects . common . navigateToApp ( 'canvas' , { hash : '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31/page/1' , } ) ; } ) ; after ( async ( ) => { await kibanaServer . importExport . unload ( archive ) ; } ) ; it ( 'creates a custom element from an element when prompted' , async ( ) => { await testSubjects . click ( 'canvasWorkpadPage > canvasWorkpadPageElementContent' , 20000 ) ; await testSubjects . click ( 'canvasWorkpadEditMenuButton' , 20000 ) ; await testSubjects . click ( 'canvasWorkpadEditMenu__saveElementButton' , 20000 ) ; await PageObjects . canvas . fillOutCustomElementForm ( 'My New Element' , 'An excellent new element' ) ; await testSubjects . exists ( 'canvasCustomElementCreate-success' , { timeout : 30000 , } ) ; } ) ; it ( 'adds the custom element to the workpad when prompted' , async ( ) => { await PageObjects . canvas . openSavedElementsModal ( ) ; const customElement = await find . byCssSelector ( '.canvasElementCard__wrapper' ) ; const elementName = await customElement . findByCssSelector ( '.euiCard__title' ) ; expect ( await elementName . getVisibleText ( ) ) . to . contain ( 'My New Element' ) ; customElement . click ( ) ; await retry . try ( async ( ) => { const elements = await testSubjects . findAll ( 'canvasWorkpadPage > canvasWorkpadPageElementContent' ) ; expect ( elements ) . to . have . length ( 5 ) ; const newElem = elements [ 4 ] ; const md = await newElem . findByCssSelector ( '.canvasMarkdown' ) ; expect ( await md . getVisibleText ( ) ) . to . contain ( 'Welcome to Canvas' ) ; await newElem . click ( ) ; await browser . pressKeys ( browser . keys . DELETE ) ; const elementsAgain = await testSubjects . findAll ( 'canvasWorkpadPage > canvasWorkpadPageElementContent' ) ; expect ( elementsAgain ) . to . have . length ( 4 ) ; } ) ; } ) ; it ( 'saves custom element modifications' , async ( ) => { await PageObjects . canvas . openSavedElementsModal ( ) ; const customElements = await find . allByCssSelector ( '.canvasElementCard__wrapper' ) ; expect ( customElements ) . to . have . length ( 1 ) ; const customElement = customElements [ 0 ] ; await customElement . moveMouseTo ( ) ; await testSubjects . click ( 'canvasElementCard__editButton' , 20000 ) ; await PageObjects . canvas . fillOutCustomElementForm ( 'My Edited New Element' , 'An excellent edited element' ) ; await retry . try ( async ( ) => { const elementName = await find . byCssSelector ( '.canvasElementCard__wrapper .euiCard__title' ) ; expect ( await elementName . getVisibleText ( ) ) . to . contain ( 'My Edited New Element' ) ; } ) ; await PageObjects . canvas . closeSavedElementsModal ( ) ; } ) ; it ( 'deletes custom element when prompted' , async ( ) => { await PageObjects . canvas . openSavedElementsModal ( ) ; const customElements = await find . allByCssSelector ( '.canvasElementCard__wrapper' ) ; expect ( customElements ) . to . have . length ( 1 ) ; const customElement = customElements [ 0 ] ; await customElement . moveMouseTo ( ) ; await testSubjects . click ( 'canvasElementCard__deleteButton' , 20000 ) ; await testSubjects . click ( 'confirmModalConfirmButton' , 20000 ) ; await retry . try ( async ( ) => { const customElementsAgain = await find . allByCssSelector ( '.canvasElementCard__wrapper' ) ; expect ( customElementsAgain ) . to . have . length ( 0 ) ; } ) ; await PageObjects . canvas . closeSavedElementsModal ( ) ; } ) ; } ) ; }