Skip to content
Permalink
Browse files
feat(protractor): Interaction: Clear
  • Loading branch information
jan-molak committed Feb 2, 2019
1 parent 2c54cd5 commit 5c8a25c3d83cc0aa42c5058b186f2c2315d3d029
@@ -0,0 +1,34 @@
import { endsWith, Ensure, equals } from '@serenity-js/assertions';
import { Actor } from '@serenity-js/core';
import { by, protractor } from 'protractor';

import { BrowseTheWeb, Clear, Navigate, Target, Value } from '../../../src';
import { pageFromTemplate } from '../../fixtures';

describe('Clear', () => {

const Bernie = Actor.named('Bernie').whoCan(
BrowseTheWeb.using(protractor.browser),
);

const Form = {
Field: Target.the('name field').located(by.id('name')),
};

/** @test {Enter} */
it('allows the actor to clear the value of a field', () => Bernie.attemptsTo(
Navigate.to(pageFromTemplate(`
<html>
<body>
<form>
<input type="text" id="name" value="Jan" />
</form>
</body>
</html>
`)),

Clear.theValueOf(Form.Field),

Ensure.that(Value.of(Form.Field), equals('')),
));
});
@@ -1,8 +1,8 @@
import { endsWith, Ensure, equals } from '@serenity-js/assertions';
import { Ensure, equals } from '@serenity-js/assertions';
import { Actor } from '@serenity-js/core';
import { by, protractor } from 'protractor';

import { BrowseTheWeb, Enter, Navigate, Target, Text, Value } from '../../../src';
import { BrowseTheWeb, Enter, Navigate, Target, Value } from '../../../src';
import { pageFromTemplate } from '../../fixtures';

describe('Enter', () => {
@@ -0,0 +1,22 @@
import { AnswersQuestions, Interaction, UsesAbilities } from '@serenity-js/core';
import { formatted } from '@serenity-js/core/lib/io';
import { ElementFinder } from 'protractor';
import { promiseOf } from '../promiseOf';
import { Target } from '../questions';

export class Clear implements Interaction {
static theValueOf(field: Target<ElementFinder>) {
return new Clear(field);
}

constructor(private readonly field: Target<ElementFinder>) {
}

performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> {
return promiseOf(this.field.answeredBy(actor).clear());
}

toString(): string {
return formatted `#actor clear the value of ${ this.field }`;
}
}
@@ -1,2 +1,3 @@
export * from './Clear';
export * from './Enter';
export * from './Navigate';

0 comments on commit 5c8a25c

Please sign in to comment.