@@ -45,6 +45,8 @@ describe('MatSort', () => {
45
45
MatSortDuplicateMatSortableIdsApp ,
46
46
MatSortableMissingIdApp ,
47
47
MatSortableInvalidDirection ,
48
+ MatSortableInvalidDirection ,
49
+ MatSortWithArrowPosition ,
48
50
] ,
49
51
} ) . compileComponents ( ) ;
50
52
} ) ,
@@ -78,7 +80,6 @@ describe('MatSort', () => {
78
80
const cdkTableMatSortAppFixture = TestBed . createComponent ( CdkTableMatSortApp ) ;
79
81
const cdkTableMatSortAppComponent = cdkTableMatSortAppFixture . componentInstance ;
80
82
81
- cdkTableMatSortAppFixture . detectChanges ( ) ;
82
83
cdkTableMatSortAppFixture . detectChanges ( ) ;
83
84
84
85
const sortables = cdkTableMatSortAppComponent . matSort . sortables ;
@@ -92,7 +93,6 @@ describe('MatSort', () => {
92
93
const matTableMatSortAppFixture = TestBed . createComponent ( MatTableMatSortApp ) ;
93
94
const matTableMatSortAppComponent = matTableMatSortAppFixture . componentInstance ;
94
95
95
- matTableMatSortAppFixture . detectChanges ( ) ;
96
96
matTableMatSortAppFixture . detectChanges ( ) ;
97
97
98
98
const sortables = matTableMatSortAppComponent . matSort . sortables ;
@@ -439,6 +439,64 @@ describe('MatSort', () => {
439
439
descriptionElement = document . getElementById ( descriptionId ) ;
440
440
expect ( descriptionElement ?. textContent ) . toBe ( 'Sort 2nd column' ) ;
441
441
} ) ;
442
+
443
+ it ( 'should render arrows after sort header by default' , ( ) => {
444
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
445
+
446
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
447
+
448
+ const containerA = matSortWithArrowPositionFixture . nativeElement . querySelector (
449
+ '#defaultA .mat-sort-header-container' ,
450
+ ) ;
451
+ const containerB = matSortWithArrowPositionFixture . nativeElement . querySelector (
452
+ '#defaultB .mat-sort-header-container' ,
453
+ ) ;
454
+
455
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
456
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
457
+ } ) ;
458
+
459
+ it ( 'should render arrows before if appropriate parameter passed' , ( ) => {
460
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
461
+ const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture . componentInstance ;
462
+ matSortWithArrowPositionComponent . arrowPosition = 'before' ;
463
+
464
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
465
+
466
+ const containerA = matSortWithArrowPositionFixture . nativeElement . querySelector (
467
+ '#defaultA .mat-sort-header-container' ,
468
+ ) ;
469
+ const containerB = matSortWithArrowPositionFixture . nativeElement . querySelector (
470
+ '#defaultB .mat-sort-header-container' ,
471
+ ) ;
472
+
473
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
474
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
475
+ } ) ;
476
+
477
+ it ( 'should render arrows in proper position based on arrowPosition parameter' , ( ) => {
478
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
479
+ const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture . componentInstance ;
480
+
481
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
482
+
483
+ const containerA = matSortWithArrowPositionFixture . nativeElement . querySelector (
484
+ '#defaultA .mat-sort-header-container' ,
485
+ ) ;
486
+ const containerB = matSortWithArrowPositionFixture . nativeElement . querySelector (
487
+ '#defaultB .mat-sort-header-container' ,
488
+ ) ;
489
+
490
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
491
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
492
+
493
+ matSortWithArrowPositionComponent . arrowPosition = 'before' ;
494
+
495
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
496
+
497
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
498
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
499
+ } ) ;
442
500
} ) ;
443
501
444
502
describe ( 'with default options' , ( ) => {
@@ -477,6 +535,45 @@ describe('MatSort', () => {
477
535
testSingleColumnSortDirectionSequence ( fixture , [ 'desc' , 'asc' ] ) ;
478
536
} ) ;
479
537
} ) ;
538
+
539
+ describe ( 'with default arrowPosition' , ( ) => {
540
+ let fixture : ComponentFixture < MatSortWithoutInputs > ;
541
+
542
+ beforeEach (
543
+ waitForAsync ( ( ) => {
544
+ TestBed . configureTestingModule ( {
545
+ imports : [ MatSortModule , MatTableModule , CdkTableModule , NoopAnimationsModule ] ,
546
+ declarations : [ MatSortWithoutInputs ] ,
547
+ providers : [
548
+ {
549
+ provide : MAT_SORT_DEFAULT_OPTIONS ,
550
+ useValue : {
551
+ disableClear : true ,
552
+ arrowPosition : 'before' ,
553
+ } ,
554
+ } ,
555
+ ] ,
556
+ } ) . compileComponents ( ) ;
557
+ } ) ,
558
+ ) ;
559
+
560
+ beforeEach ( ( ) => {
561
+ fixture = TestBed . createComponent ( MatSortWithoutInputs ) ;
562
+ fixture . detectChanges ( ) ;
563
+ } ) ;
564
+
565
+ it ( 'should render arrows in proper position' , ( ) => {
566
+ const containerA = fixture . nativeElement . querySelector (
567
+ '#defaultA .mat-sort-header-container' ,
568
+ ) ;
569
+ const containerB = fixture . nativeElement . querySelector (
570
+ '#defaultB .mat-sort-header-container' ,
571
+ ) ;
572
+
573
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
574
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
575
+ } ) ;
576
+ } ) ;
480
577
} ) ;
481
578
482
579
/**
@@ -736,3 +833,40 @@ class MatSortWithoutExplicitInputs {
736
833
dispatchMouseEvent ( sortElement , event ) ;
737
834
}
738
835
}
836
+
837
+ @Component ( {
838
+ template : `
839
+ <div matSort>
840
+ <div id="defaultA" #defaultA mat-sort-header="defaultA" [arrowPosition]="arrowPosition">
841
+ A
842
+ </div>
843
+ <div id="defaultB" #defaultB mat-sort-header="defaultB" [arrowPosition]="arrowPosition">
844
+ B
845
+ </div>
846
+ </div>
847
+ ` ,
848
+ } )
849
+ class MatSortWithArrowPosition {
850
+ arrowPosition ?: 'before' | 'after' ;
851
+ @ViewChild ( MatSort ) matSort : MatSort ;
852
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
853
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
854
+ }
855
+
856
+ @Component ( {
857
+ template : `
858
+ <div matSort>
859
+ <div id="defaultA" #defaultA mat-sort-header="defaultA">
860
+ A
861
+ </div>
862
+ <div id="defaultB" #defaultB mat-sort-header="defaultB">
863
+ B
864
+ </div>
865
+ </div>
866
+ ` ,
867
+ } )
868
+ class MatSortWithoutInputs {
869
+ @ViewChild ( MatSort ) matSort : MatSort ;
870
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
871
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
872
+ }
0 commit comments