@@ -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,67 @@ describe('MatSort', () => {
449
500
testSingleColumnSortDirectionSequence ( fixture , [ 'desc' , 'asc' ] ) ;
450
501
} ) ;
451
502
} ) ;
503
+
504
+ describe ( 'with default arrowPosition' , ( ) => {
505
+ let fixture : ComponentFixture < MatSortWithArrowPosition > ;
506
+ let component : MatSortWithArrowPosition ;
507
+
508
+ beforeEach ( waitForAsync ( ( ) => {
509
+ TestBed . configureTestingModule ( {
510
+ imports : [ MatSortModule , MatTableModule , CdkTableModule , NoopAnimationsModule ] ,
511
+ declarations : [
512
+ MatSortWithArrowPosition ,
513
+ MatSortWithoutInputs
514
+ ] ,
515
+ providers : [
516
+ {
517
+ provide : MAT_SORT_DEFAULT_OPTIONS ,
518
+ useValue : {
519
+ disableClear : true ,
520
+ arrowPosition : 'before'
521
+ } ,
522
+ }
523
+ ] ,
524
+ } ) . compileComponents ( ) ;
525
+ } ) ) ;
526
+
527
+ beforeEach ( ( ) => {
528
+ fixture = TestBed . createComponent ( MatSortWithArrowPosition ) ;
529
+ component = fixture . componentInstance ;
530
+ fixture . detectChanges ( ) ;
531
+ } ) ;
532
+
533
+ it ( 'should render arrows in proper position based on arrowPosition parameter' , ( ) => {
534
+ const containerA = fixture . nativeElement
535
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
536
+ const containerB = fixture . nativeElement
537
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
538
+
539
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
540
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
541
+
542
+ component . arrowPosition = 'after' ;
543
+
544
+ fixture . detectChanges ( ) ;
545
+
546
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
547
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( false ) ;
548
+ } ) ;
549
+
550
+ it ( 'should render arrows in proper position' , ( ) => {
551
+ const matSortWithoutInputsFixture = TestBed . createComponent ( MatSortWithoutInputs ) ;
552
+
553
+ matSortWithoutInputsFixture . detectChanges ( ) ;
554
+
555
+ const containerA = matSortWithoutInputsFixture . nativeElement
556
+ . querySelector ( '#defaultA .mat-sort-header-container' ) ;
557
+ const containerB = matSortWithoutInputsFixture . nativeElement
558
+ . querySelector ( '#defaultB .mat-sort-header-container' ) ;
559
+
560
+ expect ( containerA . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
561
+ expect ( containerB . classList . contains ( 'mat-sort-header-position-before' ) ) . toBe ( true ) ;
562
+ } ) ;
563
+ } ) ;
452
564
} ) ;
453
565
454
566
/**
@@ -709,3 +821,40 @@ class MatSortWithoutExplicitInputs {
709
821
dispatchMouseEvent ( sortElement , event ) ;
710
822
}
711
823
}
824
+
825
+ @Component ( {
826
+ template : `
827
+ <div matSort>
828
+ <div id="defaultA" #defaultA mat-sort-header="defaultA" [arrowPosition]="arrowPosition">
829
+ A
830
+ </div>
831
+ <div id="defaultB" #defaultB mat-sort-header="defaultB" [arrowPosition]="arrowPosition">
832
+ B
833
+ </div>
834
+ </div>
835
+ `
836
+ } )
837
+ class MatSortWithArrowPosition {
838
+ arrowPosition ?: 'before' | 'after' ;
839
+ @ViewChild ( MatSort ) matSort : MatSort ;
840
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
841
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
842
+ }
843
+
844
+ @Component ( {
845
+ template : `
846
+ <div matSort>
847
+ <div id="defaultA" #defaultA mat-sort-header="defaultA">
848
+ A
849
+ </div>
850
+ <div id="defaultB" #defaultB mat-sort-header="defaultB">
851
+ B
852
+ </div>
853
+ </div>
854
+ `
855
+ } )
856
+ class MatSortWithoutInputs {
857
+ @ViewChild ( MatSort ) matSort : MatSort ;
858
+ @ViewChild ( 'defaultA' ) defaultA : MatSortHeader ;
859
+ @ViewChild ( 'defaultB' ) defaultB : MatSortHeader ;
860
+ }
0 commit comments