import { DocTitleService } from './doc_title_service' ; describe ( 'DocTitleService' , ( ) => { const defaultTitle = 'OpenSearchDashboardsTest' ; const document = { title : '' } ; const getStart = ( title = defaultTitle ) => { document . title = title ; return new DocTitleService ( ) . start ( { document } ) ; } ; beforeEach ( ( ) => { document . title = defaultTitle ; } ) ; describe ( '#change()' , ( ) => { it ( 'changes the title of the document' , async ( ) => { getStart ( ) . change ( 'TitleA' ) ; expect ( document . title ) . toEqual ( 'TitleA - OpenSearchDashboardsTest' ) ; } ) ; it ( 'appends the baseTitle to the title' , async ( ) => { const start = getStart ( 'BaseTitle' ) ; start . change ( 'TitleA' ) ; expect ( document . title ) . toEqual ( 'TitleA - BaseTitle' ) ; start . change ( 'TitleB' ) ; expect ( document . title ) . toEqual ( 'TitleB - BaseTitle' ) ; } ) ; it ( 'accepts string arrays as input' , async ( ) => { const start = getStart ( ) ; start . change ( [ 'partA' , 'partB' ] ) ; expect ( document . title ) . toEqual ( `partA - partB - ${ defaultTitle }` ) ; start . change ( [ 'partA' , 'partB' , 'partC' ] ) ; expect ( document . title ) . toEqual ( `partA - partB - partC - ${ defaultTitle }` ) ; } ) ; } ) ; describe ( '#reset()' , ( ) => { it ( 'resets the title to the initial value' , async ( ) => { const start = getStart ( 'InitialTitle' ) ; start . change ( 'TitleA' ) ; expect ( document . title ) . toEqual ( 'TitleA - InitialTitle' ) ; start . reset ( ) ; expect ( document . title ) . toEqual ( 'InitialTitle' ) ; } ) ; } ) ; } ) ;