Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): Value.of(pageElement) returns a QuestionAdapter
- Loading branch information
Showing
3 changed files
with
140 additions
and
28 deletions.
There are no files selected for viewing
107 changes: 94 additions & 13 deletions
107
integration/web-specs/spec/screenplay/questions/Value.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,114 @@ | ||
import 'mocha'; | ||
|
||
import { Ensure, equals } from '@serenity-js/assertions'; | ||
import { Ensure, equals, not } from '@serenity-js/assertions'; | ||
import { actorCalled } from '@serenity-js/core'; | ||
import { By, Navigate, PageElement, Value } from '@serenity-js/web'; | ||
import { Attribute, By, Navigate, PageElement, PageElements, Value } from '@serenity-js/web'; | ||
import { expect } from '@integration/testing-tools'; | ||
|
||
/** @test {Value} */ | ||
describe('Value', () => { | ||
|
||
/** @test {Value.of} */ | ||
describe('of', () => { | ||
|
||
/** @test {Value} */ | ||
/** @test {Value.of} */ | ||
it('allows the actor to read the "value" attribute of a DOM element matching the locator', () => | ||
const input = PageElement.located(By.tagName('input')).describedAs('username field'); | ||
const form = PageElement.located(By.tagName('form')).describedAs(`form`); | ||
|
||
before(() => | ||
actorCalled('Bernie').attemptsTo( | ||
Navigate.to('/screenplay/questions/value/username_form.html'), | ||
|
||
Ensure.that(Value.of(PageElement.located(By.tagName('input')).describedAs('username field')), equals('jan-molak')), | ||
)); | ||
|
||
/** @test {Value} */ | ||
/** @test {Value#of} */ | ||
it('allows for a question relative to another target to be asked', () => | ||
it('allows the actor to read the "value" attribute of a DOM element matching the locator', () => | ||
actorCalled('Bernie').attemptsTo( | ||
Navigate.to('/screenplay/questions/value/username_form.html'), | ||
Ensure.that(Value.of(input), equals('jan-molak')), | ||
)); | ||
|
||
it('allows for a meta-question relative to another PageElement to be asked', () => | ||
actorCalled('Bernie').attemptsTo( | ||
Ensure.that( | ||
Value.of(PageElement.located(By.tagName('input')).describedAs('username field')) | ||
.of(PageElement.located(By.tagName('form')).describedAs(`form`)), | ||
Value.of(input).of(form), | ||
equals('jan-molak'), | ||
), | ||
)); | ||
|
||
it('produces a sensible description of the question being asked', () => { | ||
expect(Value.of(input).toString()) | ||
.to.equal(`the value of username field`); | ||
}); | ||
|
||
it('produces a QuestionAdapter that enables access to the underlying value', () => | ||
actorCalled('Bernie').attemptsTo( | ||
Ensure.that( | ||
Value.of(input).length, | ||
equals(9), | ||
), | ||
Ensure.that( | ||
Value.of(input).toLocaleUpperCase(), | ||
equals('JAN-MOLAK'), | ||
), | ||
)); | ||
}); | ||
|
||
describe('filtering', () => { | ||
|
||
const NonEmptyInput = | ||
PageElements.located(By.css('input')) | ||
.describedAs('input elements with non-empty value') | ||
.where(Value, not(equals(''))) | ||
.first(); | ||
|
||
before(() => | ||
actorCalled('Bernie').attemptsTo( | ||
Navigate.to('/screenplay/questions/value/filtering.html'), | ||
)); | ||
|
||
it('can be used to filter a list of elements', () => | ||
actorCalled('Wendy').attemptsTo( | ||
Ensure.that(Attribute.called('name').of(NonEmptyInput), equals('non-empty')), | ||
)); | ||
}); | ||
|
||
/** @test {Value#toString} */ | ||
describe('toString', () => { | ||
|
||
const sections = PageElements.located(By.css('section')).describedAs('sections'); | ||
const section = PageElement.located(By.css('section')).describedAs('a section'); | ||
const input = PageElement.located(By.css('input')).describedAs('input field'); | ||
|
||
it('provides a human-readable description of a regular question', () => { | ||
const description = Value.of(input).toString(); | ||
|
||
expect(description).to.equal(`the value of input field`) | ||
}); | ||
|
||
it('allows for the description to be altered', () => { | ||
const description = Value.of(input).describedAs('username').toString(); | ||
|
||
expect(description).to.equal(`username`) | ||
}); | ||
|
||
it('provides a human-readable description of the meta-question', () => { | ||
const description = Value.of(input).of(section).toString(); | ||
|
||
expect(description).to.equal(`the value of input field of a section`) | ||
}); | ||
|
||
it('provides a human-readable description of a reqular question used in a filter', () => { | ||
const found = sections.where(Value, equals('example')); | ||
|
||
const description = found.toString(); | ||
|
||
expect(description).to.equal(`sections where Value does equal 'example'`) | ||
}); | ||
|
||
it('provides a human-readable description of a meta-question used in a filter', () => { | ||
const found = sections | ||
.where(Value.of(input), equals('example')); | ||
|
||
const description = found.toString(); | ||
|
||
expect(description).to.equal(`sections where the value of input field does equal 'example'`) | ||
}); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
integration/web-specs/static/screenplay/questions/value/filtering.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html lang=""> | ||
<body> | ||
<form> | ||
<input name="empty" value="" /> | ||
<input name="non-empty" value="non-empty value" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters