-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
isSelected.spec.ts
64 lines (54 loc) · 2.64 KB
/
isSelected.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { expect, stage } from '@integration/testing-tools';
import { Ensure } from '@serenity-js/assertions';
import { AssertionError } from '@serenity-js/core';
import { by } from 'protractor';
import { isSelected, Navigate, Target, Wait } from '../../src';
import { pageFromTemplate } from '../fixtures';
import { UIActors } from '../UIActors';
describe('isSelected', function () {
const Bernie = stage(new UIActors()).actor('Bernie');
const Languages = {
TypeScript: Target.the('TypeScript option').located(by.css('select[name="languages"] > option[value="TypeScript"]')),
JavaScript: Target.the('JavaScript option').located(by.css('select[name="languages"] > option[value="JavaScript"]')),
Java: Target.the('Java option').located(by.css('select[name="languages"] > option[value="Java"]')),
};
beforeEach(() => Bernie.attemptsTo(
Navigate.to(pageFromTemplate(`
<html>
<body>
<select name="languages">
<option selected value="TypeScript">TypeScript</option>
<option value="JavaScript">JavaScript</option>
</select>
</body>
</html>
`)),
));
/** @test {isSelected} */
it('allows the actor flow to continue when the element is selected', () => expect(Bernie.attemptsTo(
Wait.until(Languages.TypeScript, isSelected()),
Ensure.that(Languages.TypeScript, isSelected()),
)).to.be.fulfilled);
/** @test {isSelected} */
it('breaks the actor flow when element is not selected', () => {
return expect(Bernie.attemptsTo(
Ensure.that(Languages.JavaScript, isSelected()),
)).to.be.rejectedWith(AssertionError, `Expected the JavaScript option to become selected`);
});
/** @test {isSelected} */
it('breaks the actor flow when element is not present', () => {
return expect(Bernie.attemptsTo(
Ensure.that(Languages.Java, isSelected()),
)).to.be.rejectedWith(AssertionError, `Expected the Java option to become present`);
});
/** @test {isSelected} */
it('contributes to a human-readable description of an assertion', () => {
expect(Ensure.that(Languages.TypeScript, isSelected()).toString())
.to.equal(`#actor ensures that the TypeScript option does become selected`);
});
/** @test {isSelected} */
it('contributes to a human-readable description of a wait', () => {
expect(Wait.until(Languages.TypeScript, isSelected()).toString())
.to.equal(`#actor waits up to 5s until the TypeScript option does become selected`);
});
});