|
| 1 | +/// <reference path='../_protractor/e2e.d.ts' /> |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +import * as toh from '../toh-1/toh-spec-shared'; |
| 5 | + |
| 6 | +export function initalPageAndUpdateHeroTests() { |
| 7 | + describe('Initial page', initialPageTests); |
| 8 | + describe('Select hero', selectHeroTests); |
| 9 | + describe('Update hero', updateHeroTests); |
| 10 | +} |
| 11 | + |
| 12 | +function initialPageTests() { |
| 13 | + toh.itHasProperTitleAndHeadings(); |
| 14 | + |
| 15 | + const expectedH2 = 'My Heroes'; |
| 16 | + |
| 17 | + it(`has h2 '${expectedH2}'`, () => { |
| 18 | + toh.expectHeading(2, expectedH2); |
| 19 | + }); |
| 20 | + |
| 21 | + it('has the right number of heroes', () => { |
| 22 | + let page = getPageElts(); |
| 23 | + expect(page.heroes.count()).toEqual(10); |
| 24 | + }); |
| 25 | + |
| 26 | + it('has no selected hero and no hero details', function () { |
| 27 | + let page = getPageElts(); |
| 28 | + expect(page.selected.isPresent()).toBeFalsy('selected hero'); |
| 29 | + expect(page.heroDetail.isPresent()).toBeFalsy('no hero detail'); |
| 30 | + }); |
| 31 | +} |
| 32 | + |
| 33 | +const targetHero = { id: 16, name: 'RubberMan' }; |
| 34 | + |
| 35 | +function selectHeroTests() { |
| 36 | + it(`selects ${targetHero.name} from hero list`, function () { |
| 37 | + let page = getPageElts(); |
| 38 | + let hero = element(by.cssContainingText('li span.badge', targetHero.id.toString())); |
| 39 | + hero.click(); |
| 40 | + // Nothing specific to expect other than lack of exceptions. |
| 41 | + }); |
| 42 | + |
| 43 | + it(`has selected ${targetHero.name}`, function () { |
| 44 | + let page = getPageElts(); |
| 45 | + let expectedText = `${targetHero.id} ${targetHero.name}`; |
| 46 | + expect(page.selected.getText()).toBe(expectedText); |
| 47 | + }); |
| 48 | + |
| 49 | + it('shows selected hero details', async () => { |
| 50 | + let page = getPageElts(); |
| 51 | + let hero = await toh.Hero.fromDetail(page.heroDetail); |
| 52 | + expect(hero.id).toEqual(targetHero.id); |
| 53 | + expect(hero.name).toEqual(targetHero.name); |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +function updateHeroTests() { |
| 58 | + it(`can update hero name`, () => { |
| 59 | + toh.addToHeroName(toh.nameSuffix); |
| 60 | + // Nothing specific to expect other than lack of exceptions. |
| 61 | + }); |
| 62 | + |
| 63 | + it(`shows updated hero name in details`, async () => { |
| 64 | + let page = getPageElts(); |
| 65 | + let hero = await toh.Hero.fromDetail(page.heroDetail); |
| 66 | + let newName = targetHero.name + toh.nameSuffix; |
| 67 | + expect(hero.id).toEqual(targetHero.id); |
| 68 | + expect(hero.name).toEqual(newName); |
| 69 | + }); |
| 70 | + |
| 71 | + it(`shows updated hero name in list`, async () => { |
| 72 | + let page = getPageElts(); |
| 73 | + let hero = toh.Hero.fromString(await page.selected.getText()); |
| 74 | + let newName = targetHero.name + toh.nameSuffix; |
| 75 | + expect(hero.id).toEqual(targetHero.id); |
| 76 | + expect(hero.name).toEqual(newName); |
| 77 | + }); |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +function getPageElts() { |
| 82 | + return { |
| 83 | + heroes: element.all(by.css('my-app li')), |
| 84 | + selected: element(by.css('my-app li.selected')), |
| 85 | + heroDetail: element(by.css('my-app > div, my-app > my-hero-detail > div')) |
| 86 | + }; |
| 87 | +} |
0 commit comments