import { ElementCondition , NullableLocatable } from '../Condition' ; import { EvaluateFn } from '../types' ; export class ElementVisibilityCondition extends ElementCondition { constructor ( desc , locator , ... args ) { super ( desc , locator ) ; this . pageFuncArgs = args ; } toString ( ) { return 'waiting for element to be visible on the page' ; } pageFunc : EvaluateFn = ( node , waitForVisible , waitForHidden ) => { if ( ! node ) return false ; function hasVisibleBoundingBox ( ) { const rect = node . getBoundingClientRect ( ) ; return ! ! ( rect . top || rect . bottom || rect . width || rect . height ) ; } const style = window . getComputedStyle ( node ) ; const isVisible = style && style . visibility !== 'hidden' && hasVisibleBoundingBox ( ) ; return waitForVisible === isVisible || waitForHidden === ! isVisible ; } ; async waitForEvent ( ) { return ; } } export class ElementLocatedCondition extends ElementCondition { constructor ( desc , locator , ... args ) { super ( desc , locator ) ; this . pageFuncArgs = args ; } toString ( ) { return 'waiting for element to be located on the page' ; } pageFunc : EvaluateFn = ( node , isPresent = true ) => { return ! ! node === isPresent ; } ; async waitForEvent ( ) { return ; } } export class ElementsLocatedCondition extends ElementCondition { constructor ( public desc , locator , ... args ) { super ( desc , locator ) ; this . pageFuncArgs = args ; } toString ( ) { const [ count ] = this . pageFuncArgs ; return `waiting for ${ count } elements to be located on the page` ; } get locatorPageFunc ( ) { return this . locator . pageFuncMany ; } pageFunc : EvaluateFn = ( nodes , count = 1 ) => { if ( typeof nodes === 'undefined' ) return false ; return nodes . length >= count ; } ; async waitForEvent ( ) { return ; } }