Skip to content

Commit 3a70cf3

Browse files
committed
add e2e tests
1 parent 70efc29 commit 3a70cf3

File tree

7 files changed

+126
-6
lines changed

7 files changed

+126
-6
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
describe('fullscreen', () => {
2+
beforeEach(() => browser.get('/fullscreen'));
3+
4+
let overlayInBody = () =>
5+
browser.isElementPresent(by.css('body > .md-overlay-container'));
6+
let overlayInFullscreen = () =>
7+
browser.isElementPresent(by.css('#fullscreenpane > .md-overlay-container'));
8+
9+
it('should open a dialog inside a fullscreen element and move it to the document body', () => {
10+
element(by.id('fullscreen')).click();
11+
element(by.id('dialog')).click();
12+
13+
overlayInFullscreen.then(isPresent => {
14+
expect(isPresent).toBe(true);
15+
element(by.id('exitfullscreenindialog')).click();
16+
overlayInBody.then(isPresent => {
17+
expect(isPresent).toBe(true);
18+
});
19+
});
20+
});
21+
22+
it('should open a dialog inside the document body and move it to a fullscreen element', () => {
23+
element(by.id('dialog')).click();
24+
overlayInBody.then(isPresent => {
25+
expect(isPresent).toBe(true);
26+
element(by.id('fullscreenindialog')).click();
27+
overlayInFullscreen.then(isPresent => {
28+
expect(isPresent).toBe(true);
29+
element(by.id('exitfullscreenindialog')).click();
30+
browser.isElementPresent(by.css('body > .md-overlay-container')).then(isPresent => {
31+
expect(isPresent).toBe(true);
32+
});
33+
});
34+
});
35+
});
36+
});

src/e2e-app/e2e-app-module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {BasicTabs} from './tabs/tabs-e2e';
1111
import {DialogE2E, TestDialog} from './dialog/dialog-e2e';
1212
import {GridListE2E} from './grid-list/grid-list-e2e';
1313
import {ListE2E} from './list/list-e2e';
14-
import {MaterialModule} from '@angular/material';
14+
import {FullscreenE2E, TestDialog as TestDialogFullScreen} from './fullscreen/fullscreen-e2e';
15+
import {MaterialModule, OverlayContainer, FullscreenOverlayContainer} from '@angular/material';
1516
import {E2E_APP_ROUTES} from './e2e-app/routes';
1617

1718

@@ -34,11 +35,14 @@ import {E2E_APP_ROUTES} from './e2e-app/routes';
3435
TestDialog,
3536
GridListE2E,
3637
ListE2E,
38+
FullscreenE2E,
39+
TestDialogFullScreen,
3740
],
3841
bootstrap: [E2EApp],
3942
providers: [
40-
{provide: AnimationDriver, useValue: AnimationDriver.NOOP}
43+
{provide: AnimationDriver, useValue: AnimationDriver.NOOP},
44+
{provide: OverlayContainer, useClass: FullscreenOverlayContainer}
4145
],
42-
entryComponents: [TestDialog]
46+
entryComponents: [TestDialog, TestDialogFullScreen]
4347
})
4448
export class E2eAppModule { }

src/e2e-app/e2e-app/e2e-app.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
<a md-list-item [routerLink]="['menu']">Menu</a>
88
<a md-list-item [routerLink]="['radio']">Radios</a>
99
<a md-list-item [routerLink]="['tabs']">Tabs</a>
10+
<a md-list-item [routerLink]="['fullscreen']">Fullscreen</a>
1011

1112
<router-outlet></router-outlet>

src/e2e-app/e2e-app/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {SimpleCheckboxes} from '../checkbox/checkbox-e2e';
99
import {DialogE2E} from '../dialog/dialog-e2e';
1010
import {GridListE2E} from '../grid-list/grid-list-e2e';
1111
import {ListE2E} from '../list/list-e2e';
12+
import {FullscreenE2E} from '../fullscreen/fullscreen-e2e';
1213

1314
export const E2E_APP_ROUTES: Routes = [
1415
{path: '', component: Home},
@@ -21,4 +22,5 @@ export const E2E_APP_ROUTES: Routes = [
2122
{path: 'dialog', component: DialogE2E},
2223
{path: 'grid-list', component: GridListE2E},
2324
{path: 'list', component: ListE2E},
25+
{path: 'fullscreen', component: FullscreenE2E},
2426
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<button id="fullscreen" (click)="toggleFullScreen()">FULLSCREEN</button>
2+
<div id="fullscreenpane" style="width: 100%; height: 100%">
3+
<button id="dialog" (click)="openDialog()">DIALOG</button>
4+
<button id="exitfullscreen" (click)="exitFullscreen()">EXIT FULLSCREEN</button>
5+
</div>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {Component, ElementRef, Output, EventEmitter} from '@angular/core';
2+
import {MdDialog, MdDialogRef, OverlayContainer,
3+
FullscreenOverlayContainer} from '@angular/material';
4+
5+
@Component({
6+
selector: 'fullscreen-e2e',
7+
moduleId: module.id,
8+
templateUrl: 'fullscreen-e2e.html'
9+
})
10+
export class FullscreenE2E {
11+
dialogRef: MdDialogRef<TestDialog>;
12+
13+
constructor (private _element: ElementRef, private _dialog: MdDialog,
14+
private _overlayContainer: OverlayContainer) { }
15+
16+
openDialog() {
17+
this.dialogRef = this._dialog.open(TestDialog);
18+
this.dialogRef.componentInstance.fullscreen.subscribe(() => this.toggleFullScreen());
19+
this.dialogRef.componentInstance.exitfullscreen.subscribe(() => this.exitFullscreen());
20+
this.dialogRef.afterClosed().subscribe(() => {
21+
this.dialogRef = null;
22+
});
23+
}
24+
25+
toggleFullScreen() {
26+
let elem = this._element.nativeElement.querySelector('#fullscreenpane');
27+
(this._overlayContainer as FullscreenOverlayContainer).toggleFullscreen(elem);
28+
}
29+
30+
exitFullscreen() {
31+
if (document.exitFullscreen) {
32+
document.exitFullscreen();
33+
} else if (document.webkitExitFullscreen) {
34+
document.webkitExitFullscreen();
35+
} else if ((document as any).mozExitFullScreen) {
36+
(document as any).mozExitFullScreen();
37+
} else if ((document as any).msExitFullScreen) {
38+
(document as any).msExitFullScreen();
39+
}
40+
}
41+
}
42+
43+
@Component({
44+
selector: 'fullscreen-dialog-e2e-test',
45+
template: `
46+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
47+
<button id="fullscreenindialog" (click)="fullscreen.emit()">FULLSCREEN</button>
48+
<button id="exitfullscreenindialog" (click)="exitfullscreen.emit()">EXIT FULLSCREEN</button>
49+
<button type="button" (click)="dialogRef.close()" id="close">CLOSE</button>`
50+
})
51+
export class TestDialog {
52+
constructor(public dialogRef: MdDialogRef<TestDialog>) { }
53+
@Output() fullscreen = new EventEmitter<void>();
54+
@Output() exitfullscreen = new EventEmitter<void>();
55+
}

src/lib/core/overlay/fullscreen-overlay-container.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import {OverlayContainer} from './overlay-container';
1414
export class FullscreenOverlayContainer extends OverlayContainer {
1515
protected _createContainer(): void {
1616
super._createContainer();
17+
this._adjustParentForFullscreenChange();
1718
this._addFullscreenChangeListener(() => this._adjustParentForFullscreenChange());
1819
}
1920

2021
private _adjustParentForFullscreenChange(): void {
2122
if (!this._containerElement) {
2223
return;
2324
}
24-
25-
let fullscreenElement = this._getFullscreenElement();
25+
let fullscreenElement = this.getFullscreenElement();
2626
let parent = fullscreenElement || document.body;
2727
parent.appendChild(this._containerElement);
2828
}
@@ -41,11 +41,28 @@ export class FullscreenOverlayContainer extends OverlayContainer {
4141

4242
// When the page is put into fullscreen mode, a specific element is specified.
4343
// Only that element and its children are visible when in fullscreen mode.
44-
private _getFullscreenElement(): Element {
44+
getFullscreenElement(): Element {
4545
return document.fullscreenElement ||
4646
document.webkitFullscreenElement ||
4747
(document as any).mozFullScreenElement ||
4848
(document as any).msFullscreenElement ||
4949
null;
5050
}
51+
52+
// returns true if it has tried to toggle fullscreen mode
53+
// but provides no guarantees whether it really happened
54+
toggleFullscreen(element: HTMLElement) {
55+
if (element.requestFullscreen) {
56+
element.requestFullscreen();
57+
} else if (element.webkitRequestFullScreen) {
58+
element.webkitRequestFullScreen();
59+
} else if ((element as any).mozRequestFullScreen) {
60+
(element as any).mozRequestFullScreen();
61+
} else if ((element as any).msRequestFullScreen) {
62+
(element as any).msRequestFullScreen();
63+
} else {
64+
return false;
65+
}
66+
return true;
67+
}
5168
}

0 commit comments

Comments
 (0)