@@ -7,16 +7,15 @@ import {
77 wrappedErrorMessage ,
88} from '@angular/cdk/testing/private' ;
99import { Component , ElementRef , ViewChild } from '@angular/core' ;
10- import { async , ComponentFixture , fakeAsync , inject , TestBed , tick } from '@angular/core/testing' ;
11- import { By } from '@angular/platform-browser' ;
10+ import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
1211import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
12+ import { By } from '@angular/platform-browser' ;
1313import { Observable } from 'rxjs' ;
1414import { map } from 'rxjs/operators' ;
1515import { MatTableModule } from '../table/index' ;
1616import {
1717 MatSort ,
1818 MatSortHeader ,
19- MatSortHeaderIntl ,
2019 MatSortModule ,
2120 Sort ,
2221 SortDirection
@@ -220,40 +219,40 @@ describe('MatSort', () => {
220219 } ) ;
221220
222221 it ( 'should allow for the cycling the sort direction to be disabled per column' , ( ) => {
223- const button = fixture . nativeElement . querySelector ( '#defaultA button ' ) ;
222+ const container = fixture . nativeElement . querySelector ( '#defaultA .mat-sort-header-container ' ) ;
224223
225224 component . sort ( 'defaultA' ) ;
226225 expect ( component . matSort . direction ) . toBe ( 'asc' ) ;
227- expect ( button . getAttribute ( 'disabled ' ) ) . toBeFalsy ( ) ;
226+ expect ( container . getAttribute ( 'tabindex ' ) ) . toBe ( '0' ) ;
228227
229228 component . disabledColumnSort = true ;
230229 fixture . detectChanges ( ) ;
231230
232231 component . sort ( 'defaultA' ) ;
233232 expect ( component . matSort . direction ) . toBe ( 'asc' ) ;
234- expect ( button . getAttribute ( 'disabled ' ) ) . toBe ( 'true' ) ;
233+ expect ( container . getAttribute ( 'tabindex ' ) ) . toBeFalsy ( ) ;
235234 } ) ;
236235
237236 it ( 'should allow for the cycling the sort direction to be disabled for all columns' , ( ) => {
238- const button = fixture . nativeElement . querySelector ( '#defaultA button ' ) ;
237+ const container = fixture . nativeElement . querySelector ( '#defaultA .mat-sort-header-container ' ) ;
239238
240239 component . sort ( 'defaultA' ) ;
241240 expect ( component . matSort . active ) . toBe ( 'defaultA' ) ;
242241 expect ( component . matSort . direction ) . toBe ( 'asc' ) ;
243- expect ( button . getAttribute ( 'disabled ' ) ) . toBeFalsy ( ) ;
242+ expect ( container . getAttribute ( 'tabindex ' ) ) . toBe ( '0' ) ;
244243
245244 component . disableAllSort = true ;
246245 fixture . detectChanges ( ) ;
247246
248247 component . sort ( 'defaultA' ) ;
249248 expect ( component . matSort . active ) . toBe ( 'defaultA' ) ;
250249 expect ( component . matSort . direction ) . toBe ( 'asc' ) ;
251- expect ( button . getAttribute ( 'disabled ' ) ) . toBe ( 'true' ) ;
250+ expect ( container . getAttribute ( 'tabindex ' ) ) . toBeFalsy ( ) ;
252251
253252 component . sort ( 'defaultB' ) ;
254253 expect ( component . matSort . active ) . toBe ( 'defaultA' ) ;
255254 expect ( component . matSort . direction ) . toBe ( 'asc' ) ;
256- expect ( button . getAttribute ( 'disabled ' ) ) . toBe ( 'true' ) ;
255+ expect ( container . getAttribute ( 'tabindex ' ) ) . toBeFalsy ( ) ;
257256 } ) ;
258257
259258 it ( 'should reset sort direction when a different column is sorted' , ( ) => {
@@ -301,29 +300,24 @@ describe('MatSort', () => {
301300 fixture , [ 'asc' , 'desc' ] , 'overrideDisableClear' ) ;
302301 } ) ;
303302
304- it ( 'should apply the aria-labels to the button' , ( ) => {
305- const button = fixture . nativeElement . querySelector ( '#defaultA button' ) ;
306- expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Change sorting for defaultA' ) ;
307- } ) ;
308-
309303 it ( 'should toggle indicator hint on button focus/blur and hide on click' , ( ) => {
310304 const header = fixture . componentInstance . defaultA ;
311- const button = fixture . nativeElement . querySelector ( '#defaultA button ' ) ;
305+ const container = fixture . nativeElement . querySelector ( '#defaultA .mat-sort-header-container ' ) ;
312306 const focusEvent = createFakeEvent ( 'focus' ) ;
313307 const blurEvent = createFakeEvent ( 'blur' ) ;
314308
315309 // Should start without a displayed hint
316310 expect ( header . _showIndicatorHint ) . toBeFalsy ( ) ;
317311
318312 // Focusing the button should show the hint, blurring should hide it
319- button . dispatchEvent ( focusEvent ) ;
313+ container . dispatchEvent ( focusEvent ) ;
320314 expect ( header . _showIndicatorHint ) . toBeTruthy ( ) ;
321315
322- button . dispatchEvent ( blurEvent ) ;
316+ container . dispatchEvent ( blurEvent ) ;
323317 expect ( header . _showIndicatorHint ) . toBeFalsy ( ) ;
324318
325319 // Show the indicator hint. On click the hint should be hidden
326- button . dispatchEvent ( focusEvent ) ;
320+ container . dispatchEvent ( focusEvent ) ;
327321 expect ( header . _showIndicatorHint ) . toBeTruthy ( ) ;
328322
329323 header . _handleClick ( ) ;
@@ -356,7 +350,7 @@ describe('MatSort', () => {
356350
357351 it ( 'should apply the aria-sort label to the header when sorted' , ( ) => {
358352 const sortHeaderElement = fixture . nativeElement . querySelector ( '#defaultA' ) ;
359- expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( null ) ;
353+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( 'none' ) ;
360354
361355 component . sort ( 'defaultA' ) ;
362356 fixture . detectChanges ( ) ;
@@ -368,22 +362,9 @@ describe('MatSort', () => {
368362
369363 component . sort ( 'defaultA' ) ;
370364 fixture . detectChanges ( ) ;
371- expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( null ) ;
365+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( 'none' ) ;
372366 } ) ;
373367
374- it ( 'should re-render when the i18n labels have changed' ,
375- inject ( [ MatSortHeaderIntl ] , ( intl : MatSortHeaderIntl ) => {
376- const header = fixture . debugElement . query ( By . directive ( MatSortHeader ) ) ! . nativeElement ;
377- const button = header . querySelector ( '.mat-sort-header-button' ) ;
378-
379- intl . sortButtonLabel = ( ) => 'Sort all of the things' ;
380- intl . changes . next ( ) ;
381- fixture . detectChanges ( ) ;
382-
383- expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Sort all of the things' ) ;
384- } )
385- ) ;
386-
387368 it ( 'should not render the arrow if sorting is disabled for that column' , fakeAsync ( ( ) => {
388369 const sortHeaderElement = fixture . nativeElement . querySelector ( '#defaultA' ) ;
389370
@@ -412,9 +393,9 @@ describe('MatSort', () => {
412393 it ( 'should have a focus indicator' , ( ) => {
413394 const headerNativeElement =
414395 fixture . debugElement . query ( By . directive ( MatSortHeader ) ) ! . nativeElement ;
415- const buttonNativeElement = headerNativeElement . querySelector ( '.mat-sort-header-button ' ) ;
396+ const container = headerNativeElement . querySelector ( '.mat-sort-header-container ' ) ;
416397
417- expect ( buttonNativeElement . classList . contains ( 'mat-focus-indicator' ) ) . toBe ( true ) ;
398+ expect ( container . classList . contains ( 'mat-focus-indicator' ) ) . toBe ( true ) ;
418399 } ) ;
419400
420401} ) ;
0 commit comments