import * as SUT from '../index' ; import { defaultVerboseOptions } from '../../is-handle-visible' ; import { sleep } from '../../../../utils' ; import { Browser , ElementHandle , chromium } from 'playwright' ; import * as path from 'path' ; describe ( 'handle is read-only' , ( ) : 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 . isHandleReadOnly ( handle , defaultVerboseOptions ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when handle is null' , async ( ) : Promise < void > => { const handle = null ; const result = await SUT . isHandleReadOnly ( handle , defaultVerboseOptions ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return false when selector has no readOnly property' , 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 , 'is-handle-read-only.test.html' ) }` ; await page . goto ( url ) ; await sleep ( 1000 ) ; const handle = await page . $ ( 'p' ) ; const result = await SUT . isHandleReadOnly ( handle , defaultVerboseOptions ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( false ) ; } ) ; test ( 'should return true when selector is read-only' , 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 , 'is-handle-read-only.test.html' ) }` ; await page . goto ( url ) ; await sleep ( 1000 ) ; const handle = await page . $ ( '#readonlyInput' ) ; const result = await SUT . isHandleReadOnly ( handle , defaultVerboseOptions ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( true ) ; } ) ; test ( 'should return false when selector is not readonly' , 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 , 'is-handle-read-only.test.html' ) }` ; await page . goto ( url ) ; await sleep ( 1000 ) ; const handle = await page . $ ( '#enabledInput' ) ; const result = await SUT . isHandleReadOnly ( handle , defaultVerboseOptions ) ; expect ( handle ) . toBeDefined ( ) ; expect ( result ) . toBe ( false ) ; } ) ; } ) ;