@@ -36,6 +36,7 @@ import {
36
36
MAT_DIALOG_DEFAULT_OPTIONS
37
37
} from './index' ;
38
38
import { Subject } from 'rxjs' ;
39
+ import { MutationObserverFactory } from '@angular/cdk/observers' ;
39
40
40
41
41
42
describe ( 'MatDialog' , ( ) => {
@@ -47,15 +48,30 @@ describe('MatDialog', () => {
47
48
let testViewContainerRef : ViewContainerRef ;
48
49
let viewContainerFixture : ComponentFixture < ComponentWithChildViewContainer > ;
49
50
let mockLocation : SpyLocation ;
51
+ let mutationCallbacks : Function [ ] ;
50
52
51
53
beforeEach ( fakeAsync ( ( ) => {
54
+ mutationCallbacks = [ ] ;
52
55
TestBed . configureTestingModule ( {
53
56
imports : [ MatDialogModule , DialogTestModule ] ,
54
57
providers : [
55
58
{ provide : Location , useClass : SpyLocation } ,
56
59
{ provide : ScrollDispatcher , useFactory : ( ) => ( {
57
60
scrolled : ( ) => scrolledSubject . asObservable ( )
58
61
} ) } ,
62
+ {
63
+ provide : MutationObserverFactory ,
64
+ useValue : {
65
+ create : ( callback : Function ) => {
66
+ mutationCallbacks . push ( callback ) ;
67
+
68
+ return {
69
+ observe : ( ) => { } ,
70
+ disconnect : ( ) => { }
71
+ } ;
72
+ }
73
+ }
74
+ }
59
75
] ,
60
76
} ) ;
61
77
@@ -1148,6 +1164,14 @@ describe('MatDialog', () => {
1148
1164
expect ( button . getAttribute ( 'aria-label' ) ) . toBeTruthy ( ) ;
1149
1165
} ) ) ;
1150
1166
1167
+ it ( 'should not have an aria-label if a button has bound text' , fakeAsync ( ( ) => {
1168
+ let button = overlayContainerElement . querySelector ( '.close-with-text-binding' ) ! ;
1169
+ mutationCallbacks . forEach ( callback => callback ( ) ) ;
1170
+ viewContainerFixture . detectChanges ( ) ;
1171
+
1172
+ expect ( button . getAttribute ( 'aria-label' ) ) . toBeFalsy ( ) ;
1173
+ } ) ) ;
1174
+
1151
1175
it ( 'should not have an aria-label if a button has text' , fakeAsync ( ( ) => {
1152
1176
let button = overlayContainerElement . querySelector ( '[mat-dialog-close]' ) ! ;
1153
1177
expect ( button . getAttribute ( 'aria-label' ) ) . toBeFalsy ( ) ;
@@ -1511,6 +1535,7 @@ class PizzaMsg {
1511
1535
<button class="close-without-text" mat-dialog-close></button>
1512
1536
<button class="close-icon-button" mat-icon-button mat-dialog-close>exit</button>
1513
1537
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
1538
+ <button class="close-with-text-binding" mat-dialog-close>{{closeButtonText}}</button>
1514
1539
<button
1515
1540
class="close-with-aria-label"
1516
1541
aria-label="Best close button ever"
@@ -1519,7 +1544,9 @@ class PizzaMsg {
1519
1544
</mat-dialog-actions>
1520
1545
`
1521
1546
} )
1522
- class ContentElementDialog { }
1547
+ class ContentElementDialog {
1548
+ closeButtonText = 'Close' ;
1549
+ }
1523
1550
1524
1551
@Component ( {
1525
1552
template : `
@@ -1531,6 +1558,7 @@ class ContentElementDialog {}
1531
1558
<button class="close-without-text" mat-dialog-close></button>
1532
1559
<button class="close-icon-button" mat-icon-button mat-dialog-close>exit</button>
1533
1560
<button class="close-with-true" [mat-dialog-close]="true">Close and return true</button>
1561
+ <button class="close-with-text-binding" mat-dialog-close>{{closeButtonText}}</button>
1534
1562
<button
1535
1563
class="close-with-aria-label"
1536
1564
aria-label="Best close button ever"
@@ -1542,6 +1570,7 @@ class ContentElementDialog {}
1542
1570
} )
1543
1571
class ComponentWithContentElementTemplateRef {
1544
1572
@ViewChild ( TemplateRef ) templateRef : TemplateRef < any > ;
1573
+ closeButtonText = 'Close' ;
1545
1574
}
1546
1575
1547
1576
@Component ( {
0 commit comments