1+ import { E2EUtils } from '../../utils.e2e' ;
2+
13describe ( 'dialog' , ( ) => {
4+ const utils = new E2EUtils ( ) ;
5+
26 beforeEach ( ( ) => browser . get ( '/dialog' ) ) ;
37
48 it ( 'should open a dialog' , ( ) => {
59 element ( by . id ( 'default' ) ) . click ( ) ;
6- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( true ) ) ;
10+ utils . expectToExist ( 'md-dialog-container' ) ;
711 } ) ;
812
913 it ( 'should close by clicking on the backdrop' , ( ) => {
1014 element ( by . id ( 'default' ) ) . click ( ) ;
1115
1216 waitForDialog ( ) . then ( ( ) => {
1317 clickOnBackrop ( ) ;
14- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( false ) ) ;
18+ utils . expectToExist ( 'md-dialog-container' , false ) ;
1519 } ) ;
1620 } ) ;
1721
1822 it ( 'should close by pressing escape' , ( ) => {
1923 element ( by . id ( 'default' ) ) . click ( ) ;
2024
2125 waitForDialog ( ) . then ( ( ) => {
22- pressEscape ( ) ;
23- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( false ) ) ;
26+ utils . pressKeys ( protractor . Key . ESCAPE ) ;
27+ utils . expectToExist ( 'md-dialog-container' , false ) ;
2428 } ) ;
2529 } ) ;
2630
@@ -29,15 +33,15 @@ describe('dialog', () => {
2933
3034 waitForDialog ( ) . then ( ( ) => {
3135 element ( by . id ( 'close' ) ) . click ( ) ;
32- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( false ) ) ;
36+ utils . expectToExist ( 'md-dialog-container' , false ) ;
3337 } ) ;
3438 } ) ;
3539
3640 it ( 'should focus the first focusable element' , ( ) => {
3741 element ( by . id ( 'default' ) ) . click ( ) ;
3842
3943 waitForDialog ( ) . then ( ( ) => {
40- expectFocusOn ( element ( by . css ( 'md-dialog-container input' ) ) ) ;
44+ utils . expectFocusOn ( 'md-dialog-container input' ) ;
4145 } ) ;
4246 } ) ;
4347
@@ -48,7 +52,7 @@ describe('dialog', () => {
4852
4953 waitForDialog ( ) . then ( ( ) => {
5054 clickOnBackrop ( ) ;
51- expectFocusOn ( openButton ) ;
55+ utils . expectFocusOn ( openButton ) ;
5256 } ) ;
5357 } ) ;
5458
@@ -58,8 +62,8 @@ describe('dialog', () => {
5862 waitForDialog ( ) . then ( ( ) => {
5963 let tab = protractor . Key . TAB ;
6064
61- browser . actions ( ) . sendKeys ( tab , tab , tab ) . perform ( ) ;
62- expectFocusOn ( element ( by . id ( ' close') ) ) ;
65+ utils . pressKeys ( tab , tab , tab ) ;
66+ utils . expectFocusOn ( '# close') ;
6367 } ) ;
6468 } ) ;
6569
@@ -68,38 +72,24 @@ describe('dialog', () => {
6872
6973 waitForDialog ( ) . then ( ( ) => {
7074 clickOnBackrop ( ) ;
71- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( true ) ) ;
75+ utils . expectToExist ( 'md-dialog-container' ) ;
7276 } ) ;
7377 } ) ;
7478
7579 it ( 'should be able to prevent closing by pressing escape' , ( ) => {
7680 element ( by . id ( 'disabled' ) ) . click ( ) ;
7781
7882 waitForDialog ( ) . then ( ( ) => {
79- pressEscape ( ) ;
80- waitForDialog ( ) . then ( isPresent => expect ( isPresent ) . toBe ( true ) ) ;
83+ utils . pressKeys ( protractor . Key . ESCAPE ) ;
84+ utils . expectToExist ( 'md-dialog-container' ) ;
8185 } ) ;
8286 } ) ;
8387
8488 function waitForDialog ( ) {
85- return browser . isElementPresent ( by . css ( 'md-dialog-container' ) ) ;
89+ return utils . waitForElement ( 'md-dialog-container' ) ;
8690 }
8791
8892 function clickOnBackrop ( ) {
89- browser . actions ( )
90- // We need to move the cursor to the top left so
91- // the dialog doesn't receive the click accidentally.
92- . mouseMove ( element ( by . css ( '.md-overlay-backdrop' ) ) . getWebElement ( ) , { x : 0 , y : 0 } )
93- . click ( )
94- . perform ( ) ;
95- }
96-
97- function pressEscape ( ) {
98- browser . actions ( ) . sendKeys ( protractor . Key . ESCAPE ) . perform ( ) ;
99- }
100-
101- // TODO(crisbeto): should be moved to a common util. copied from the menu e2e setup.
102- function expectFocusOn ( el : any ) : void {
103- expect ( browser . driver . switchTo ( ) . activeElement ( ) . getInnerHtml ( ) ) . toBe ( el . getInnerHtml ( ) ) ;
93+ utils . clickElementAtPoint ( '.md-overlay-backdrop' , { x : 0 , y : 0 } ) ;
10494 }
10595} ) ;
0 commit comments