import { Answerable, AnswersQuestions, Interaction, Question, UsesAbilities } from '@serenity-js/core'; import { formatted } from '@serenity-js/core/lib/io'; import { ElementFinder } from 'protractor'; import { withAnswerOf } from '../withAnswerOf'; export class Enter extends Interaction { static theValue(value: Answerable) { return { into: (field: Question | ElementFinder) => new Enter(value, field), }; } constructor( private readonly value: Answerable, private readonly field: Question | ElementFinder, ) { super(); } performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike { return actor.answer(this.value) .then(value => withAnswerOf(actor, this.field, elf => elf.sendKeys(value))); } toString(): string { return formatted `#actor enters ${this.value} into ${this.field}`; } }