1- import { Component , DebugElement , ElementRef , ViewChild } from '@angular/core' ;
2- import { async , ComponentFixture , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
1+ import { Component , ViewChild } from '@angular/core' ;
2+ import { async , TestBed , fakeAsync , tick } from '@angular/core/testing' ;
33import { By } from '@angular/platform-browser' ;
44import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
55import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
66import { IDialogEventArgs , IgxDialogComponent , IgxDialogModule } from './dialog.component' ;
77import { configureTestSuite } from '../test-utils/configure-suite' ;
8+ import { PositionSettings , slideInTop , slideOutBottom , HorizontalAlignment , VerticalAlignment } from 'igniteui-angular' ;
9+ import { useAnimation } from '@angular/animations' ;
810
911const OVERLAY_MAIN_CLASS = 'igx-overlay' ;
1012const OVERLAY_WRAPPER_CLASS = `${ OVERLAY_MAIN_CLASS } __wrapper` ;
1113const OVERLAY_MODAL_WRAPPER_CLASS = `${ OVERLAY_WRAPPER_CLASS } --modal` ;
14+ const CLASS_OVERLAY_CONTENT_MODAL = `${ OVERLAY_MAIN_CLASS } __content--modal` ;
1215
1316describe ( 'Dialog' , ( ) => {
1417 configureTestSuite ( ) ;
@@ -21,7 +24,8 @@ describe('Dialog', () => {
2124 NestedDialogsComponent ,
2225 CustomTemplates1DialogComponent ,
2326 CustomTemplates2DialogComponent ,
24- DialogSampleComponent
27+ DialogSampleComponent ,
28+ PositionSettingsDialogComponent
2529 ] ,
2630 imports : [ BrowserAnimationsModule , NoopAnimationsModule , IgxDialogModule ]
2731 } ) . compileComponents ( ) ;
@@ -322,6 +326,78 @@ describe('Dialog', () => {
322326 expect ( dialog . isOpen ) . toEqual ( false ) ;
323327 } ) ) ;
324328
329+ describe ( 'Position settings' , ( ) => {
330+ let fix ;
331+ let dialog ;
332+ let detect ;
333+
334+ beforeEach ( fakeAsync ( ( ) => {
335+ fix = TestBed . createComponent ( PositionSettingsDialogComponent ) ;
336+ fix . detectChanges ( ) ;
337+ dialog = fix . componentInstance . dialog ;
338+ detect = ( ) => dialog . cdr . detectChanges ( ) ;
339+ } ) ) ;
340+
341+ it ( 'Define different position settings ' , ( async ( ) => {
342+ const currentElement = fix . componentInstance ;
343+ dialog . open ( ) ;
344+ fix . detectChanges ( ) ;
345+ await wait ( 16 ) ;
346+
347+ expect ( dialog . isOpen ) . toEqual ( true ) ;
348+ const firstContentRect = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT_MODAL ) [ 0 ] . getBoundingClientRect ( ) ;
349+ const middleDialogPosition = document . documentElement . offsetHeight / 2 - firstContentRect . height / 2 ;
350+ expect ( firstContentRect . left ) . toEqual ( 0 , 'OffsetLeft position check' ) ;
351+ expect ( firstContentRect . top ) . toBeGreaterThanOrEqual ( middleDialogPosition - 2 , 'OffsetTop position check' ) ;
352+ expect ( firstContentRect . top ) . toBeLessThanOrEqual ( middleDialogPosition + 2 , 'OffsetTop position check' ) ;
353+
354+ dialog . close ( ) ;
355+ fix . detectChanges ( ) ;
356+ await wait ( 16 ) ;
357+
358+ expect ( dialog . isOpen ) . toEqual ( false ) ;
359+ dialog . positionSettings = currentElement . newPositionSettings ;
360+ fix . detectChanges ( ) ;
361+ await wait ( 16 ) ;
362+
363+ dialog . open ( ) ;
364+ fix . detectChanges ( ) ;
365+ await wait ( 16 ) ;
366+
367+ expect ( dialog . isOpen ) . toEqual ( true ) ;
368+ const secondContentRect = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT_MODAL ) [ 0 ] . getBoundingClientRect ( ) ;
369+ const topDialogPosition = document . documentElement . offsetWidth / 2 - secondContentRect . width / 2 ;
370+ expect ( secondContentRect . top ) . toEqual ( 0 , 'OffsetTop position check' ) ;
371+ expect ( secondContentRect . left ) . toBeGreaterThanOrEqual ( topDialogPosition - 2 , 'OffsetLeft position check' ) ;
372+ expect ( secondContentRect . left ) . toBeLessThanOrEqual ( topDialogPosition + 2 , 'OffsetLeft position check' ) ;
373+
374+ dialog . close ( ) ;
375+ fix . detectChanges ( ) ;
376+ await wait ( 16 ) ;
377+
378+ expect ( dialog . isOpen ) . toEqual ( false ) ;
379+ } ) ) ;
380+
381+ it ( 'Set animation settings' , ( async ( ) => {
382+ const currentElement = fix . componentInstance ;
383+
384+ // Check initial animation settings
385+ expect ( dialog . positionSettings . openAnimation . animation . type ) . toEqual ( 8 , 'Animation type is set' ) ;
386+ expect ( dialog . positionSettings . openAnimation . options . params . duration ) . toEqual ( '200ms' , 'Animation duration is set to 200ms' ) ;
387+
388+ expect ( dialog . positionSettings . closeAnimation . animation . type ) . toEqual ( 8 , 'Animation type is set' ) ;
389+ expect ( dialog . positionSettings . closeAnimation . options . params . duration ) . toEqual ( '200ms' , 'Animation duration is set to 200ms' ) ;
390+
391+ dialog . positionSettings = currentElement . animationSettings ;
392+ fix . detectChanges ( ) ;
393+ await wait ( 16 ) ;
394+
395+ // Check the new animation settings
396+ expect ( dialog . positionSettings . openAnimation . options . params . duration ) . toEqual ( '800ms' , 'Animation duration is set to 800ms' ) ;
397+ expect ( dialog . positionSettings . closeAnimation . options . params . duration ) . toEqual ( '700ms' , 'Animation duration is set to 700ms' ) ;
398+ } ) ) ;
399+ } ) ;
400+
325401 function dispatchEvent ( element : HTMLElement , eventType : string ) {
326402 const event = new Event ( eventType ) ;
327403 element . dispatchEvent ( event ) ;
@@ -436,3 +512,32 @@ class CustomTemplates1DialogComponent {
436512class CustomTemplates2DialogComponent {
437513 @ViewChild ( 'dialog' ) public dialog : IgxDialogComponent ;
438514}
515+
516+
517+ @Component ( {
518+ template : `<igx-dialog #dialog title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK"
519+ [positionSettings]="positionSettings" >
520+ </igx-dialog>` } )
521+ class PositionSettingsDialogComponent {
522+ @ViewChild ( 'dialog' ) public dialog : IgxDialogComponent ;
523+
524+ public positionSettings : PositionSettings = {
525+ horizontalDirection : HorizontalAlignment . Left ,
526+ verticalDirection : VerticalAlignment . Middle ,
527+ horizontalStartPoint : HorizontalAlignment . Left ,
528+ verticalStartPoint : VerticalAlignment . Middle ,
529+ openAnimation : useAnimation ( slideInTop , { params : { duration : '200ms' } } ) ,
530+ closeAnimation : useAnimation ( slideOutBottom , { params : { duration : '200ms' } } )
531+ } ;
532+
533+ public newPositionSettings : PositionSettings = {
534+ horizontalDirection : HorizontalAlignment . Center ,
535+ verticalDirection : VerticalAlignment . Top
536+ } ;
537+
538+ public animationSettings : PositionSettings = {
539+ openAnimation : useAnimation ( slideInTop , { params : { duration : '800ms' } } ) ,
540+ closeAnimation : useAnimation ( slideOutBottom , { params : { duration : '700ms' } } )
541+ } ;
542+
543+ }
0 commit comments