|
| 1 | +describe('Router', 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 | + routerParent: element(by.css('my-app > undefined')), |
| 13 | + routerTitle: element(by.css('my-app > undefined > h2')), |
| 14 | + |
| 15 | + crisisHref: hrefEles.get(0), |
| 16 | + crisisList: element.all(by.css('my-app > undefined > undefined li')), |
| 17 | + crisisDetail: element(by.css('my-app > undefined > undefined > div')), |
| 18 | + crisisDetailTitle: element(by.css('my-app > undefined > undefined > div > h3')), |
| 19 | + |
| 20 | + heroesHref: hrefEles.get(1), |
| 21 | + heroesList: element.all(by.css('my-app > undefined li')), |
| 22 | + heroDetail: element(by.css('my-app > undefined > div')), |
| 23 | + heroDetailTitle: element(by.css('my-app > undefined > div > h3')), |
| 24 | + |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + it('should be able to see the start screen', function () { |
| 29 | + var page = getPageStruct(); |
| 30 | + expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices'); |
| 31 | + expect(page.crisisHref.getText()).toEqual("Crisis Center"); |
| 32 | + expect(page.heroesHref.getText()).toEqual("Heroes"); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should be able to see crises center items', function () { |
| 36 | + var page = getPageStruct(); |
| 37 | + expect(page.crisisList.count()).toBe(4, "should be 4 crisis center entries at start"); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should be able to see hero items', function () { |
| 41 | + var page = getPageStruct(); |
| 42 | + page.heroesHref.click().then(function() { |
| 43 | + expect(page.routerTitle.getText()).toContain('HEROES'); |
| 44 | + expect(page.heroesList.count()).toBe(6, "should be 6 heroes"); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should be able to toggle the views', function () { |
| 49 | + var page = getPageStruct(); |
| 50 | + page.crisisHref.click().then(function() { |
| 51 | + expect(page.crisisList.count()).toBe(4, "should be 4 crisis center entries"); |
| 52 | + return page.heroesHref.click(); |
| 53 | + }).then(function() { |
| 54 | + expect(page.heroesList.count()).toBe(6, "should be 6 heroes"); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should be able to edit and save details from the crisis center view', function () { |
| 59 | + crisisCenterEdit(2, true); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should be able to edit and cancel details from the crisis center view', function () { |
| 63 | + crisisCenterEdit(3, false); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should be able to edit and save details from the heroes view', function () { |
| 67 | + var page = getPageStruct(); |
| 68 | + var heroEle, heroText; |
| 69 | + page.heroesHref.click().then(function() { |
| 70 | + heroEle = page.heroesList.get(4); |
| 71 | + return heroEle.getText(); |
| 72 | + }).then(function(text) { |
| 73 | + expect(text.length).toBeGreaterThan(0, 'should have some text'); |
| 74 | + // remove leading id from text |
| 75 | + heroText = text.substr(text.indexOf(' ')).trim(); |
| 76 | + return heroEle.click(); |
| 77 | + }).then(function() { |
| 78 | + expect(page.heroesList.count()).toBe(0, "should no longer see crisis center entries"); |
| 79 | + expect(page.heroDetail.isPresent()).toBe(true, 'should be able to see crisis detail'); |
| 80 | + expect(page.heroDetailTitle.getText()).toContain(heroText); |
| 81 | + var inputEle = page.heroDetail.element(by.css('input')); |
| 82 | + return sendKeys(inputEle, '-foo'); |
| 83 | + }).then(function() { |
| 84 | + expect(page.heroDetailTitle.getText()).toContain(heroText + '-foo'); |
| 85 | + var buttonEle = page.heroDetail.element(by.css('button')); |
| 86 | + return buttonEle.click(); |
| 87 | + }).then(function() { |
| 88 | + expect(heroEle.getText()).toContain(heroText + '-foo'); |
| 89 | + }) |
| 90 | + }); |
| 91 | + |
| 92 | + function crisisCenterEdit(index, shouldSave) { |
| 93 | + var page = getPageStruct(); |
| 94 | + var crisisEle, crisisText; |
| 95 | + page.crisisHref.click().then(function () { |
| 96 | + crisisEle = page.crisisList.get(index); |
| 97 | + return crisisEle.getText(); |
| 98 | + }).then(function (text) { |
| 99 | + expect(text.length).toBeGreaterThan(0, 'should have some text'); |
| 100 | + // remove leading id from text |
| 101 | + crisisText = text.substr(text.indexOf(' ')).trim(); |
| 102 | + return crisisEle.click(); |
| 103 | + }).then(function () { |
| 104 | + expect(page.crisisList.count()).toBe(0, "should no longer see crisis center entries"); |
| 105 | + expect(page.crisisDetail.isPresent()).toBe(true, 'should be able to see crisis detail'); |
| 106 | + expect(page.crisisDetailTitle.getText()).toContain(crisisText); |
| 107 | + var inputEle = page.crisisDetail.element(by.css('input')); |
| 108 | + return sendKeys(inputEle, '-foo'); |
| 109 | + }).then(function () { |
| 110 | + expect(page.crisisDetailTitle.getText()).toContain(crisisText + '-foo'); |
| 111 | + var buttonEle = page.crisisDetail.element(by.cssContainingText('button', shouldSave ? 'Save' : 'Cancel')); |
| 112 | + return buttonEle.click(); |
| 113 | + }).then(function () { |
| 114 | + if (shouldSave) { |
| 115 | + expect(crisisEle.getText()).toContain(crisisText + '-foo'); |
| 116 | + } else { |
| 117 | + expect(crisisEle.getText()).not.toContain(crisisText + '-foo'); |
| 118 | + } |
| 119 | + }); |
| 120 | + } |
| 121 | + |
| 122 | +}); |
0 commit comments