import * as SUT from '../index' ; import { Browser , ElementHandle , chromium } from 'playwright' ; import * as path from 'path' ; describe ( 'handle has exact value' , ( ) : void => { let browser = undefined ; beforeEach ( ( ) : void => { } ) ; afterEach ( async ( ) : Promise < void > => { if ( browser ) { await browser . close ( ) ; } } ) ; test ( 'should return false when handle is undefined' , async ( ) : Promise < void > => { const handle = undefined ; const result = await SUT . hasHandleExactValue ( handle , 'foobar' ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when handle is null' , async ( ) : Promise < void > => { const handle = null ; const result = await SUT . hasHandleExactValue ( handle , 'foobar' ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when handle is null and expected value is empty' , async ( ) : Promise < void > => { const handle = null ; const result = await SUT . hasHandleExactValue ( handle , '' ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when handle is undefined and expected value is empty' , async ( ) : Promise < void > => { const handle = undefined ; const result = await SUT . hasHandleExactValue ( handle , '' ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return true when selector has exact value' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const inputSelector = '#emptyInput' ; await page . click ( inputSelector ) ; await page . type ( inputSelector , ' yo ' ) ; const handle = await page . $ ( inputSelector ) ; const result = await SUT . hasHandleExactValue ( handle , ' yo ' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return false when selector has not the value' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const inputSelector = '#emptyInput' ; await page . click ( inputSelector ) ; await page . type ( inputSelector , ' yo ' ) ; const handle = await page . $ ( inputSelector ) ; const result = await SUT . hasHandleExactValue ( handle , 'foobar' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when selector has not the exact value' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const inputSelector = '#emptyInput' ; await page . click ( inputSelector ) ; await page . type ( inputSelector , ' yo ' ) ; const handle = await page . $ ( inputSelector ) ; const result = await SUT . hasHandleExactValue ( handle , 'yo' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return true when selector has undefined value and expected is empty' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const handle = await page . $ ( '#withUndefinedValue' ) ; const result = await SUT . hasHandleExactValue ( handle , '' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return true when selector has empty value and expected is empty' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const handle = await page . $ ( '#emptyInput' ) ; const result = await SUT . hasHandleExactValue ( handle , '' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return true when selector has null value and expected is empty' , async ( ) : Promise < void > => { browser = await chromium . launch ( { headless : true } ) ; const browserContext = await browser . newContext ( { viewport : null } ) ; const page = await browserContext . newPage ( ) ; const url = `file:${ path . join ( __dirname , 'has-handle-exact-value.test.html' ) }` ; await page . goto ( url ) ; const handle = await page . $ ( '#withNullValue' ) ; const result = await SUT . hasHandleExactValue ( handle , '' ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( true ) ; } ) ; } ) ;