2015-12-20 16:17:16 -05:00
|
|
|
describe('Tutorial', function () {
|
|
|
|
|
|
|
|
beforeAll(function () {
|
|
|
|
browser.get('');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-03 14:32:57 -05:00
|
|
|
function getPageStruct() {
|
|
|
|
hrefEles = element.all(by.css('my-app a'));
|
2015-12-20 16:17:16 -05:00
|
|
|
|
2016-01-03 14:32:57 -05: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')),
|
2015-12-20 16:17:16 -05:00
|
|
|
|
2016-01-03 14:32:57 -05:00
|
|
|
myHeroesHref: hrefEles.get(1),
|
|
|
|
myHeroesParent: element(by.css('my-app my-heroes')),
|
|
|
|
allHeroes: element.all(by.css('my-app my-heroes li')),
|
2015-12-20 16:17:16 -05:00
|
|
|
|
2016-01-03 14:32:57 -05:00
|
|
|
heroDetail: element(by.css('my-app my-hero-detail'))
|
|
|
|
}
|
2015-12-20 16:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should be able to see the start screen', function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
var page = getPageStruct();
|
|
|
|
expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices');
|
|
|
|
expect(page.myDashboardHref.getText()).toEqual("Dashboard");
|
|
|
|
expect(page.myHeroesHref.getText()).toEqual("Heroes");
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to see dashboard choices', function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
var page = getPageStruct();
|
|
|
|
expect(page.topHeroes.count()).toBe(4, "should be 4 dashboard hero choices");
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to toggle the views', function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
var page = getPageStruct();
|
|
|
|
|
|
|
|
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');
|
|
|
|
expect(page.allHeroes.count()).toBeGreaterThan(4, "should be more than 4 heroes shown");
|
|
|
|
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 () {
|
|
|
|
var page = getPageStruct();
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available');
|
|
|
|
var heroEle = page.topHeroes.get(3);
|
|
|
|
var heroDescrEle = heroEle.element(by.css('h4'));
|
|
|
|
var heroDescr;
|
|
|
|
return heroDescrEle.getText().then(function(text) {
|
|
|
|
heroDescr = text;
|
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
return editDetails(page, heroDescr, '-foo');
|
2015-12-20 16:17:16 -05:00
|
|
|
}).then(function() {
|
2016-01-03 14:32:57 -05:00
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back');
|
|
|
|
expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
|
2016-01-03 14:32:57 -05:00
|
|
|
it('should be able to edit details from "Heroes" view', function () {
|
|
|
|
var page = getPageStruct();
|
|
|
|
expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be present');
|
|
|
|
var viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details'));
|
|
|
|
var heroEle, heroDescr;
|
|
|
|
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
|
|
|
|
heroDescr = text.substr(text.indexOf(' ')+1);
|
|
|
|
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');
|
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
|
2016-01-03 14:32:57 -05:00
|
|
|
function editDetails(page, origValue, textToAdd) {
|
|
|
|
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');
|
|
|
|
var inputEle = page.heroDetail.element(by.css('input'));
|
|
|
|
expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box');
|
|
|
|
var backButtonEle = page.heroDetail.element(by.css('button'));
|
|
|
|
expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button');
|
|
|
|
var detailTextEle = page.heroDetail.element(by.css('div h2'));
|
|
|
|
expect(detailTextEle.getText()).toContain(origValue);
|
|
|
|
return sendKeys(inputEle, textToAdd).then(function () {
|
|
|
|
expect(detailTextEle.getText()).toContain(origValue + textToAdd);
|
|
|
|
return backButtonEle.click();
|
|
|
|
});
|
|
|
|
}
|
2015-12-20 16:17:16 -05:00
|
|
|
|
|
|
|
});
|