import * as SUT from '../../../fluent-api' ; import * as path from 'path' ; describe ( 'Selector API - isEnabled' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should return false on wrong selector' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'is-enabled.test.html' ) }` ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : true } ) . withCursor ( ) . navigateTo ( url ) ; const selector = p . selector ( 'input' ) . withValue ( 'foo' ) ; const result = await selector . isEnabled ( ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return true when selector is enabled' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'is-enabled.test.html' ) }` ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : true } ) . withCursor ( ) . navigateTo ( url ) ; const selector = p . selector ( 'input' ) . withValue ( 'I am enabled' ) ; const result = await selector . isEnabled ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return true when selector is enabled #2' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'is-enabled.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'I am enabled' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : true } ) . withCursor ( ) . navigateTo ( url ) ; const result = await selector . isEnabled ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return false when selector is disabled' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'is-enabled.test.html' ) }` ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : true } ) . withCursor ( ) . navigateTo ( url ) ; const selector = p . selector ( 'input' ) . withValue ( 'I am disabled' ) ; const result = await selector . isEnabled ( ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should wait for selector to be enabled' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'is-enabled.test.html' ) }` ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : true } ) . withCursor ( ) . navigateTo ( url ) ; const selector = p . selector ( 'input#disabled-then-enabled-input' ) ; const initialEnabledStatus = await selector . isEnabled ( ) ; await p . waitUntil ( ( ) => selector . isEnabled ( ) ) ; const finalEnabledStatus = await selector . isEnabled ( ) ; expect ( initialEnabledStatus ) . toBe ( false ) ; expect ( finalEnabledStatus ) . toBe ( true ) ; } ) ; } ) ;