import { AnswersQuestions , Expectation , ExpectationMet , MetaQuestion , Question , UsesAbilities } from '@serenity-js/core' ; import { formatted } from '@serenity-js/core/lib/io' ; import { ListAdapter } from '@serenity-js/core/lib/screenplay/questions/lists' ; import { ElementArrayFinder , ElementFinder } from 'protractor' ; desc Adapts  ElementArrayFinder so that it can be used with  {@link @serenity-js/core/lib/screenplay/questions~List} .
 *
 *  You most likely won't need to use this class directly. Instead, check out  Target and  Target . all .
 *
 *  see Target implements serenity-js export class ElementArrayFinderListAdapter implements ListAdapter < ElementFinder , ElementArrayFinder > { param { Question < ElementArrayFinder > | ElementArrayFinder } collection constructor ( private readonly collection ) { } desc Returns the number of  ElementFinder s that the underlying  ElementArrayFinder contains,
     *  left after applying any filters.
     *
     *  param { AnswersQuestions & UsesAbilities } actor returns { Promise < number > } count ( actor ) { return Promise . resolve ( this . elements ( actor ) . count ( ) ) ; } desc Returns the first of  ElementFinder s that the underlying  ElementArrayFinder contains,
     *  left after applying any filters
     *
     *  param { AnswersQuestions & UsesAbilities } actor returns { ElementFinder } first ( actor ) { return this . elements ( actor ) . first ( ) ; } desc Returns the last of  ElementFinder s that the underlying  ElementArrayFinder contains,
     *  left after applying any filters
     *
     *  param { AnswersQuestions & UsesAbilities } actor returns { ElementFinder } last ( actor ) { return this . elements ( actor ) . last ( ) ; } desc Returns the nth of  ElementFinder s that the underlying  ElementArrayFinder contains,
     *  left after applying any filters
     *
     *  param { AnswersQuestions & UsesAbilities } actor param { number } index returns { ElementFinder } get ( actor , index ) { return this . elements ( actor ) . get ( index ) ; } desc Returns the underlying  ElementArrayFinder ,
     *  with any filters applied.
     *
     *  param { AnswersQuestions & UsesAbilities } actor returns { ElementFinder } items ( actor ) { return this . elements ( actor ) ; } desc Filters the underlying  ElementArrayFinder so that the result contains only those  ElementFinder s that meet the  Expectation param { serenity-js param { serenity-js returns { serenity-js see {@link @serenity-js/core/lib/screenplay/questions~MetaQuestion} withFilter < Answer_Type > ( question , expectation ) { return new ElementArrayFinderListAdapter ( new ElementArrayFinderArrayListFilter ( this . collection , question , expectation ) ) ; } desc Returns a human-readable description of the underlying  ElementArrayFinder .
     *
     *  returns { string } toString ( ) { return formatted `${ this . collection }` ; } private elements ( actor ) { return Question . isAQuestion ( this . collection ) ? this . collection . answeredBy ( actor ) : this . collection ; } } private class ElementArrayFinderArrayListFilter < Answer_Type > extends Question < ElementArrayFinder > { constructor ( private readonly collection , private readonly question , private readonly expectation ) { super ( [ formatted `${ collection }` , collection instanceof ElementArrayFinderArrayListFilter ? 'and' : 'where' , formatted `${ question } does ${ expectation }` ] . join ( ' ' ) ) ; } answeredBy ( actor ) { return this . finderAs ( actor ) . filter ( ( elementFinder ) => Promise . resolve ( this . question . of ( elementFinder ) . answeredBy ( actor ) ) . then ( answer => this . expectation . answeredBy ( actor ) ( answer ) ) . then ( outcome => outcome instanceof ExpectationMet ) ) ; } private finderAs ( actor ) { return Question . isAQuestion ( this . collection ) ? this . collection . answeredBy ( actor ) : this . collection ; } }