@@ -27,7 +27,13 @@ import {MatDialogContainer} from './dialog-container';
27
27
import { OverlayContainer } from '@angular/cdk/overlay' ;
28
28
import { A , ESCAPE } from '@angular/cdk/keycodes' ;
29
29
import { dispatchKeyboardEvent } from '@angular/cdk/testing' ;
30
- import { MAT_DIALOG_DATA , MatDialog , MatDialogModule , MatDialogRef } from './index' ;
30
+ import {
31
+ MAT_DIALOG_DATA ,
32
+ MatDialog ,
33
+ MatDialogModule ,
34
+ MatDialogRef ,
35
+ MAT_DIALOG_DEFAULT_OPTIONS
36
+ } from './index' ;
31
37
32
38
33
39
describe ( 'MatDialog' , ( ) => {
@@ -965,6 +971,7 @@ describe('MatDialog', () => {
965
971
expect ( container . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
966
972
} ) ) ;
967
973
} ) ;
974
+
968
975
} ) ;
969
976
970
977
describe ( 'MatDialog with a parent MatDialog' , ( ) => {
@@ -1045,6 +1052,95 @@ describe('MatDialog with a parent MatDialog', () => {
1045
1052
} ) ) ;
1046
1053
} ) ;
1047
1054
1055
+ describe ( 'MatDialog with default options' , ( ) => {
1056
+ let dialog : MatDialog ;
1057
+ let overlayContainer : OverlayContainer ;
1058
+ let overlayContainerElement : HTMLElement ;
1059
+
1060
+ let testViewContainerRef : ViewContainerRef ;
1061
+ let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
1062
+
1063
+ beforeEach ( fakeAsync ( ( ) => {
1064
+ const defaultConfig = {
1065
+ hasBackdrop : false ,
1066
+ disableClose : true ,
1067
+ width : '100px' ,
1068
+ height : '100px' ,
1069
+ minWidth : '50px' ,
1070
+ minHeight : '50px' ,
1071
+ maxWidth : '150px' ,
1072
+ maxHeight : '150px' ,
1073
+ autoFocus : false ,
1074
+ } ;
1075
+
1076
+ TestBed . configureTestingModule ( {
1077
+ imports : [ MatDialogModule , DialogTestModule ] ,
1078
+ providers : [
1079
+ { provide : MAT_DIALOG_DEFAULT_OPTIONS , useValue : defaultConfig } ,
1080
+ ] ,
1081
+ } ) ;
1082
+
1083
+ TestBed . compileComponents ( ) ;
1084
+ } ) ) ;
1085
+
1086
+ beforeEach ( inject ( [ MatDialog , OverlayContainer ] ,
1087
+ ( d : MatDialog , oc : OverlayContainer ) => {
1088
+ dialog = d ;
1089
+ overlayContainer = oc ;
1090
+ overlayContainerElement = oc . getContainerElement ( ) ;
1091
+ } ) ) ;
1092
+
1093
+ afterEach ( ( ) => {
1094
+ overlayContainer . ngOnDestroy ( ) ;
1095
+ } ) ;
1096
+
1097
+ beforeEach ( ( ) => {
1098
+ viewContainerFixture = TestBed . createComponent ( ComponentWithChildViewContainer ) ;
1099
+
1100
+ viewContainerFixture . detectChanges ( ) ;
1101
+ testViewContainerRef = viewContainerFixture . componentInstance . childViewContainer ;
1102
+ } ) ;
1103
+
1104
+ it ( 'should use the provided defaults' , ( ) => {
1105
+ dialog . open ( PizzaMsg , { viewContainerRef : testViewContainerRef } ) ;
1106
+
1107
+ viewContainerFixture . detectChanges ( ) ;
1108
+
1109
+ expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ) . toBeFalsy ( ) ;
1110
+
1111
+ dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
1112
+ expect ( overlayContainerElement . querySelector ( 'mat-dialog-container' ) ) . toBeTruthy ( ) ;
1113
+
1114
+ expect ( document . activeElement . tagName ) . not . toBe ( 'INPUT' ) ;
1115
+
1116
+ let overlayPane = overlayContainerElement . querySelector ( '.cdk-overlay-pane' ) as HTMLElement ;
1117
+ expect ( overlayPane . style . width ) . toBe ( '100px' ) ;
1118
+ expect ( overlayPane . style . height ) . toBe ( '100px' ) ;
1119
+ expect ( overlayPane . style . minWidth ) . toBe ( '50px' ) ;
1120
+ expect ( overlayPane . style . minHeight ) . toBe ( '50px' ) ;
1121
+ expect ( overlayPane . style . maxWidth ) . toBe ( '150px' ) ;
1122
+ expect ( overlayPane . style . maxHeight ) . toBe ( '150px' ) ;
1123
+ } ) ;
1124
+
1125
+ it ( 'should be overridable by open() options' , fakeAsync ( ( ) => {
1126
+ dialog . open ( PizzaMsg , {
1127
+ hasBackdrop : true ,
1128
+ disableClose : false ,
1129
+ viewContainerRef : testViewContainerRef
1130
+ } ) ;
1131
+
1132
+ viewContainerFixture . detectChanges ( ) ;
1133
+
1134
+ expect ( overlayContainerElement . querySelector ( '.cdk-overlay-backdrop' ) ) . toBeTruthy ( ) ;
1135
+
1136
+ dispatchKeyboardEvent ( document . body , 'keydown' , ESCAPE ) ;
1137
+ viewContainerFixture . detectChanges ( ) ;
1138
+ flush ( ) ;
1139
+
1140
+ expect ( overlayContainerElement . querySelector ( 'mat-dialog-container' ) ) . toBeFalsy ( ) ;
1141
+ } ) ) ;
1142
+ } ) ;
1143
+
1048
1144
1049
1145
@Directive ( { selector : 'dir-with-view-container' } )
1050
1146
class DirectiveWithViewContainer {
0 commit comments