@@ -30,9 +30,9 @@ import {
30
30
31
31
32
32
describe ( 'MatSort' , ( ) => {
33
- describe ( 'without default options' , ( ) => {
34
- let fixture : ComponentFixture < SimpleMatSortApp > ;
35
- let component : SimpleMatSortApp ;
33
+ describe ( 'without default options' , ( ) => {
34
+ let fixture : ComponentFixture < SimpleMatSortApp > ;
35
+ let component : SimpleMatSortApp ;
36
36
37
37
beforeEach ( waitForAsync ( ( ) => {
38
38
TestBed . configureTestingModule ( {
@@ -44,7 +44,8 @@ describe('MatSort', () => {
44
44
MatSortHeaderMissingMatSortApp ,
45
45
MatSortDuplicateMatSortableIdsApp ,
46
46
MatSortableMissingIdApp ,
47
- MatSortableInvalidDirection
47
+ MatSortableInvalidDirection ,
48
+ MatSortWithArrowPosition
48
49
] ,
49
50
} ) . compileComponents ( ) ;
50
51
} ) ) ;
@@ -77,7 +78,6 @@ describe('MatSort', () => {
77
78
const cdkTableMatSortAppFixture = TestBed . createComponent ( CdkTableMatSortApp ) ;
78
79
const cdkTableMatSortAppComponent = cdkTableMatSortAppFixture . componentInstance ;
79
80
80
- cdkTableMatSortAppFixture . detectChanges ( ) ;
81
81
cdkTableMatSortAppFixture . detectChanges ( ) ;
82
82
83
83
const sortables = cdkTableMatSortAppComponent . matSort . sortables ;
@@ -91,7 +91,6 @@ describe('MatSort', () => {
91
91
const matTableMatSortAppFixture = TestBed . createComponent ( MatTableMatSortApp ) ;
92
92
const matTableMatSortAppComponent = matTableMatSortAppFixture . componentInstance ;
93
93
94
- matTableMatSortAppFixture . detectChanges ( ) ;
95
94
matTableMatSortAppFixture . detectChanges ( ) ;
96
95
97
96
const sortables = matTableMatSortAppComponent . matSort . sortables ;
@@ -411,6 +410,58 @@ describe('MatSort', () => {
411
410
412
411
expect ( container . classList . contains ( 'mat-focus-indicator' ) ) . toBe ( true ) ;
413
412
} ) ;
413
+
414
+ it ( 'should render arrows after sort header by default' , ( ) => {
415
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
416
+
417
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
418
+
419
+ const containerA = matSortWithArrowPositionFixture . nativeElement
420
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
421
+ const containerB = matSortWithArrowPositionFixture . nativeElement
422
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
423
+
424
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
425
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
426
+ } ) ;
427
+
428
+ it ( 'should render arrows before if appropriate parameter passed' , ( ) => {
429
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
430
+ const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture . componentInstance ;
431
+ matSortWithArrowPositionComponent . arrowPosition = 'before' ;
432
+
433
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
434
+
435
+ const containerA = matSortWithArrowPositionFixture . nativeElement
436
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
437
+ const containerB = matSortWithArrowPositionFixture . nativeElement
438
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
439
+
440
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
441
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
442
+ } ) ;
443
+
444
+ it ( 'should render arrows in proper position based on arrowPosition parameter' , ( ) => {
445
+ const matSortWithArrowPositionFixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
446
+ const matSortWithArrowPositionComponent = matSortWithArrowPositionFixture . componentInstance ;
447
+
448
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
449
+
450
+ const containerA = matSortWithArrowPositionFixture . nativeElement
451
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
452
+ const containerB = matSortWithArrowPositionFixture . nativeElement
453
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
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
+ matSortWithArrowPositionComponent . arrowPosition = 'before' ;
459
+
460
+ matSortWithArrowPositionFixture . detectChanges ( ) ;
461
+
462
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
463
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
464
+ } ) ;
414
465
} ) ;
415
466
416
467
describe ( 'with default options' , ( ) => {
@@ -449,6 +500,43 @@ describe('MatSort', () => {
449
500
testSingleColumnSortDirectionSequence ( fixture , [ 'desc' , 'asc' ] ) ;
450
501
} ) ;
451
502
} ) ;
503
+
504
+ describe ( 'with default arrowPosition' , ( ) => {
505
+ let fixture : ComponentFixture < MatSortWithoutInputs > ;
506
+
507
+ beforeEach ( waitForAsync ( ( ) => {
508
+ TestBed . configureTestingModule ( {
509
+ imports : [ MatSortModule , MatTableModule , CdkTableModule , NoopAnimationsModule ] ,
510
+ declarations : [
511
+ MatSortWithoutInputs
512
+ ] ,
513
+ providers : [
514
+ {
515
+ provide : MAT_SORT_DEFAULT_OPTIONS ,
516
+ useValue : {
517
+ disableClear : true ,
518
+ arrowPosition : 'before'
519
+ } ,
520
+ }
521
+ ] ,
522
+ } ) . compileComponents ( ) ;
523
+ } ) ) ;
524
+
525
+ beforeEach ( ( ) => {
526
+ fixture = TestBed . createComponent ( MatSortWithoutInputs ) ;
527
+ fixture . detectChanges ( ) ;
528
+ } ) ;
529
+
530
+ it ( 'should render arrows in proper position' , ( ) => {
531
+ const containerA = fixture . nativeElement
532
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
533
+ const containerB = fixture . nativeElement
534
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
535
+
536
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
537
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
538
+ } ) ;
539
+ } ) ;
452
540
} ) ;
453
541
454
542
/**
@@ -709,3 +797,40 @@ class MatSortWithoutExplicitInputs {
709
797
dispatchMouseEvent ( sortElement , event ) ;
710
798
}
711
799
}
800
+
801
+ @Component ( {
802
+ template : `
803
+ <div matSort>
804
+ <div id="defaultA" #defaultA mat-sort-header="defaultA" [arrowPosition]="arrowPosition">
805
+ A
806
+ </div>
807
+ <div id="defaultB" #defaultB mat-sort-header="defaultB" [arrowPosition]="arrowPosition">
808
+ B
809
+ </div>
810
+ </div>
811
+ `
812
+ } )
813
+ class MatSortWithArrowPosition {
814
+ arrowPosition ?: 'before' | 'after' ;
815
+ @ViewChild ( MatSort ) matSort : MatSort ;
816
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
817
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
818
+ }
819
+
820
+ @Component ( {
821
+ template : `
822
+ <div matSort>
823
+ <div id="defaultA" #defaultA mat-sort-header="defaultA">
824
+ A
825
+ </div>
826
+ <div id="defaultB" #defaultB mat-sort-header="defaultB">
827
+ B
828
+ </div>
829
+ </div>
830
+ `
831
+ } )
832
+ class MatSortWithoutInputs {
833
+ @ViewChild ( MatSort ) matSort : MatSort ;
834
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
835
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
836
+ }
0 commit comments