@@ -33,6 +33,7 @@ import {HeaderCellComponent} from './header_cell_component';
3333 [header]="header"
3434 [sortingInfo]="sortingInfo"
3535 [hparamsEnabled]="hparamsEnabled"
36+ [controlsEnabled]="controlsEnabled"
3637 (headerClicked)="headerClicked($event)"
3738 (deleteButtonClicked)="deleteButtonClicked($event)"
3839 ></tb-data-table-header-cell>
@@ -44,7 +45,8 @@ class TestableComponent {
4445
4546 @Input ( ) header ! : ColumnHeader ;
4647 @Input ( ) sortingInfo ! : SortingInfo ;
47- @Input ( ) hparamsEnabled ?: boolean ;
48+ @Input ( ) hparamsEnabled ! : boolean ;
49+ @Input ( ) controlsEnabled ! : boolean ;
4850
4951 @Input ( ) headerClicked ! : ( sortingInfo : SortingInfo ) => void ;
5052 @Input ( ) deleteButtonClicked ! : ( header : ColumnHeader ) => void ;
@@ -63,6 +65,8 @@ describe('header cell', () => {
6365 function createComponent ( input : {
6466 header ?: ColumnHeader ;
6567 sortingInfo ?: SortingInfo ;
68+ hparamsEnabled ?: boolean ;
69+ controlsEnabled ?: boolean ;
6670 } ) : ComponentFixture < TestableComponent > {
6771 const fixture = TestBed . createComponent ( TestableComponent ) ;
6872
@@ -76,26 +80,27 @@ describe('header cell', () => {
7680 name : 'run' ,
7781 order : SortingOrder . ASCENDING ,
7882 } ;
83+ fixture . componentInstance . hparamsEnabled = input . hparamsEnabled ?? true ;
84+ fixture . componentInstance . controlsEnabled = input . controlsEnabled ?? true ;
7985
8086 headerClickedSpy = jasmine . createSpy ( ) ;
8187 fixture . componentInstance . headerClicked = headerClickedSpy ;
8288
8389 deleteButtonClickedSpy = jasmine . createSpy ( ) ;
8490 fixture . componentInstance . deleteButtonClicked = deleteButtonClickedSpy ;
8591
92+ fixture . detectChanges ( ) ;
8693 return fixture ;
8794 }
8895
8996 it ( 'renders' , ( ) => {
9097 const fixture = createComponent ( { } ) ;
91- fixture . detectChanges ( ) ;
9298 const cell = fixture . debugElement . query ( By . css ( '.cell' ) ) ;
9399 expect ( cell ) . toBeTruthy ( ) ;
94100 } ) ;
95101
96102 it ( 'emits headerClicked event when cell element is clicked' , ( ) => {
97103 const fixture = createComponent ( { } ) ;
98- fixture . detectChanges ( ) ;
99104 fixture . debugElement
100105 . query ( By . directive ( HeaderCellComponent ) )
101106 . componentInstance . headerClicked . subscribe ( ) ;
@@ -104,14 +109,8 @@ describe('header cell', () => {
104109 } ) ;
105110
106111 describe ( 'delete column button' , ( ) => {
107- let fixture : ComponentFixture < TestableComponent > ;
108- beforeEach ( ( ) => {
109- fixture = createComponent ( { } ) ;
110- fixture . componentInstance . hparamsEnabled = true ;
111- fixture . detectChanges ( ) ;
112- } ) ;
113-
114112 it ( 'emits removeColumn event when delete button clicked' , ( ) => {
113+ const fixture = createComponent ( { hparamsEnabled : true } ) ;
115114 fixture . debugElement
116115 . query ( By . directive ( HeaderCellComponent ) )
117116 . componentInstance . deleteButtonClicked . subscribe ( ) ;
@@ -128,14 +127,91 @@ describe('header cell', () => {
128127 } ) ;
129128
130129 it ( 'renders delete button when hparamsEnabled is true' , ( ) => {
130+ const fixture = createComponent ( { hparamsEnabled : true } ) ;
131+
131132 expect ( fixture . debugElement . query ( By . css ( '.delete-icon' ) ) ) . toBeTruthy ( ) ;
132133 } ) ;
133134
134135 it ( 'does not render delete button when hparamsEnabled is false' , ( ) => {
135- fixture . componentInstance . hparamsEnabled = false ;
136- fixture . detectChanges ( ) ;
136+ const fixture = createComponent ( { hparamsEnabled : false } ) ;
137137
138138 expect ( fixture . debugElement . query ( By . css ( '.delete-icon' ) ) ) . toBeFalsy ( ) ;
139139 } ) ;
140+
141+ it ( 'does not render delete button when controlsEnabled is false' , ( ) => {
142+ const fixture = createComponent ( { controlsEnabled : false } ) ;
143+
144+ expect ( fixture . debugElement . query ( By . css ( '.delete-icon' ) ) ) . toBeFalsy ( ) ;
145+ } ) ;
146+ } ) ;
147+
148+ describe ( 'sorting icon' , ( ) => {
149+ it ( 'shows sorting icon when sortingInfo matches header' , ( ) => {
150+ const fixture = createComponent ( {
151+ sortingInfo : {
152+ name : 'run' ,
153+ order : SortingOrder . ASCENDING ,
154+ } ,
155+ } ) ;
156+
157+ expect (
158+ fixture . debugElement
159+ . query ( By . css ( '.sorting-icon-container mat-icon' ) )
160+ . nativeElement . classList . contains ( 'show' )
161+ ) . toBe ( true ) ;
162+ } ) ;
163+
164+ it ( 'does not render sorting icon when sortingInfo does not match header' , ( ) => {
165+ const fixture = createComponent ( {
166+ sortingInfo : {
167+ name : 'not-this-header' ,
168+ order : SortingOrder . ASCENDING ,
169+ } ,
170+ } ) ;
171+
172+ expect (
173+ fixture . debugElement
174+ . query ( By . css ( '.sorting-icon-container mat-icon' ) )
175+ . nativeElement . classList . contains ( 'show' )
176+ ) . toBe ( false ) ;
177+ } ) ;
178+
179+ it ( 'renders downward arrow if order is DESCENDING' , ( ) => {
180+ const fixture = createComponent ( {
181+ sortingInfo : {
182+ name : 'run' ,
183+ order : SortingOrder . DESCENDING ,
184+ } ,
185+ } ) ;
186+
187+ expect (
188+ fixture . debugElement
189+ . query ( By . css ( '.sorting-icon-container mat-icon' ) )
190+ . nativeElement . getAttribute ( 'svgIcon' )
191+ ) . toBe ( 'arrow_downward_24px' ) ;
192+ } ) ;
193+
194+ it ( 'renders downward arrow if order is DESCENDING' , ( ) => {
195+ const fixture = createComponent ( {
196+ sortingInfo : {
197+ name : 'run' ,
198+ order : SortingOrder . ASCENDING ,
199+ } ,
200+ } ) ;
201+
202+ expect (
203+ fixture . debugElement
204+ . query ( By . css ( '.sorting-icon-container mat-icon' ) )
205+ . nativeElement . getAttribute ( 'svgIcon' )
206+ ) . toBe ( 'arrow_upward_24px' ) ;
207+ } ) ;
208+
209+ it ( 'does not render sorting icon when controlsEnabled is false' , ( ) => {
210+ const fixture = createComponent ( { controlsEnabled : false } ) ;
211+
212+ expect (
213+ fixture . debugElement . query ( By . css ( '.sorting-icon-container mat-icon' ) )
214+ ) . toBeFalsy ( ) ;
215+ } ) ;
140216 } ) ;
141217} ) ;
0 commit comments