2016-06-15 21:01:03 -04:00
|
|
|
/// <reference path='../_protractor/e2e.d.ts' />
|
|
|
|
'use strict';
|
2015-12-20 16:17:16 -05:00
|
|
|
describe('Structural Directives', function () {
|
|
|
|
|
|
|
|
// tests interact - so we need beforeEach instead of beforeAll
|
|
|
|
beforeEach(function () {
|
|
|
|
browser.get('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to use ngFor, ngIf and ngWhen together', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let allDivEles = element.all(by.css('structural-directives > div'));
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(allDivEles.get(0).getText()).toEqual('Mr. Nice');
|
|
|
|
expect(allDivEles.get(1).getText()).toEqual('Mr. Nice');
|
|
|
|
expect(allDivEles.get(4).getText()).toEqual('Ready');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to toggle ngIf with a button', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let setConditionButtonEle = element.all(by.css('button')).get(0);
|
|
|
|
let conditionTrueEles = element.all(by.cssContainingText('p', 'condition is true'));
|
|
|
|
let conditionFalseEles = element.all(by.cssContainingText('p', 'condition is false'));
|
2015-12-20 16:17:16 -05:00
|
|
|
expect(conditionTrueEles.count()).toBe(2, 'should be two condition true elements');
|
|
|
|
expect(conditionFalseEles.count()).toBe(0, 'should be no condition false elements');
|
|
|
|
setConditionButtonEle.click().then(function() {
|
|
|
|
expect(conditionTrueEles.count()).toBe(0, 'should be no condition true elements');
|
|
|
|
expect(conditionFalseEles.count()).toBe(2, 'should be two condition false elements');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to compare use of ngIf with changing css visibility', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let setConditionButtonEle = element.all(by.css('button')).get(0);
|
|
|
|
let ngIfButtonEle = element(by.cssContainingText('button', 'if | !if'));
|
|
|
|
let ngIfParentEle = ngIfButtonEle.element(by.xpath('..'));
|
|
|
|
let ngIfSiblingEle = ngIfParentEle.element(by.css('heavy-loader'));
|
|
|
|
let cssButtonEle = element(by.cssContainingText('button', 'show | hide'));
|
|
|
|
let cssSiblingEle = cssButtonEle.element(by.xpath('..')).element(by.css('heavy-loader'));
|
2016-06-01 12:11:58 -04:00
|
|
|
let setConditionText: string;
|
2015-12-20 16:17:16 -05:00
|
|
|
setConditionButtonEle.getText().then(function(text) {
|
|
|
|
setConditionText = text;
|
|
|
|
expect(ngIfButtonEle.isPresent()).toBe(true, 'should be able to find ngIfButton');
|
|
|
|
expect(cssButtonEle.isPresent()).toBe(true, 'should be able to find cssButton');
|
|
|
|
expect(ngIfParentEle.isPresent()).toBe(true, 'should be able to find ngIfButton parent');
|
|
|
|
expect(ngIfSiblingEle.isPresent()).toBe(true, 'should be able to find ngIfButton sibling');
|
|
|
|
expect(cssSiblingEle.isPresent()).toBe(true, 'should be able to find cssButton sibling');
|
|
|
|
return ngIfButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(ngIfSiblingEle.isPresent()).toBe(false, 'now should NOT be able to find ngIfButton sibling');
|
|
|
|
expect(setConditionButtonEle.getText()).not.toEqual(setConditionText);
|
|
|
|
return cssButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(cssSiblingEle.isPresent()).toBe(true, 'now should still be able to find cssButton sibling');
|
|
|
|
expect(cssSiblingEle.isDisplayed()).toBe(false, 'now cssButton sibling should NOT be visible');
|
|
|
|
return ngIfButtonEle.click();
|
|
|
|
}).then(function() {
|
|
|
|
expect(setConditionButtonEle.getText()).toEqual(setConditionText);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be able to use *ngIf ', function () {
|
2016-05-30 14:05:09 -04:00
|
|
|
let setConditionButtonEle = element.all(by.css('button')).get(0);
|
|
|
|
let displayEles = element.all(by.cssContainingText('p', 'Our heroes are true!'));
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(displayEles.count()).toBe(2, 'should be displaying two ngIf elements');
|
2015-12-20 16:17:16 -05:00
|
|
|
setConditionButtonEle.click().then(function() {
|
2016-06-07 19:06:25 -04:00
|
|
|
expect(displayEles.count()).toBe(0, 'should nog longer be displaying ngIf elements');
|
2015-12-20 16:17:16 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|