import { AnswersQuestions, Question, UsesAbilities } from '@serenity-js/core'; import { formatted } from '@serenity-js/core/lib/io'; import { ElementFinder } from 'protractor'; import { Attribute } from './Attribute'; import { RelativeQuestion } from './RelativeQuestion'; import { TargetNestedElement } from './targets'; export class CSSClasses implements Question>, RelativeQuestion | ElementFinder, Promise> { static of(target: Question | ElementFinder) { return new CSSClasses(target); } constructor(private readonly target: Question | ElementFinder) { } of(parent: Question | ElementFinder): Question> { return new CSSClasses(new TargetNestedElement(parent, this.target)); } answeredBy(actor: AnswersQuestions & UsesAbilities): Promise { return Attribute.of(this.target).called('class').answeredBy(actor) .then(attribute => attribute .replace(/\s+/, ' ') .trim() .split(' ') .filter(cssClass => !! cssClass), ); } toString(): string { return formatted `the CSS classes of ${ this.target}`; } }