import * as SUT from '../../playwright-fluent' ; import * as path from 'path' ; describe ( 'Playwright Fluent - uncheck' , ( ) : void => { let p ; beforeEach ( ( ) : void => { p = new SUT . PlaywrightFluent ( ) ; } ) ; afterEach ( async ( ) : Promise < void > => { await p . close ( ) ; } ) ; test ( 'should wait until selector is enabled - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = '#dynamically-added-input' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector ) ; const isUnchecked = await p . isUnchecked ( selector ) ; expect ( isUnchecked ) . toBe ( true ) ; await p . expectThatSelector ( selector ) . isUnchecked ( ) ; } ) ; test ( 'should wait until selector object is enabled - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = p . selector ( 'input#dynamically-added-input' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector ) ; await p . expectThat ( selector ) . isUnchecked ( ) ; const isUnchecked = await selector . isUnchecked ( ) ; expect ( isUnchecked ) . toBe ( true ) ; } ) ; test ( 'should do nothing when selector is already unchecked - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = '#unchecked-and-disabled' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector ) ; const isUnchecked = await p . isUnchecked ( selector ) ; expect ( isUnchecked ) . toBe ( true ) ; await p . expectThatSelector ( selector ) . isUnchecked ( ) ; } ) ; test ( 'should do nothing when selector object is already unchecked - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'I am unchecked and disabled' ) ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector ) ; const isUnchecked = await selector . isUnchecked ( ) ; expect ( isUnchecked ) . toBe ( true ) ; await p . expectThatSelector ( selector ) . isUnchecked ( ) ; } ) ; test ( 'should not uncheck a non existing selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = 'foobar' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Selector 'foobar' was not found in DOM" ) ; } ) ; test ( 'should not uncheck a non existing selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = p . selector ( 'foobar' ) ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Cannot uncheck 'selector(foobar)' because this selector was not found in DOM" ) ; } ) ; test ( 'should not uncheck a hidden selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = '#hidden' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Cannot hover on '#hidden' because this selector is not visible" ) ; } ) ; test ( 'should not uncheck a disabled selector - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = '#disabled' ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } expect ( result && result . message ) . toContain ( "Cannot uncheck '#disabled' because this selector is disabled" ) ; } ) ; test ( 'should not uncheck a disabled selector object - chromium' , async ( ) : Promise < void > => { const url = `file:${ path . join ( __dirname , 'uncheck.test.html' ) }` ; const selector = p . selector ( 'input' ) . withValue ( 'I am disabled' ) ; let result = undefined ; try { await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . navigateTo ( url ) . uncheck ( selector , { timeoutInMilliseconds : 2000 } ) ; } catch ( error ) { result = error as Error ; } const errorMessage = `Cannot uncheck 'selector(input)
  .withValue(I am disabled)' because this selector is disabled` ; expect ( result && result . message ) . toContain ( errorMessage ) ; } ) ; test ( 'should uncheck - chromium' , async ( ) : Promise < void > => { const url = 'https://reactstrap.github.io/?path=/docs/components-forms--input' ; const checkMeOut = p . selector ( 'label' ) . withText ( 'Check me out' ) . parent ( ) . find ( 'input' ) ; const storyBookIframe = 'iframe#storybook-preview-iframe' ; await p . withBrowser ( 'chromium' ) . withOptions ( { headless : false } ) . withCursor ( ) . emulateDevice ( 'iPhone 6 landscape' ) . navigateTo ( url ) . switchToIframe ( storyBookIframe ) . check ( checkMeOut ) . expectThatSelector ( checkMeOut ) . isChecked ( ) . uncheck ( checkMeOut ) . expectThatSelector ( checkMeOut ) . isUnchecked ( ) ; expect ( await checkMeOut . isUnchecked ( ) ) . toBe ( true ) ; expect ( await checkMeOut . isChecked ( ) ) . toBe ( false ) ; } ) ; } ) ;