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,88 @@ describe('Dialog', () => {
322326 expect ( dialog . isOpen ) . toEqual ( false ) ;
323327 } ) ) ;
324328
329+ fdescribe ( 'Position settings' , ( ) => {
330+ let fix ;
331+ let dialog ;
332+ let detect ;
333+ const positionSettings : PositionSettings = {
334+ horizontalDirection : HorizontalAlignment . Center ,
335+ verticalDirection : VerticalAlignment . Top
336+ } ;
337+
338+ beforeEach ( fakeAsync ( ( ) => {
339+ fix = TestBed . createComponent ( PositionSettingsDialogComponent ) ;
340+ fix . detectChanges ( ) ;
341+ dialog = fix . componentInstance . dialog ;
342+ detect = ( ) => dialog . cdr . detectChanges ( ) ;
343+ } ) ) ;
344+
345+ it ( 'Define different position settings ' , ( async ( ) => {
346+ dialog . open ( ) ;
347+ fix . detectChanges ( ) ;
348+ await wait ( 16 ) ;
349+
350+ expect ( dialog . isOpen ) . toEqual ( true ) ;
351+ const firstContentRect = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT_MODAL ) [ 0 ] . getBoundingClientRect ( ) ;
352+ const middleDialogPosition = document . documentElement . offsetHeight / 2 - firstContentRect . height / 2 ;
353+ expect ( firstContentRect . left ) . toEqual ( 0 , 'OffsetLeft position check' ) ;
354+ expect ( firstContentRect . top ) . toBeGreaterThanOrEqual ( middleDialogPosition - 2 , 'OffsetTop position check' ) ;
355+ expect ( firstContentRect . top ) . toBeLessThanOrEqual ( middleDialogPosition + 2 , 'OffsetTop position check' ) ;
356+
357+ dialog . close ( ) ;
358+ fix . detectChanges ( ) ;
359+ await wait ( 16 ) ;
360+
361+ expect ( dialog . isOpen ) . toEqual ( false ) ;
362+ dialog . positionSettings = positionSettings ;
363+ fix . detectChanges ( ) ;
364+ await wait ( 16 ) ;
365+
366+ dialog . open ( ) ;
367+ fix . detectChanges ( ) ;
368+ await wait ( 16 ) ;
369+
370+ expect ( dialog . isOpen ) . toEqual ( true ) ;
371+ const secondContentRect = document . getElementsByClassName ( CLASS_OVERLAY_CONTENT_MODAL ) [ 0 ] . getBoundingClientRect ( ) ;
372+ const topDialogPosition = document . documentElement . offsetWidth / 2 - secondContentRect . width / 2 ;
373+ expect ( secondContentRect . top ) . toEqual ( 0 , 'OffsetTop position check' ) ;
374+ expect ( secondContentRect . left ) . toBeGreaterThanOrEqual ( topDialogPosition - 2 , 'OffsetLeft position check' ) ;
375+ expect ( secondContentRect . left ) . toBeLessThanOrEqual ( topDialogPosition + 2 , 'OffsetLeft position check' ) ;
376+
377+ dialog . close ( ) ;
378+ fix . detectChanges ( ) ;
379+ await wait ( 16 ) ;
380+
381+ expect ( dialog . isOpen ) . toEqual ( false ) ;
382+ } ) ) ;
383+
384+ it ( 'Set animation settings' , ( async ( ) => {
385+ const currentElement = fix . componentInstance ;
386+ dialog . positionSettings = currentElement . animationSettings ;
387+ fix . detectChanges ( ) ;
388+ await wait ( 16 ) ;
389+
390+ // Check the new animation settings
391+ expect ( dialog . positionSettings . openAnimation . animation . type ) . toEqual ( 8 , 'Animation type is set' ) ;
392+ expect ( dialog . positionSettings . openAnimation . options . params . duration ) . toEqual ( '800ms' , 'Animation duration is set to 800ms' ) ;
393+
394+ expect ( dialog . positionSettings . closeAnimation . animation . type ) . toEqual ( 8 , 'Animation type is set' ) ;
395+ expect ( dialog . positionSettings . closeAnimation . options . params . duration ) . toEqual ( '700ms' , 'Animation duration is set to 700ms' ) ;
396+
397+ dialog . open ( ) ;
398+ fix . detectChanges ( ) ;
399+
400+ await wait ( 16 ) ;
401+ expect ( dialog . isOpen ) . toEqual ( true ) ;
402+
403+ dialog . close ( ) ;
404+ fix . detectChanges ( ) ;
405+ await wait ( 16 ) ;
406+
407+ expect ( dialog . isOpen ) . toEqual ( false ) ;
408+ } ) ) ;
409+ } ) ;
410+
325411 function dispatchEvent ( element : HTMLElement , eventType : string ) {
326412 const event = new Event ( eventType ) ;
327413 element . dispatchEvent ( event ) ;
@@ -436,3 +522,24 @@ class CustomTemplates1DialogComponent {
436522class CustomTemplates2DialogComponent {
437523 @ViewChild ( 'dialog' , { static : true } ) public dialog : IgxDialogComponent ;
438524}
525+
526+
527+ @Component ( {
528+ template : `<igx-dialog #dialog title="Notification" message="Your email has been sent successfully!" leftButtonLabel="OK"
529+ [positionSettings]="positionSettings" >
530+ </igx-dialog>` } )
531+ class PositionSettingsDialogComponent {
532+ @ViewChild ( 'dialog' , { static : true } ) public dialog : IgxDialogComponent ;
533+
534+ public positionSettings : PositionSettings = {
535+ horizontalDirection : HorizontalAlignment . Left ,
536+ verticalDirection : VerticalAlignment . Middle ,
537+ horizontalStartPoint : HorizontalAlignment . Left ,
538+ verticalStartPoint : VerticalAlignment . Middle
539+ } ;
540+
541+ public animationSettings : PositionSettings = {
542+ openAnimation : useAnimation ( slideInTop , { params : { duration : '800ms' } } ) ,
543+ closeAnimation : useAnimation ( slideOutBottom , { params : { duration : '700ms' } } )
544+ } ;
545+ }
0 commit comments