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' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
import { BrowserAnimationsModule , NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
5
import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
6
6
import { IDialogEventArgs , IgxDialogComponent , IgxDialogModule } from './dialog.component' ;
7
7
import { configureTestSuite } from '../test-utils/configure-suite' ;
8
+ import { PositionSettings , slideInTop , slideOutBottom , HorizontalAlignment , VerticalAlignment } from 'igniteui-angular' ;
9
+ import { useAnimation } from '@angular/animations' ;
8
10
9
11
const OVERLAY_MAIN_CLASS = 'igx-overlay' ;
10
12
const OVERLAY_WRAPPER_CLASS = `${ OVERLAY_MAIN_CLASS } __wrapper` ;
11
13
const OVERLAY_MODAL_WRAPPER_CLASS = `${ OVERLAY_WRAPPER_CLASS } --modal` ;
14
+ const CLASS_OVERLAY_CONTENT_MODAL = `${ OVERLAY_MAIN_CLASS } __content--modal` ;
12
15
13
16
describe ( 'Dialog' , ( ) => {
14
17
configureTestSuite ( ) ;
@@ -21,7 +24,8 @@ describe('Dialog', () => {
21
24
NestedDialogsComponent ,
22
25
CustomTemplates1DialogComponent ,
23
26
CustomTemplates2DialogComponent ,
24
- DialogSampleComponent
27
+ DialogSampleComponent ,
28
+ PositionSettingsDialogComponent
25
29
] ,
26
30
imports : [ BrowserAnimationsModule , NoopAnimationsModule , IgxDialogModule ]
27
31
} ) . compileComponents ( ) ;
@@ -322,6 +326,78 @@ describe('Dialog', () => {
322
326
expect ( dialog . isOpen ) . toEqual ( false ) ;
323
327
} ) ) ;
324
328
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
+
325
401
function dispatchEvent ( element : HTMLElement , eventType : string ) {
326
402
const event = new Event ( eventType ) ;
327
403
element . dispatchEvent ( event ) ;
@@ -436,3 +512,32 @@ class CustomTemplates1DialogComponent {
436
512
class CustomTemplates2DialogComponent {
437
513
@ViewChild ( 'dialog' , { static : true } ) public dialog : IgxDialogComponent ;
438
514
}
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' , { static : true } ) 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