|
1 |
| -import { browser, element, by } from 'protractor'; |
| 1 | +'use strict'; // necessary for es6 output in node |
2 | 2 |
|
3 |
| -describe('Hierarchical dependency injection', function () { |
| 3 | +import { browser, by, element, ElementFinder } from 'protractor'; |
4 | 4 |
|
5 |
| - beforeEach(function () { |
| 5 | +describe('Hierarchical dependency injection', () => { |
| 6 | + |
| 7 | + beforeAll(() => { |
6 | 8 | browser.get('');
|
7 | 9 | });
|
8 | 10 |
|
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 | + heroText: '', |
13 | 15 |
|
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-card')), // first hero card |
| 19 | + cardNameInputEl: element.all(by.css('heroes-list hero-card input')).get(0), |
| 20 | + cancelButtonEl: element(by.cssContainingText('heroes-list hero-card button', 'Cancel')), |
| 21 | + closeButtonEl: element(by.cssContainingText('heroes-list hero-card button', 'Close')), |
| 22 | + saveButtonEl: element(by.cssContainingText('heroes-list hero-card button', 'Save')) |
| 23 | + } |
17 | 24 |
|
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'); |
| 25 | + it('should list multiple heroes', () => { |
| 26 | + expect(element.all(by.css('heroes-list li')).count()).toBeGreaterThan(1); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should show no hero cards at the start', () => { |
| 30 | + expect(element.all(by.css('heroes-list li hero-card')).count()).toBe(0); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should open first hero in hero-card view after click', () => { |
| 34 | + page.heroEl.getText() |
| 35 | + .then(val => { |
| 36 | + // console.log('Selected hero text: ' + val); |
| 37 | + page.heroText = val; |
| 38 | + page.heroName = val.substring(0, val.indexOf('()') - 1) |
| 39 | + }) |
| 40 | + .then(() => page.heroEl.click()) |
| 41 | + .then(() => { |
| 42 | + expect(page.heroCardEl.isDisplayed()).toBe(true); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + it('hero card should have first hero\'s name', () => { |
| 47 | + // Not `page.cardNameInputEl.getAttribute('value')` although later that is essential |
| 48 | + expect(page.cardNameInputEl.getText()).toEqual(page.heroName); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should be able to cancel change', () => { |
| 52 | + page.cardNameInputEl.sendKeys('foo') |
| 53 | + .then(() => { |
| 54 | + expect(page.cardNameInputEl.getAttribute('value')).toContain('foo', 'input name should have foo'); |
| 55 | + expect(page.heroEl.getText()).toEqual(page.heroText, 'list text should be unchanged'); |
| 56 | + return page.cancelButtonEl.click(); |
| 57 | + }) |
| 58 | + .then(() => { |
| 59 | + expect(page.cardNameInputEl.getAttribute('value')).not.toContain('foo', 'input name should not have foo'); |
| 60 | + expect(page.heroEl.getText()).toEqual(page.heroText, 'list text should be unchanged'); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should be able to save change', () => { |
| 65 | + page.cardNameInputEl.sendKeys('bar') |
| 66 | + .then(() => { |
| 67 | + expect(page.cardNameInputEl.getAttribute('value')).toContain('bar', 'input name should have bar'); |
| 68 | + expect(page.heroEl.getText()).toEqual(page.heroText, 'list text should be unchanged'); |
| 69 | + return page.saveButtonEl.click(); |
| 70 | + }) |
| 71 | + .then(() => { |
| 72 | + expect(page.cardNameInputEl.getAttribute('value')).toContain('bar', 'input name should still have bar'); |
| 73 | + expect(page.heroEl.getText()).toContain('bar', 'list text should have changed to include bar'); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should be able to close card', () => { |
| 78 | + page.saveButtonEl.click() |
| 79 | + .then(() => { |
| 80 | + expect(element.all(by.css('heroes-list li hero-card')).count()).toBe(0); |
| 81 | + }); |
22 | 82 | });
|
23 |
| - }); |
24 | 83 |
|
25 |
| - it('should be able to save editor change', function () { |
26 |
| - testEdit(true); |
27 | 84 | });
|
28 | 85 |
|
29 |
| - it('should be able to cancel editor change', function () { |
30 |
| - testEdit(false); |
| 86 | + describe('Villains Scenario', () => { |
| 87 | + it('should list multiple villains', () => { |
| 88 | + expect(element.all(by.css('villains-list li')).count()).toBeGreaterThan(1); |
| 89 | + }); |
31 | 90 | });
|
32 | 91 |
|
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 |
| - } |
| 92 | + describe('Cars Scenario', () => { |
54 | 93 |
|
| 94 | + it('A-component should use expected services', () => { |
| 95 | + expect(element(by.css('a-car')).getText()).toContain('C1-E1-T1'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('B-component should use expected services', () => { |
| 99 | + expect(element(by.css('b-car')).getText()).toContain('C2-E2-T1'); |
| 100 | + }); |
55 | 101 |
|
| 102 | + it('C-component should use expected services', () => { |
| 103 | + expect(element(by.css('c-car')).getText()).toContain('C3-E2-T1'); |
| 104 | + }); |
| 105 | + }); |
56 | 106 | });
|
0 commit comments