@@ -311,41 +311,48 @@ describe('MdDialog', () => {
311
311
} ) ;
312
312
313
313
describe ( 'dialog content elements' , ( ) => {
314
- let fixture : ComponentFixture < ContentElementDialog > ;
315
- let dialogElement : HTMLElement ;
314
+ let dialogRef : MdDialogRef < ContentElementDialog > ;
316
315
317
316
beforeEach ( ( ) => {
318
- fixture = TestBed . createComponent ( ContentElementDialog ) ;
319
- dialogElement = fixture . debugElement . nativeElement ;
320
- dialog . open ( ContentElementDialog ) ;
321
- fixture . detectChanges ( ) ;
317
+ dialogRef = dialog . open ( ContentElementDialog ) ;
318
+ viewContainerFixture . detectChanges ( ) ;
322
319
} ) ;
323
320
324
- it ( 'close the dialog when clicking on the close button' , ( ) => {
321
+ it ( 'should close the dialog when clicking on the close button' , ( ) => {
325
322
expect ( overlayContainerElement . querySelectorAll ( '.md-dialog-container' ) . length ) . toBe ( 1 ) ;
326
323
327
- ( dialogElement . querySelector ( 'button[md-dialog-close]' ) as HTMLElement ) . click ( ) ;
324
+ ( overlayContainerElement . querySelector ( 'button[md-dialog-close]' ) as HTMLElement ) . click ( ) ;
328
325
329
326
expect ( overlayContainerElement . querySelectorAll ( '.md-dialog-container' ) . length ) . toBe ( 0 ) ;
330
327
} ) ;
331
328
332
- it ( 'close not close the dialog if [md-dialog-close] is applied on a non-button node' , ( ) => {
329
+ it ( 'should not close the dialog if [md-dialog-close] is applied on a non-button node' , ( ) => {
333
330
expect ( overlayContainerElement . querySelectorAll ( '.md-dialog-container' ) . length ) . toBe ( 1 ) ;
334
331
335
- ( dialogElement . querySelector ( 'div[md-dialog-close]' ) as HTMLElement ) . click ( ) ;
332
+ ( overlayContainerElement . querySelector ( 'div[md-dialog-close]' ) as HTMLElement ) . click ( ) ;
336
333
337
334
expect ( overlayContainerElement . querySelectorAll ( '.md-dialog-container' ) . length ) . toBe ( 1 ) ;
338
335
} ) ;
339
336
337
+ it ( 'should allow for a user-specified aria-label on the close button' , ( ) => {
338
+ let button = overlayContainerElement . querySelector ( 'button[md-dialog-close]' ) ;
339
+
340
+ dialogRef . componentInstance . closeButtonAriaLabel = 'Best close button ever' ;
341
+ viewContainerFixture . detectChanges ( ) ;
342
+
343
+ expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Best close button ever' ) ;
344
+ } ) ;
345
+
340
346
it ( 'should add a role to the dialog title' , ( ) => {
341
- let header = dialogElement . querySelector ( '[md-dialog-title]' ) ;
347
+ let header = overlayContainerElement . querySelector ( '[md-dialog-title]' ) ;
342
348
expect ( header . getAttribute ( 'role' ) ) . toBe ( 'heading' ) ;
343
349
} ) ;
344
350
345
351
it ( 'should add a role to the dialog content' , ( ) => {
346
- let content = dialogElement . querySelector ( 'md-dialog-content' ) ;
352
+ let content = overlayContainerElement . querySelector ( 'md-dialog-content' ) ;
347
353
expect ( content . getAttribute ( 'role' ) ) . toBe ( 'main' ) ;
348
354
} ) ;
355
+
349
356
} ) ;
350
357
} ) ;
351
358
@@ -378,12 +385,14 @@ class PizzaMsg {
378
385
<h1 md-dialog-title>This is the title</h1>
379
386
<md-dialog-content>Lorem ipsum dolor sit amet.</md-dialog-content>
380
387
<md-dialog-actions>
381
- <button md-dialog-close>Close</button>
388
+ <button md-dialog-close [aria-label]="closeButtonAriaLabel" >Close</button>
382
389
<div md-dialog-close>Should not close</div>
383
390
</md-dialog-actions>
384
391
`
385
392
} )
386
- class ContentElementDialog { }
393
+ class ContentElementDialog {
394
+ closeButtonAriaLabel : string ;
395
+ }
387
396
388
397
// Create a real (non-test) NgModule as a workaround for
389
398
// https://github.com/angular/angular/issues/10760
0 commit comments