2016-10-06 18:25:52 -04:00
|
|
|
'use strict'; // necessary for es6 output in node
|
|
|
|
|
|
|
|
import { browser, element, by } from 'protractor';
|
|
|
|
|
2015-12-20 16:17:16 -05:00
|
|
|
describe('Lifecycle hooks', function () {
|
|
|
|
|
|
|
|
beforeAll(function () {
|
|
|
|
browser.get('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should open correctly', function () {
|
|
|
|
expect(element.all(by.css('h2')).get(0).getText()).toEqual('Peek-A-Boo');
|
|
|
|
});
|
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support peek-a-boo', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let pabComp = element(by.css('peek-a-boo-parent peek-a-boo'));
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(pabComp.isPresent()).toBe(false, 'should not be able to find the "peek-a-boo" component');
|
2016-05-30 14:05:09 -04:00
|
|
|
let pabButton = element.all(by.css('peek-a-boo-parent button')).get(0);
|
|
|
|
let updateHeroButton = element.all(by.css('peek-a-boo-parent button')).get(1);
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(pabButton.getText()).toContain('Create Peek');
|
|
|
|
pabButton.click().then(function () {
|
|
|
|
expect(pabButton.getText()).toContain('Destroy Peek');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(pabComp.isDisplayed()).toBe(true, 'should be able to see the "peek-a-boo" component');
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(pabComp.getText()).toContain('Windstorm');
|
|
|
|
expect(pabComp.getText()).not.toContain('Windstorm!');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(updateHeroButton.isPresent()).toBe(true, 'should be able to see the update hero button');
|
2015-12-20 16:17:16 -05:00
|
|
|
return updateHeroButton.click();
|
|
|
|
}).then(function () {
|
|
|
|
expect(pabComp.getText()).toContain('Windstorm!');
|
|
|
|
return pabButton.click();
|
|
|
|
}).then(function () {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(pabComp.isPresent()).toBe(false, 'should no longer be able to find the "peek-a-boo" component');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support OnChanges hook', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let onChangesViewEle = element.all(by.css('on-changes div')).get(0);
|
|
|
|
let inputEles = element.all(by.css('on-changes-parent input'));
|
|
|
|
let heroNameInputEle = inputEles.get(1);
|
|
|
|
let powerInputEle = inputEles.get(0);
|
|
|
|
let titleEle = onChangesViewEle.element(by.css('p'));
|
|
|
|
let changeLogEles = onChangesViewEle.all(by.css('div'));
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(titleEle.getText()).toContain('Windstorm can sing');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(changeLogEles.count()).toEqual(2, 'should start with 2 messages');
|
2016-10-06 18:25:52 -04:00
|
|
|
heroNameInputEle.sendKeys('-foo-');
|
|
|
|
expect(titleEle.getText()).toContain('Windstorm-foo- can sing');
|
|
|
|
expect(changeLogEles.count()).toEqual(2, 'should still have 2 messages');
|
|
|
|
powerInputEle.sendKeys('-bar-');
|
|
|
|
expect(titleEle.getText()).toContain('Windstorm-foo- can sing-bar-');
|
|
|
|
// 7 == 2 previously + length of '-bar-'
|
|
|
|
expect(changeLogEles.count()).toEqual(7, 'should have 7 messages now');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support DoCheck hook', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let doCheckViewEle = element.all(by.css('do-check div')).get(0);
|
|
|
|
let inputEles = element.all(by.css('do-check-parent input'));
|
|
|
|
let heroNameInputEle = inputEles.get(1);
|
|
|
|
let powerInputEle = inputEles.get(0);
|
|
|
|
let titleEle = doCheckViewEle.element(by.css('p'));
|
|
|
|
let changeLogEles = doCheckViewEle.all(by.css('div'));
|
2016-06-01 12:11:58 -04:00
|
|
|
let logCount: number;
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(titleEle.getText()).toContain('Windstorm can sing');
|
2016-10-06 18:25:52 -04:00
|
|
|
changeLogEles.count().then(function(count: number) {
|
2016-08-31 21:08:57 -04:00
|
|
|
// 3 messages to start
|
|
|
|
expect(count).toEqual(3, 'should start with 3 messages');
|
2016-01-23 13:21:09 -05:00
|
|
|
logCount = count;
|
2016-10-06 18:25:52 -04:00
|
|
|
return heroNameInputEle.sendKeys('-foo-');
|
2016-01-23 13:21:09 -05:00
|
|
|
}).then(function () {
|
|
|
|
expect(titleEle.getText()).toContain('Windstorm-foo- can sing');
|
2016-06-07 19:06:25 -04:00
|
|
|
return changeLogEles.count();
|
2016-10-06 18:25:52 -04:00
|
|
|
}).then(function(count: number) {
|
2016-06-13 21:12:25 -04:00
|
|
|
// one more for each keystroke
|
|
|
|
expect(count).toEqual(logCount + 5, 'should add 5 more messages');
|
2016-01-23 13:21:09 -05:00
|
|
|
logCount = count;
|
2016-10-06 18:25:52 -04:00
|
|
|
return powerInputEle.sendKeys('-bar-');
|
2016-01-23 13:21:09 -05:00
|
|
|
}).then(function () {
|
|
|
|
expect(titleEle.getText()).toContain('Windstorm-foo- can sing-bar-');
|
2016-08-31 21:08:57 -04:00
|
|
|
expect(changeLogEles.count()).toEqual(logCount + 6, 'should add 6 more messages');
|
2016-01-23 13:21:09 -05:00
|
|
|
});
|
|
|
|
});
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support AfterView hooks', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let parentEle = element(by.tagName('after-view-parent'));
|
|
|
|
let buttonEle = parentEle.element(by.tagName('button')); // Reset
|
|
|
|
let commentEle = parentEle.element(by.className('comment'));
|
|
|
|
let logEles = parentEle.all(by.css('h4 ~ div'));
|
2016-08-09 12:38:25 -04:00
|
|
|
let childViewInputEle = parentEle.element(by.css('my-child-view input'));
|
2016-06-01 12:11:58 -04:00
|
|
|
let logCount: number;
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(childViewInputEle.getAttribute('value')).toContain('Magneta');
|
|
|
|
expect(commentEle.isPresent()).toBe(false, 'comment should not be in DOM');
|
|
|
|
|
2016-10-06 18:25:52 -04:00
|
|
|
logEles.count().then(function(count: number) {
|
2015-12-20 16:17:16 -05:00
|
|
|
logCount = count;
|
2016-10-06 18:25:52 -04:00
|
|
|
return childViewInputEle.sendKeys('-test-');
|
2015-12-20 16:17:16 -05:00
|
|
|
}).then(function() {
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(childViewInputEle.getAttribute('value')).toContain('-test-');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(commentEle.getText()).toContain('long name');
|
2015-12-20 16:17:16 -05:00
|
|
|
return logEles.count();
|
2016-10-06 18:25:52 -04:00
|
|
|
}).then(function(count: number) {
|
|
|
|
expect(logCount + 7).toEqual(count, '7 additional log messages should have been added');
|
2015-12-20 16:17:16 -05:00
|
|
|
logCount = count;
|
|
|
|
return buttonEle.click();
|
|
|
|
}).then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(logEles.count()).toBeLessThan(logCount, 'log should shrink after reset');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
|
|
|
|
it('should support AfterContent hooks', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let parentEle = element(by.tagName('after-content-parent'));
|
|
|
|
let buttonEle = parentEle.element(by.tagName('button')); // Reset
|
|
|
|
let commentEle = parentEle.element(by.className('comment'));
|
|
|
|
let logEles = parentEle.all(by.css('h4 ~ div'));
|
|
|
|
let childViewInputEle = parentEle.element(by.css('my-child input'));
|
2016-06-01 12:11:58 -04:00
|
|
|
let logCount: number;
|
2016-04-27 14:28:22 -04:00
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(childViewInputEle.getAttribute('value')).toContain('Magneta');
|
|
|
|
expect(commentEle.isPresent()).toBe(false, 'comment should not be in DOM');
|
|
|
|
|
2016-10-06 18:25:52 -04:00
|
|
|
logEles.count().then(function(count: number) {
|
2015-12-20 16:17:16 -05:00
|
|
|
logCount = count;
|
2016-10-06 18:25:52 -04:00
|
|
|
return childViewInputEle.sendKeys('-test-');
|
2015-12-20 16:17:16 -05:00
|
|
|
}).then(function() {
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(childViewInputEle.getAttribute('value')).toContain('-test-');
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
|
2016-01-23 13:21:09 -05:00
|
|
|
expect(commentEle.getText()).toContain('long name');
|
2015-12-20 16:17:16 -05:00
|
|
|
return logEles.count();
|
2016-10-06 18:25:52 -04:00
|
|
|
}).then(function(count: number) {
|
2016-06-13 21:12:25 -04:00
|
|
|
expect(logCount + 5).toEqual(count, '5 additional log messages should have been added');
|
2015-12-20 16:17:16 -05:00
|
|
|
logCount = count;
|
|
|
|
return buttonEle.click();
|
|
|
|
}).then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(logEles.count()).toBeLessThan(logCount, 'log should shrink after reset');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support spy\'s OnInit & OnDestroy hooks', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let inputEle = element(by.css('spy-parent input'));
|
2016-06-07 19:06:25 -04:00
|
|
|
let addHeroButtonEle = element(by.cssContainingText('spy-parent button', 'Add Hero'));
|
|
|
|
let resetHeroesButtonEle = element(by.cssContainingText('spy-parent button', 'Reset Heroes'));
|
2016-05-30 14:05:09 -04:00
|
|
|
let heroEles = element.all(by.css('spy-parent div[mySpy'));
|
|
|
|
let logEles = element.all(by.css('spy-parent h4 ~ div'));
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(heroEles.count()).toBe(2, 'should have two heroes displayed');
|
|
|
|
expect(logEles.count()).toBe(2, 'should have two log entries');
|
2016-10-06 18:25:52 -04:00
|
|
|
inputEle.sendKeys('-test-').then(function() {
|
2015-12-20 16:17:16 -05:00
|
|
|
return addHeroButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(heroEles.count()).toBe(3, 'should have added one hero');
|
|
|
|
expect(heroEles.get(2).getText()).toContain('-test-');
|
|
|
|
expect(logEles.count()).toBe(3, 'should now have 3 log entries');
|
|
|
|
return resetHeroesButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(heroEles.count()).toBe(0, 'should no longer have any heroes');
|
|
|
|
expect(logEles.count()).toBe(7, 'should now have 7 log entries - 3 orig + 1 reset + 3 removeall');
|
2016-06-07 19:06:25 -04:00
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
|
2016-01-23 13:21:09 -05:00
|
|
|
it('should support "spy counter"', function () {
|
2016-06-07 19:06:25 -04:00
|
|
|
let updateCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Update'));
|
|
|
|
let resetCounterButtonEle = element(by.cssContainingText('counter-parent button', 'Reset'));
|
2016-05-30 14:05:09 -04:00
|
|
|
let textEle = element(by.css('counter-parent my-counter > div'));
|
|
|
|
let logEles = element.all(by.css('counter-parent h4 ~ div'));
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(textEle.getText()).toContain('Counter = 0');
|
|
|
|
expect(logEles.count()).toBe(2, 'should start with two log entries');
|
|
|
|
updateCounterButtonEle.click().then(function() {
|
|
|
|
expect(textEle.getText()).toContain('Counter = 1');
|
|
|
|
expect(logEles.count()).toBe(3, 'should now have 3 log entries');
|
|
|
|
return resetCounterButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(textEle.getText()).toContain('Counter = 0');
|
|
|
|
expect(logEles.count()).toBe(7, 'should now have 7 log entries - 3 prev + 1 reset + 2 destroy + 1 init');
|
2016-06-07 19:06:25 -04:00
|
|
|
});
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
});
|