2017-02-22 18:13:21 +00:00
|
|
|
import { browser, element, by } from 'protractor';
|
|
|
|
|
2020-07-30 13:03:13 +03:00
|
|
|
describe('Structural Directives', () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
beforeAll(() => browser.get(''));
|
2017-02-22 18:13:21 +00:00
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('first div should show hero name with *ngIf', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const allDivs = element.all(by.tagName('div'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await allDivs.get(0).getText()).toEqual('Dr Nice');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('first li should show hero name with *ngFor', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const allLis = element.all(by.tagName('li'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await allLis.get(0).getText()).toEqual('Dr Nice');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('ngSwitch have two <happy-hero> instances', async () => {
|
2017-08-22 21:31:15 +02:00
|
|
|
const happyHeroEls = element.all(by.tagName('app-happy-hero'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await happyHeroEls.count()).toEqual(2);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should toggle *ngIf="hero" with a button', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const toggleHeroButton = element.all(by.cssContainingText('button', 'Toggle hero')).get(0);
|
|
|
|
const paragraph = element.all(by.cssContainingText('p', 'I turned the corner'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await paragraph.get(0).getText()).toContain('I waved');
|
|
|
|
await toggleHeroButton.click();
|
|
|
|
expect(await paragraph.get(0).getText()).not.toContain('I waved');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('should have only one "Hip!" (the other is erased)', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const paragraph = element.all(by.cssContainingText('p', 'Hip!'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await paragraph.count()).toEqual(1);
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('appUnless should show 3 paragraph (A)s and (B)s at the start', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const paragraph = element.all(by.css('p.unless'));
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await paragraph.count()).toEqual(3);
|
2017-02-22 18:13:21 +00:00
|
|
|
for (let i = 0; i < 3; i++) {
|
2020-11-23 20:17:10 +02:00
|
|
|
expect(await paragraph.get(i).getText()).toContain('(A)');
|
2017-02-22 18:13:21 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
it('appUnless should show 1 paragraph (B) after toggling condition', async () => {
|
2017-02-22 18:13:21 +00:00
|
|
|
const toggleConditionButton = element.all(by.cssContainingText('button', 'Toggle condition')).get(0);
|
|
|
|
const paragraph = element.all(by.css('p.unless'));
|
|
|
|
|
2020-11-23 20:17:10 +02:00
|
|
|
await toggleConditionButton.click();
|
|
|
|
|
|
|
|
expect(await paragraph.count()).toEqual(1);
|
|
|
|
expect(await paragraph.get(0).getText()).toContain('(B)');
|
2017-02-22 18:13:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|