|
| 1 | +describe('Tutorial', function () { |
| 2 | + |
| 3 | + beforeAll(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')), |
| 19 | + |
| 20 | + heroDetail: element(by.css('my-app my-hero-detail')) |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + it('should be able to see the start screen', function () { |
| 25 | + var page = getPageStruct(); |
| 26 | + expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices'); |
| 27 | + expect(page.myDashboardHref.getText()).toEqual("Dashboard"); |
| 28 | + expect(page.myHeroesHref.getText()).toEqual("Heroes"); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should be able to see dashboard choices', function () { |
| 32 | + var page = getPageStruct(); |
| 33 | + expect(page.topHeroes.count()).toBe(4, "should be 4 dashboard hero choices"); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should be able to toggle the views', function () { |
| 37 | + var page = getPageStruct(); |
| 38 | + |
| 39 | + expect(page.myDashboardParent.element(by.css('h3')).getText()).toEqual('Top Heroes'); |
| 40 | + page.myHeroesHref.click().then(function() { |
| 41 | + expect(page.myDashboardParent.isPresent()).toBe(false, 'should no longer see dashboard element'); |
| 42 | + expect(page.allHeroes.count()).toBeGreaterThan(4, "should be more than 4 heroes shown"); |
| 43 | + return page.myDashboardHref.click(); |
| 44 | + }).then(function() { |
| 45 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'should once again see the dashboard element'); |
| 46 | + }); |
| 47 | + |
| 48 | + }); |
| 49 | + |
| 50 | + it('should be able to edit details from "Dashboard" view', function () { |
| 51 | + var page = getPageStruct(); |
| 52 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available'); |
| 53 | + var heroEle = page.topHeroes.get(3); |
| 54 | + var heroDescrEle = heroEle.element(by.css('h4')); |
| 55 | + var heroDescr; |
| 56 | + return heroDescrEle.getText().then(function(text) { |
| 57 | + heroDescr = text; |
| 58 | + return heroEle.click(); |
| 59 | + }).then(function() { |
| 60 | + return editDetails(page, heroDescr, '-foo'); |
| 61 | + }).then(function() { |
| 62 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back'); |
| 63 | + expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should be able to edit details from "Heroes" view', function () { |
| 68 | + var page = getPageStruct(); |
| 69 | + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be present'); |
| 70 | + var viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details')); |
| 71 | + var heroEle, heroDescr; |
| 72 | + page.myHeroesHref.click().then(function() { |
| 73 | + expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present'); |
| 74 | + expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be present'); |
| 75 | + expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should not yet be present'); |
| 76 | + heroEle = page.allHeroes.get(2); |
| 77 | + return heroEle.getText(); |
| 78 | + }).then(function(text) { |
| 79 | + // remove leading 'id' from the element |
| 80 | + heroDescr = text.substr(text.indexOf(' ')+1); |
| 81 | + return heroEle.click(); |
| 82 | + }).then(function() { |
| 83 | + expect(viewDetailsButtonEle.isDisplayed()).toBe(true, 'viewDetails button should now be visible'); |
| 84 | + return viewDetailsButtonEle.click(); |
| 85 | + }).then(function() { |
| 86 | + return editDetails(page, heroDescr, '-bar'); |
| 87 | + }).then(function() { |
| 88 | + expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be back'); |
| 89 | + expect(heroEle.getText()).toContain(heroDescr + '-bar'); |
| 90 | + expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should again NOT be present'); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + function editDetails(page, origValue, textToAdd) { |
| 95 | + expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present'); |
| 96 | + expect(page.myHeroesParent.isPresent()).toBe(false, 'myHeroes element should NOT be present'); |
| 97 | + expect(page.heroDetail.isDisplayed()).toBe(true, 'should be able to see hero-details'); |
| 98 | + var inputEle = page.heroDetail.element(by.css('input')); |
| 99 | + expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box'); |
| 100 | + var backButtonEle = page.heroDetail.element(by.css('button')); |
| 101 | + expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button'); |
| 102 | + var detailTextEle = page.heroDetail.element(by.css('div h2')); |
| 103 | + expect(detailTextEle.getText()).toContain(origValue); |
| 104 | + return sendKeys(inputEle, textToAdd).then(function () { |
| 105 | + expect(detailTextEle.getText()).toContain(origValue + textToAdd); |
| 106 | + return backButtonEle.click(); |
| 107 | + }); |
| 108 | + } |
| 109 | + |
| 110 | +}); |
0 commit comments