2016-06-15 21:01:03 -04:00
|
|
|
/// <reference path='../_protractor/e2e.d.ts' />
|
|
|
|
'use strict';
|
2016-01-03 14:32:57 -05:00
|
|
|
describe('Router', function () {
|
|
|
|
|
|
|
|
beforeAll(function () {
|
|
|
|
browser.get('');
|
|
|
|
});
|
|
|
|
|
|
|
|
function getPageStruct() {
|
2016-06-01 12:11:58 -04:00
|
|
|
let hrefEles = element.all(by.css('my-app a'));
|
2016-01-03 14:32:57 -05:00
|
|
|
|
|
|
|
return {
|
|
|
|
hrefs: hrefEles,
|
|
|
|
routerParent: element(by.css('my-app > undefined')),
|
|
|
|
routerTitle: element(by.css('my-app > undefined > h2')),
|
|
|
|
|
|
|
|
crisisHref: hrefEles.get(0),
|
|
|
|
crisisList: element.all(by.css('my-app > undefined > undefined li')),
|
|
|
|
crisisDetail: element(by.css('my-app > undefined > undefined > div')),
|
|
|
|
crisisDetailTitle: element(by.css('my-app > undefined > undefined > div > h3')),
|
|
|
|
|
|
|
|
heroesHref: hrefEles.get(1),
|
|
|
|
heroesList: element.all(by.css('my-app > undefined li')),
|
|
|
|
heroDetail: element(by.css('my-app > undefined > div')),
|
|
|
|
heroDetailTitle: element(by.css('my-app > undefined > div > h3')),
|
|
|
|
|
2016-06-07 19:06:25 -04:00
|
|
|
};
|
2016-01-03 14:32:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should be able to see the start screen', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-01-03 14:32:57 -05:00
|
|
|
expect(page.hrefs.count()).toEqual(2, 'should be two dashboard choices');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.crisisHref.getText()).toEqual('Crisis Center');
|
|
|
|
expect(page.heroesHref.getText()).toEqual('Heroes');
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to see crises center items', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.crisisList.count()).toBe(4, 'should be 4 crisis center entries at start');
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to see hero items', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-01-03 14:32:57 -05:00
|
|
|
page.heroesHref.click().then(function() {
|
|
|
|
expect(page.routerTitle.getText()).toContain('HEROES');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.heroesList.count()).toBe(6, 'should be 6 heroes');
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to toggle the views', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-01-03 14:32:57 -05:00
|
|
|
page.crisisHref.click().then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.crisisList.count()).toBe(4, 'should be 4 crisis center entries');
|
2016-01-03 14:32:57 -05:00
|
|
|
return page.heroesHref.click();
|
|
|
|
}).then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.heroesList.count()).toBe(6, 'should be 6 heroes');
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to edit and save details from the crisis center view', function () {
|
|
|
|
crisisCenterEdit(2, true);
|
|
|
|
});
|
|
|
|
|
2016-05-30 14:05:09 -04:00
|
|
|
it('should be able to edit and cancel details from the crisis center view', function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
crisisCenterEdit(3, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to edit and save details from the heroes view', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-06-01 12:11:58 -04:00
|
|
|
let heroEle: protractor.ElementFinder;
|
|
|
|
let heroText: string;
|
2016-01-03 14:32:57 -05:00
|
|
|
page.heroesHref.click().then(function() {
|
|
|
|
heroEle = page.heroesList.get(4);
|
|
|
|
return heroEle.getText();
|
|
|
|
}).then(function(text) {
|
|
|
|
expect(text.length).toBeGreaterThan(0, 'should have some text');
|
|
|
|
// remove leading id from text
|
|
|
|
heroText = text.substr(text.indexOf(' ')).trim();
|
|
|
|
return heroEle.click();
|
|
|
|
}).then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.heroesList.count()).toBe(0, 'should no longer see crisis center entries');
|
2016-01-03 14:32:57 -05:00
|
|
|
expect(page.heroDetail.isPresent()).toBe(true, 'should be able to see crisis detail');
|
|
|
|
expect(page.heroDetailTitle.getText()).toContain(heroText);
|
2016-05-30 14:05:09 -04:00
|
|
|
let inputEle = page.heroDetail.element(by.css('input'));
|
2016-01-03 14:32:57 -05:00
|
|
|
return sendKeys(inputEle, '-foo');
|
|
|
|
}).then(function() {
|
|
|
|
expect(page.heroDetailTitle.getText()).toContain(heroText + '-foo');
|
2016-05-30 14:05:09 -04:00
|
|
|
let buttonEle = page.heroDetail.element(by.css('button'));
|
2016-01-03 14:32:57 -05:00
|
|
|
return buttonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(heroEle.getText()).toContain(heroText + '-foo');
|
2016-06-07 19:06:25 -04:00
|
|
|
});
|
2016-01-03 14:32:57 -05:00
|
|
|
});
|
|
|
|
|
2016-06-01 12:11:58 -04:00
|
|
|
function crisisCenterEdit(index: number, shouldSave: boolean) {
|
2016-05-30 14:05:09 -04:00
|
|
|
let page = getPageStruct();
|
2016-06-01 12:11:58 -04:00
|
|
|
let crisisEle: protractor.ElementFinder;
|
|
|
|
let crisisText: string;
|
2016-05-03 14:19:50 -04:00
|
|
|
page.crisisHref.click()
|
|
|
|
.then(function () {
|
2016-01-03 14:32:57 -05:00
|
|
|
crisisEle = page.crisisList.get(index);
|
|
|
|
return crisisEle.getText();
|
|
|
|
}).then(function (text) {
|
|
|
|
expect(text.length).toBeGreaterThan(0, 'should have some text');
|
|
|
|
// remove leading id from text
|
|
|
|
crisisText = text.substr(text.indexOf(' ')).trim();
|
|
|
|
return crisisEle.click();
|
|
|
|
}).then(function () {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(page.crisisList.count()).toBe(0, 'should no longer see crisis center entries');
|
2016-01-03 14:32:57 -05:00
|
|
|
expect(page.crisisDetail.isPresent()).toBe(true, 'should be able to see crisis detail');
|
|
|
|
expect(page.crisisDetailTitle.getText()).toContain(crisisText);
|
2016-05-30 14:05:09 -04:00
|
|
|
let inputEle = page.crisisDetail.element(by.css('input'));
|
2016-01-03 14:32:57 -05:00
|
|
|
return sendKeys(inputEle, '-foo');
|
|
|
|
}).then(function () {
|
|
|
|
expect(page.crisisDetailTitle.getText()).toContain(crisisText + '-foo');
|
2016-05-30 14:05:09 -04:00
|
|
|
let buttonEle = page.crisisDetail.element(by.cssContainingText('button', shouldSave ? 'Save' : 'Cancel'));
|
2016-01-03 14:32:57 -05:00
|
|
|
return buttonEle.click();
|
|
|
|
}).then(function () {
|
|
|
|
if (shouldSave) {
|
|
|
|
expect(crisisEle.getText()).toContain(crisisText + '-foo');
|
|
|
|
} else {
|
|
|
|
expect(crisisEle.getText()).not.toContain(crisisText + '-foo');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|