-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeople.steps.js
69 lines (47 loc) · 2.04 KB
/
people.steps.js
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
65
66
67
68
69
import { Given, When, Then } from "cucumber";
import HomePage from "../pages/Home.page";
const homePage = new HomePage();
const { SearchForm } = homePage;
import _ from "lodash";
import { sanitizeTable } from "../utils/helpers";
const toLowerCase = v => _.isString(v) ? v.toLowerCase() : v;
Then(/^[pP]eople should( not)? be selected$/i,
flag => expect(SearchForm.peopleInput.isSelected()).toBe(!flag)
);
When(/^I (?:select|press|choose) (?:the )?People( button)?$/i, button => {
const { peopleInput, peopleLabel } = SearchForm;
(button ? peopleInput : peopleLabel).click()
});
When(/^I switch to People$/i, () => {
const { peopleInput } = SearchForm;
peopleInput.click()
SearchForm.searchBtn.click()
});
Then(/^I (should(?: not)?) see a list of (?:[pP]eople|[cC]haracters)$/i, should => {
homePage.loadingMsg.waitForDisplayed({ reverse : true });
const displayedCharacters = homePage.Characters.filter(p => p.container.isDisplayed()).map(r => r.asModel);
should.includes("not") ?
expect(displayedCharacters).toHaveLength(0) :
expect(displayedCharacters.length).toBeGreaterThan(0);
});
Then(/^each [cC]haracter should display its details$/i, () => {
homePage.loadingMsg.waitForDisplayed({ reverse : true });
const { Characters } = homePage;
expect(Characters.filter(p => p.container.isDisplayed())).not.toHaveLength(0);
Characters.forEach(({ name, gender, birthYear, eyeColor, skinColor }) =>
[name, gender, birthYear, eyeColor, skinColor].forEach(prop => {
expect(prop).toBeDisplayed();
expect(prop.getText()).not.toHaveLength(0);
})
)
});
Then(/^I should see (?:a|some) ([cC]haracters?) listed$/i, (dummy, table) => {
homePage.loadingMsg.waitForDisplayed({ reverse: true });
const expectedCharacters = sanitizeTable(table)
.map(c => _.pickBy(c, d => d !== undefined))
.map(c => _.mapValues(c, toLowerCase))
const actualCharacters = homePage.Characters
.map(c => c.asModel)
.map(c => _.mapValues(c, toLowerCase))
expect(actualCharacters).toEqual(expect.arrayContaining(expectedCharacters.map(expect.objectContaining)));
});