-
Notifications
You must be signed in to change notification settings - Fork 0
/
planets.steps.js
64 lines (43 loc) · 1.9 KB
/
planets.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
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(/^pPlanets should( not)? be selected$/i, flag =>
expect(SearchForm.planetsInput.isSelected()).toBe(!flag)
);
When(/^I (?:select|press|choose) (?:the )?Planets( button)?$/i, button => {
const { planetsInput, planetsLabel } = SearchForm;
(button ? planetsInput : planetsLabel).click()
});
When(/^I switch to Planets$/i, () => {
const { planetsInput, planetsLabel } = SearchForm;
planetsInput.click()
SearchForm.searchBtn.click()
});
Then(/^I should( not)? see a list of [pP]lanets$/i, notSee => {
homePage.loadingMsg.waitForDisplayed({ reverse : true });
const displayedPlanets = homePage.Planets.filter(p => p.container.isDisplayed()).map(p => p.asModel);
notSee ?
expect(displayedPlanets).toHaveLength(0) :
expect(displayedPlanets.length).toBeGreaterThan(0);
});
Then(/^each [pP]lanet should display its details$/i, () => {
homePage.loadingMsg.waitForDisplayed({ reverse : true });
const { Planets } = homePage;
expect(Planets.filter(p => p.container.isDisplayed())).not.toHaveLength(0);
Planets.forEach(({ name, climate, population, gravity }) =>
[name, climate, population, gravity].forEach(prop => {
expect(prop).toBeDisplayed();
expect(prop.getText()).not.toHaveLength(0);
})
)
});
Then(/^I should see (?:a|some) ([pP]lanets?) listed$/i, (dummy, table) => {
homePage.loadingMsg.waitForDisplayed({ reverse: true });
const expectedPlanets = sanitizeTable(table).map(c => _.mapValues(c, toLowerCase))
const actualPlanets = homePage.Planets.map(p => _.mapValues(p.asModel, toLowerCase))
expect(actualPlanets).toEqual(expect.arrayContaining(expectedPlanets.map(expect.objectContaining)));
});