Skip to content

Commit cd592f7

Browse files
committed
e2e test update
1 parent 99f710b commit cd592f7

File tree

1 file changed

+87
-40
lines changed
  • public/docs/_examples/hierarchical-dependency-injection

1 file changed

+87
-40
lines changed
Lines changed: 87 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,103 @@
1-
import { browser, element, by } from 'protractor';
1+
'use strict'; // necessary for es6 output in node
22

3-
describe('Hierarchical dependency injection', function () {
3+
import { browser, by, element } from 'protractor';
44

5-
beforeEach(function () {
5+
describe('Hierarchical dependency injection', () => {
6+
7+
beforeAll(() => {
68
browser.get('');
79
});
810

9-
it('should open with a card view', function () {
10-
expect(element.all(by.cssContainingText('button', 'edit')).get(0).isDisplayed()).toBe(true,
11-
'edit button should be displayed');
12-
});
11+
describe('Heroes Scenario', () => {
12+
let page = {
13+
heroName: '',
14+
income: '',
1315

14-
it('should have multiple heroes listed', function () {
15-
expect(element.all(by.css('heroes-list li')).count()).toBeGreaterThan(1);
16-
});
16+
// queries
17+
heroEl: element.all(by.css('heroes-list li')).get(0), // first hero
18+
heroCardEl: element(by.css('heroes-list hero-tax-return')), // first hero tax-return
19+
taxReturnNameEl: element.all(by.css('heroes-list hero-tax-return #name')).get(0),
20+
incomeInputEl: element.all(by.css('heroes-list hero-tax-return input')).get(0),
21+
cancelButtonEl: element(by.cssContainingText('heroes-list hero-tax-return button', 'Cancel')),
22+
closeButtonEl: element(by.cssContainingText('heroes-list hero-tax-return button', 'Close')),
23+
saveButtonEl: element(by.cssContainingText('heroes-list hero-tax-return button', 'Save'))
24+
};
1725

18-
it('should change to editor view after selection', function () {
19-
let editButtonEle = element.all(by.cssContainingText('button', 'edit')).get(0);
20-
editButtonEle.click().then(function() {
21-
expect(editButtonEle.isDisplayed()).toBe(false, 'edit button should be hidden after selection');
26+
it('should list multiple heroes', () => {
27+
expect(element.all(by.css('heroes-list li')).count()).toBeGreaterThan(1);
28+
});
29+
30+
it('should show no hero tax-returns at the start', () => {
31+
expect(element.all(by.css('heroes-list li hero-tax-return')).count()).toBe(0);
32+
});
33+
34+
it('should open first hero in hero-tax-return view after click', () => {
35+
page.heroEl.getText()
36+
.then(val => {
37+
page.heroName = val;
38+
})
39+
.then(() => page.heroEl.click())
40+
.then(() => {
41+
expect(page.heroCardEl.isDisplayed()).toBe(true);
42+
});
43+
});
44+
45+
it('hero tax-return should have first hero\'s name', () => {
46+
// Not `page.tax-returnNameInputEl.getAttribute('value')` although later that is essential
47+
expect(page.taxReturnNameEl.getText()).toEqual(page.heroName);
48+
});
49+
50+
it('should be able to cancel change', () => {
51+
page.incomeInputEl.clear()
52+
.then(() => page.incomeInputEl.sendKeys('777'))
53+
.then(() => {
54+
expect(page.incomeInputEl.getAttribute('value')).toBe('777', 'income should be 777');
55+
return page.cancelButtonEl.click();
56+
})
57+
.then(() => {
58+
expect(page.incomeInputEl.getAttribute('value')).not.toBe('777', 'income should not be 777');
59+
});
60+
});
61+
62+
it('should be able to save change', () => {
63+
page.incomeInputEl.clear()
64+
.then(() => page.incomeInputEl.sendKeys('999'))
65+
.then(() => {
66+
expect(page.incomeInputEl.getAttribute('value')).toBe('999', 'income should be 999');
67+
return page.saveButtonEl.click();
68+
})
69+
.then(() => {
70+
expect(page.incomeInputEl.getAttribute('value')).toBe('999', 'income should still be 999');
71+
});
72+
});
73+
74+
it('should be able to close tax-return', () => {
75+
page.saveButtonEl.click()
76+
.then(() => {
77+
expect(element.all(by.css('heroes-list li hero-tax-return')).count()).toBe(0);
78+
});
2279
});
23-
});
2480

25-
it('should be able to save editor change', function () {
26-
testEdit(true);
2781
});
2882

29-
it('should be able to cancel editor change', function () {
30-
testEdit(false);
83+
describe('Villains Scenario', () => {
84+
it('should list multiple villains', () => {
85+
expect(element.all(by.css('villains-list li')).count()).toBeGreaterThan(1);
86+
});
3187
});
3288

33-
function testEdit(shouldSave: boolean) {
34-
// select 2nd ele
35-
let heroEle = element.all(by.css('heroes-list li')).get(1);
36-
// get the 2nd span which is the name of the hero
37-
let heroNameEle = heroEle.all(by.css('hero-card span')).get(1);
38-
let editButtonEle = heroEle.element(by.cssContainingText('button', 'edit'));
39-
editButtonEle.click().then(function() {
40-
let inputEle = heroEle.element(by.css('hero-editor input'));
41-
return inputEle.sendKeys('foo');
42-
}).then(function() {
43-
let buttonName = shouldSave ? 'save' : 'cancel';
44-
let buttonEle = heroEle.element(by.cssContainingText('button', buttonName));
45-
return buttonEle.click();
46-
}).then(function() {
47-
if (shouldSave) {
48-
expect(heroNameEle.getText()).toContain('foo');
49-
} else {
50-
expect(heroNameEle.getText()).not.toContain('foo');
51-
}
52-
});
53-
}
89+
describe('Cars Scenario', () => {
5490

91+
it('A-component should use expected services', () => {
92+
expect(element(by.css('a-car')).getText()).toContain('C1-E1-T1');
93+
});
94+
95+
it('B-component should use expected services', () => {
96+
expect(element(by.css('b-car')).getText()).toContain('C2-E2-T1');
97+
});
5598

99+
it('C-component should use expected services', () => {
100+
expect(element(by.css('c-car')).getText()).toContain('C3-E2-T1');
101+
});
102+
});
56103
});

0 commit comments

Comments
 (0)