import { AnswersQuestions , Interaction , LogicError , Question , UsesAbilities } from '@serenity-js/core' ; import { formatted } from '@serenity-js/core/lib/io' ; import { ElementFinder , protractor } from 'protractor' ; import { Value } from '../questions' ; import { withAnswerOf } from '../withAnswerOf' ; desc Instructs the  {@link @serenity-js/core/lib/screenplay/actor~Actor} to
 *  clear the `value` of a [form `input`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
 *
 *  example example example see BrowseTheWeb see Enter see Value see Target see {@link @serenity-js/assertions~Ensure} see {@link @serenity-js/assertions/lib/expectations~equals} extends serenity-js export class Clear extends Interaction { desc Instantiates this  {@link @serenity-js/core/lib/screenplay~Interaction} .
     *
     *  param { Question < ElementFinder > | ElementFinder } field returns { serenity-js static theValueOf ( field ) { return new Clear ( field ) ; } param { Question < ElementFinder > | ElementFinder } field constructor ( private readonly field ) { super ( ) ; } desc Makes the provided  {@link @serenity-js/core/lib/screenplay/actor~Actor} *  perform this  {@link @serenity-js/core/lib/screenplay~Interaction} .
     *
     *  param { UsesAbilities & AnswersQuestions } actor An  {@link @serenity-js/core/lib/screenplay/actor~Actor} to perform this  {@link @serenity-js/core/lib/screenplay~Interaction} returns { PromiseLike < void > } see {@link @serenity-js/core/lib/screenplay/actor~Actor} see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities} see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions} performAs ( actor ) { return new Value ( this . field ) . answeredBy ( actor ) . then ( value => { if ( value === null ) { throw new LogicError ( `${ this . capitaliseFirstLetter ( this . field . toString ( ) ) } doesn't seem to have a 'value' attribute that could be cleared.` ) ; } if ( value !== undefined ) { return withAnswerOf ( actor , this . field , ( elf ) => { return this . removeCharactersFrom ( elf , value . length ) ; } ) ; } } ) ; } desc Generates a description to be used when reporting this  {@link @serenity-js/core/lib/screenplay~Activity} .
     *
     *  returns { string } toString ( ) { return formatted `#actor clears the value of ${ this . field }` ; } private capitaliseFirstLetter ( text ) { return text . charAt ( 0 ) . toUpperCase ( ) + text . slice ( 1 ) ; } private removeCharactersFrom ( elf , numberOfCharacters ) { return numberOfCharacters === 0 ? Promise . resolve ( void 0 ) : elf . sendKeys ( protractor . Key . END , ... this . times ( numberOfCharacters , protractor . Key . BACK_SPACE ) ) ; } private times ( length , key ) { return Array . from ( { length } ) . map ( ( ) => key ) ; } }