2016-05-30 14:05:09 -04:00
|
|
|
/// <reference path='../_protractor/e2e.d.ts' />
|
2016-04-09 00:18:37 -04:00
|
|
|
describe('TOH Http Chapter', function () {
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
browser.get('');
|
|
|
|
});
|
|
|
|
|
|
|
|
function getPageStruct() {
|
2016-05-30 14:05:09 -04:00
|
|
|
let hrefEles = element.all(by.css('my-app a'));
|
2016-04-09 00:18:37 -04:00
|
|
|
|
|
|
|
return {
|
|
|
|
hrefs: hrefEles,
|
|
|
|
myDashboardHref: hrefEles.get(0),
|
|
|
|
myDashboardParent: element(by.css('my-app my-dashboard')),
|
|
|
|
topHeroes: element.all(by.css('my-app my-dashboard .module.hero')),
|
|
|
|
|
|
|
|
myHeroesHref: hrefEles.get(1),
|
|
|
|
myHeroesParent: element(by.css('my-app my-heroes')),
|
|
|
|
allHeroes: element.all(by.css('my-app my-heroes li .hero-element')),
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
firstDeleteButton: element.all(by.buttonText('Delete')).get(0),
|
|
|
|
|
|
|
|
addButton: element.all(by.buttonText('Add New Hero')).get(0),
|
|
|
|
|
|
|
|
heroDetail: element(by.css('my-app my-hero-detail'))
|
2016-05-30 14:05:09 -04:00
|
|
|
};
|
2016-04-09 00:18:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should be able to add a hero from the "Heroes" view', function(){
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
|
|
|
let heroCount: webdriver.promise.Promise<number>;
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
page.myHeroesHref.click().then(function() {
|
|
|
|
browser.waitForAngular();
|
|
|
|
heroCount = page.allHeroes.count();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(heroCount).toBe(10, 'should show 10');
|
2016-04-09 00:18:37 -04:00
|
|
|
}).then(function() {
|
|
|
|
return page.addButton.click();
|
|
|
|
}).then(function(){
|
|
|
|
return save(page,'','The New Hero');
|
|
|
|
}).then(function(){
|
|
|
|
browser.waitForAngular();
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
heroCount = page.allHeroes.count();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(heroCount).toBe(11, 'should show 11');
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
let newHero = element(by.xpath('//span[@class="hero-element" and contains(text(),"The New Hero")]'));
|
2016-04-09 00:18:37 -04:00
|
|
|
expect(newHero).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to delete hero from "Heroes" view', function(){
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
|
|
|
let heroCount: webdriver.promise.Promise<number>;
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
page.myHeroesHref.click().then(function() {
|
|
|
|
browser.waitForAngular();
|
|
|
|
heroCount = page.allHeroes.count();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(heroCount).toBe(10, 'should show 10');
|
2016-04-09 00:18:37 -04:00
|
|
|
}).then(function() {
|
|
|
|
return page.firstDeleteButton.click();
|
|
|
|
}).then(function(){
|
|
|
|
browser.waitForAngular();
|
|
|
|
heroCount = page.allHeroes.count();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(heroCount).toBe(9, 'should show 9');
|
2016-04-09 00:18:37 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to save details from "Dashboard" view', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-04-09 00:18:37 -04:00
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available');
|
2016-05-30 14:05:09 -04:00
|
|
|
let heroEle = page.topHeroes.get(2);
|
|
|
|
let heroDescrEle = heroEle.element(by.css('h4'));
|
|
|
|
let heroDescr: string;
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
return heroDescrEle.getText().then(function(text) {
|
|
|
|
heroDescr = text;
|
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
return save(page, heroDescr, '-foo');
|
|
|
|
})
|
|
|
|
.then(function(){
|
|
|
|
return page.myDashboardHref.click();
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back');
|
|
|
|
expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to save details from "Heroes" view', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
let viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details'));
|
|
|
|
let heroEle: protractor.ElementFinder, heroDescr: string;
|
2016-05-19 03:30:30 -04:00
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
page.myHeroesHref.click().then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present');
|
|
|
|
expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be present');
|
|
|
|
expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should not yet be present');
|
|
|
|
heroEle = page.allHeroes.get(0);
|
|
|
|
return heroEle.getText();
|
|
|
|
}).then(function(text) {
|
|
|
|
// remove leading 'id' from the element
|
2016-05-30 14:05:09 -04:00
|
|
|
heroDescr = text.substr(text.indexOf(' ') + 1);
|
2016-04-09 00:18:37 -04:00
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(viewDetailsButtonEle.isDisplayed()).toBe(true, 'viewDetails button should now be visible');
|
|
|
|
return viewDetailsButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
return save(page, heroDescr, '-bar');
|
|
|
|
})
|
|
|
|
.then(function(){
|
|
|
|
return page.myHeroesHref.click();
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
expect(heroEle.getText()).toContain(heroDescr + '-bar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
function save(page: any, origValue: string, textToAdd: string) {
|
|
|
|
let inputEle = page.heroDetail.element(by.css('input'));
|
2016-04-09 00:18:37 -04:00
|
|
|
expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box');
|
2016-05-30 14:05:09 -04:00
|
|
|
let saveButtonEle = page.heroDetail.element(by.buttonText('Save'));
|
|
|
|
let backButtonEle = page.heroDetail.element(by.buttonText('Back'));
|
2016-04-09 00:18:37 -04:00
|
|
|
expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button');
|
2016-05-30 14:05:09 -04:00
|
|
|
let detailTextEle = page.heroDetail.element(by.css('div h2'));
|
2016-04-09 00:18:37 -04:00
|
|
|
expect(detailTextEle.getText()).toContain(origValue);
|
|
|
|
return sendKeys(inputEle, textToAdd).then(function () {
|
|
|
|
expect(detailTextEle.getText()).toContain(origValue + textToAdd);
|
|
|
|
return saveButtonEle.click();
|
|
|
|
});
|
|
|
|
}
|
2016-05-19 03:30:30 -04:00
|
|
|
|
|
|
|
it('should be able to see the start screen', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices');
|
2016-05-30 14:05:09 -04:00
|
|
|
expect(page.myDashboardHref.getText()).toEqual('Dashboard');
|
|
|
|
expect(page.myHeroesHref.getText()).toEqual('Heroes');
|
2016-05-19 03:30:30 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to see dashboard choices', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
|
|
|
expect(page.topHeroes.count()).toBe(4, 'should be 4 dashboard hero choices');
|
2016-05-19 03:30:30 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to toggle the views', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-05-19 03:30:30 -04:00
|
|
|
|
|
|
|
expect(page.myDashboardParent.element(by.css('h3')).getText()).toEqual('Top Heroes');
|
|
|
|
page.myHeroesHref.click().then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(false, 'should no longer see dashboard element');
|
2016-05-30 14:05:09 -04:00
|
|
|
expect(page.allHeroes.count()).toBeGreaterThan(4, 'should be more than 4 heroes shown');
|
2016-05-19 03:30:30 -04:00
|
|
|
return page.myDashboardHref.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'should once again see the dashboard element');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to edit details from "Dashboard" view', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available');
|
2016-05-30 14:05:09 -04:00
|
|
|
let heroEle = page.topHeroes.get(3);
|
|
|
|
let heroDescrEle = heroEle.element(by.css('h4'));
|
|
|
|
let heroDescr: string;
|
2016-05-19 03:30:30 -04:00
|
|
|
return heroDescrEle.getText().then(function(text) {
|
|
|
|
heroDescr = text;
|
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
return editDetails(page, heroDescr, '-foo');
|
|
|
|
}).then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back');
|
|
|
|
expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to edit details from "Heroes" view', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be present');
|
2016-05-30 14:05:09 -04:00
|
|
|
let viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details'));
|
|
|
|
let heroEle: protractor.ElementFinder, heroDescr: string;
|
2016-05-19 03:30:30 -04:00
|
|
|
page.myHeroesHref.click().then(function() {
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present');
|
|
|
|
expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be present');
|
|
|
|
expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should not yet be present');
|
|
|
|
heroEle = page.allHeroes.get(2);
|
|
|
|
return heroEle.getText();
|
|
|
|
}).then(function(text) {
|
|
|
|
// remove leading 'id' from the element
|
2016-05-30 14:05:09 -04:00
|
|
|
heroDescr = text.substr(text.indexOf(' ') + 1);
|
2016-05-19 03:30:30 -04:00
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(viewDetailsButtonEle.isDisplayed()).toBe(true, 'viewDetails button should now be visible');
|
|
|
|
return viewDetailsButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
return editDetails(page, heroDescr, '-bar');
|
|
|
|
}).then(function() {
|
|
|
|
expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be back');
|
|
|
|
expect(heroEle.getText()).toContain(heroDescr + '-bar');
|
|
|
|
expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should again NOT be present');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
function editDetails(page: any, origValue: string, textToAdd: string) {
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present');
|
|
|
|
expect(page.myHeroesParent.isPresent()).toBe(false, 'myHeroes element should NOT be present');
|
|
|
|
expect(page.heroDetail.isDisplayed()).toBe(true, 'should be able to see hero-details');
|
2016-05-30 14:05:09 -04:00
|
|
|
let inputEle = page.heroDetail.element(by.css('input'));
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box');
|
2016-05-30 14:05:09 -04:00
|
|
|
let buttons = page.heroDetail.all(by.css('button'));
|
|
|
|
let backButtonEle = buttons.get(0);
|
|
|
|
let saveButtonEle = buttons.get(1);
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button');
|
|
|
|
expect(saveButtonEle.isDisplayed()).toBe(true, 'should be able to see the save button');
|
2016-05-30 14:05:09 -04:00
|
|
|
let detailTextEle = page.heroDetail.element(by.css('div h2'));
|
2016-05-19 03:30:30 -04:00
|
|
|
expect(detailTextEle.getText()).toContain(origValue);
|
|
|
|
return sendKeys(inputEle, textToAdd).then(function () {
|
|
|
|
expect(detailTextEle.getText()).toContain(origValue + textToAdd);
|
|
|
|
return saveButtonEle.click();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-09 00:18:37 -04:00
|
|
|
});
|