import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - runStory' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should chain two stories - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'run-story.test.html' ) }` ; const selector = 'select#selectWithBlankOption' ; interface StartAppProps { browser : SUT . BrowserName ; isHeadless : boolean ; url : string ; } const startApp = async ( p , props ) => { await p . withBrowser ( props . browser ) . withOptions ( { headless : props . isHeadless } ) . withCursor ( ) . navigateTo ( props . url ) ; } ; const selectLabel = async ( p , label ) => { await p . select ( label ) . in ( selector ) ; } ; await p . runStory ( startApp , { browser : 'chromium' , isHeadless : false , url } ) . runStory ( selectLabel , 'label 2' ) ; const value = await p . getValueOf ( selector ) ; expect ( value ) . toBe ( 'value 2' ) ; } ) ; test ( 'should run embedded stories - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'run-story.test.html' ) }` ; const selector = 'select#selectWithBlankOption' ; interface StartAppProps { browser : SUT . BrowserName ; isHeadless : boolean ; url : string ; } const startApp = async ( p , props ) => { await p . withBrowser ( props . browser ) . withOptions ( { headless : props . isHeadless } ) . withCursor ( ) . navigateTo ( props . url ) ; } ; const selectLabel = async ( p , label ) => { await p . select ( label ) . in ( selector ) ; } ; const mainStory = async ( p ) => { await p . runStory ( startApp , { browser : 'chromium' , isHeadless : false , url } ) . runStory ( selectLabel , 'label 2' ) ; } ; await p . runStory ( mainStory ) ; const value = await p . getValueOf ( selector ) ; expect ( value ) . toBe ( 'value 2' ) ; } ) ; test ( 'should combine stories - chromium' , async ( ) : Promise < void > => { const results = [ ] ; const storyA1 = async ( p ) => { results . push ( 'storyA1' ) ; await p . expectThatAsyncFunc ( async ( ) => true ) . resolvesTo ( true ) ; } ; const storyA2 = async ( p ) => { results . push ( 'storyA2' ) ; await p . expectThatAsyncFunc ( async ( ) => true ) . resolvesTo ( true ) ; } ; const storyA = async ( p ) => { results . push ( 'storyA' ) ; await p . runStory ( storyA1 ) . and ( storyA2 ) ; } ; const storyB1 = async ( p ) => { results . push ( 'storyB1' ) ; await p . expectThatAsyncFunc ( async ( ) => true ) . resolvesTo ( true ) ; } ; const storyB2 = async ( p ) => { results . push ( 'storyB2' ) ; await p . expectThatAsyncFunc ( async ( ) => true ) . resolvesTo ( true ) ; } ; const storyB = async ( p ) => { results . push ( 'storyB' ) ; await p . do ( storyB1 ) . and ( storyB2 ) ; } ; const mainStory = async ( p ) => { await p . attemptsTo ( storyA ) ; await p . and ( storyB ) ; } ; await p . verifyIf ( mainStory ) ; expect ( results . join ( ) ) . toBe ( 'storyA,storyA1,storyA2,storyB,storyB1,storyB2' ) ; } ) ; } ) ;