|
| 1 | +describe('TOH Http Chapter', function () { |
| 2 | + |
| 3 | + beforeEach(function () { |
| 4 | + browser.get(''); |
| 5 | + }); |
| 6 | + |
| 7 | + function getPageStruct() { |
| 8 | + hrefEles = element.all(by.css('my-app a')); |
| 9 | + |
| 10 | + return { |
| 11 | + hrefs: hrefEles, |
| 12 | + myDashboardHref: hrefEles.get(0), |
| 13 | + myDashboardParent: element(by.css('my-app my-dashboard')), |
| 14 | + topHeroes: element.all(by.css('my-app my-dashboard .module.hero')), |
| 15 | + |
| 16 | + myHeroesHref: hrefEles.get(1), |
| 17 | + myHeroesParent: element(by.css('my-app my-heroes')), |
| 18 | + allHeroes: element.all(by.css('my-app my-heroes li .hero-element')), |
| 19 | + |
| 20 | + firstDeleteButton: element.all(by.buttonText('Delete')).get(0), |
| 21 | + |
| 22 | + addButton: element.all(by.buttonText('Add New Hero')).get(0), |
| 23 | + |
| 24 | + heroDetail: element(by.css('my-app my-hero-detail')) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + it('should be able to add a hero from the "Heroes" view', function(){ |
| 29 | + var page = getPageStruct(); |
| 30 | + var heroCount; |
| 31 | + |
| 32 | + page.myHeroesHref.click().then(function() { |
| 33 | + browser.waitForAngular(); |
| 34 | + heroCount = page.allHeroes.count(); |
| 35 | + expect(heroCount).toBe(4, 'should show 4'); |
| 36 | + }).then(function() { |
| 37 | + return page.addButton.click(); |
| 38 | + }).then(function(){ |
| 39 | + return save(page,'','The New Hero'); |
| 40 | + }).then(function(){ |
| 41 | + browser.waitForAngular(); |
| 42 | + |
| 43 | + heroCount = page.allHeroes.count(); |
| 44 | + expect(heroCount).toBe(5, 'should show 5'); |
| 45 | + |
| 46 | + var newHero = element(by.xpath('//span[@class="hero-element" and contains(text(),"The New Hero")]')); |
| 47 | + expect(newHero).toBeDefined(); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should be able to delete hero from "Heroes" view', function(){ |
| 52 | + var page = getPageStruct(); |
| 53 | + var heroCount; |
| 54 | + |
| 55 | + page.myHeroesHref.click().then(function() { |
| 56 | + browser.waitForAngular(); |
| 57 | + heroCount = page.allHeroes.count(); |
| 58 | + expect(heroCount).toBe(4, 'should show 4'); |
| 59 | + }).then(function() { |
| 60 | + return page.firstDeleteButton.click(); |
| 61 | + }).then(function(){ |
| 62 | + browser.waitForAngular(); |
| 63 | + heroCount = page.allHeroes.count(); |
| 64 | + expect(heroCount).toBe(3, 'should show 3'); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should be able to save details from "Dashboard" view', function () { |
| 69 | + var page = getPageStruct(); |
| 70 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available'); |
| 71 | + var heroEle = page.topHeroes.get(2); |
| 72 | + var heroDescrEle = heroEle.element(by.css('h4')); |
| 73 | + var heroDescr; |
| 74 | + |
| 75 | + return heroDescrEle.getText().then(function(text) { |
| 76 | + heroDescr = text; |
| 77 | + return heroEle.click(); |
| 78 | + }).then(function() { |
| 79 | + return save(page, heroDescr, '-foo'); |
| 80 | + }) |
| 81 | + .then(function(){ |
| 82 | + return page.myDashboardHref.click(); |
| 83 | + }) |
| 84 | + .then(function() { |
| 85 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back'); |
| 86 | + expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo'); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should be able to save details from "Heroes" view', function () { |
| 91 | + var page = getPageStruct(); |
| 92 | + |
| 93 | + var viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details')); |
| 94 | + var heroEle, heroDescr; |
| 95 | + |
| 96 | + page.myHeroesHref.click().then(function() { |
| 97 | + expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present'); |
| 98 | + expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be present'); |
| 99 | + expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should not yet be present'); |
| 100 | + heroEle = page.allHeroes.get(0); |
| 101 | + return heroEle.getText(); |
| 102 | + }).then(function(text) { |
| 103 | + // remove leading 'id' from the element |
| 104 | + heroDescr = text.substr(text.indexOf(' ')+1); |
| 105 | + return heroEle.click(); |
| 106 | + }).then(function() { |
| 107 | + expect(viewDetailsButtonEle.isDisplayed()).toBe(true, 'viewDetails button should now be visible'); |
| 108 | + return viewDetailsButtonEle.click(); |
| 109 | + }).then(function() { |
| 110 | + return save(page, heroDescr, '-bar'); |
| 111 | + }) |
| 112 | + .then(function(){ |
| 113 | + return page.myHeroesHref.click(); |
| 114 | + }) |
| 115 | + .then(function() { |
| 116 | + expect(heroEle.getText()).toContain(heroDescr + '-bar'); |
| 117 | + }); |
| 118 | + }); |
| 119 | + |
| 120 | + function save(page, origValue, textToAdd) { |
| 121 | + var inputEle = page.heroDetail.element(by.css('input')); |
| 122 | + expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box'); |
| 123 | + var saveButtonEle = page.heroDetail.element(by.buttonText('Save')); |
| 124 | + var backButtonEle = page.heroDetail.element(by.buttonText('Back')); |
| 125 | + expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button'); |
| 126 | + var detailTextEle = page.heroDetail.element(by.css('div h2')); |
| 127 | + expect(detailTextEle.getText()).toContain(origValue); |
| 128 | + return sendKeys(inputEle, textToAdd).then(function () { |
| 129 | + expect(detailTextEle.getText()).toContain(origValue + textToAdd); |
| 130 | + return saveButtonEle.click(); |
| 131 | + }); |
| 132 | + } |
| 133 | +}); |
0 commit comments