@@ -33,6 +33,7 @@ import {HeaderCellComponent} from './header_cell_component';
33
33
[header]="header"
34
34
[sortingInfo]="sortingInfo"
35
35
[hparamsEnabled]="hparamsEnabled"
36
+ [controlsEnabled]="controlsEnabled"
36
37
(headerClicked)="headerClicked($event)"
37
38
(deleteButtonClicked)="deleteButtonClicked($event)"
38
39
></tb-data-table-header-cell>
@@ -44,7 +45,8 @@ class TestableComponent {
44
45
45
46
@Input() header!: ColumnHeader;
46
47
@Input() sortingInfo!: SortingInfo;
47
- @Input() hparamsEnabled?: boolean;
48
+ @Input() hparamsEnabled!: boolean;
49
+ @Input() controlsEnabled!: boolean;
48
50
49
51
@Input() headerClicked!: (sortingInfo: SortingInfo) => void;
50
52
@Input() deleteButtonClicked!: (header: ColumnHeader) => void;
@@ -63,6 +65,8 @@ describe('header cell', () => {
63
65
function createComponent(input: {
64
66
header?: ColumnHeader;
65
67
sortingInfo?: SortingInfo;
68
+ hparamsEnabled?: boolean;
69
+ controlsEnabled?: boolean;
66
70
}): ComponentFixture<TestableComponent> {
67
71
const fixture = TestBed.createComponent(TestableComponent);
68
72
@@ -76,26 +80,27 @@ describe('header cell', () => {
76
80
name: 'run',
77
81
order: SortingOrder.ASCENDING,
78
82
};
83
+ fixture.componentInstance.hparamsEnabled = input.hparamsEnabled ?? true;
84
+ fixture.componentInstance.controlsEnabled = input.controlsEnabled ?? true;
79
85
80
86
headerClickedSpy = jasmine.createSpy();
81
87
fixture.componentInstance.headerClicked = headerClickedSpy;
82
88
83
89
deleteButtonClickedSpy = jasmine.createSpy();
84
90
fixture.componentInstance.deleteButtonClicked = deleteButtonClickedSpy;
85
91
92
+ fixture.detectChanges();
86
93
return fixture;
87
94
}
88
95
89
96
it('renders', () => {
90
97
const fixture = createComponent({});
91
- fixture.detectChanges();
92
98
const cell = fixture.debugElement.query(By.css('.cell'));
93
99
expect(cell).toBeTruthy();
94
100
});
95
101
96
102
it('emits headerClicked event when cell element is clicked', () => {
97
103
const fixture = createComponent({});
98
- fixture.detectChanges();
99
104
fixture.debugElement
100
105
.query(By.directive(HeaderCellComponent))
101
106
.componentInstance.headerClicked.subscribe();
@@ -104,14 +109,8 @@ describe('header cell', () => {
104
109
});
105
110
106
111
describe('delete column button', () => {
107
- let fixture: ComponentFixture<TestableComponent>;
108
- beforeEach(() => {
109
- fixture = createComponent({});
110
- fixture.componentInstance.hparamsEnabled = true;
111
- fixture.detectChanges();
112
- });
113
-
114
112
it('emits removeColumn event when delete button clicked', () => {
113
+ const fixture = createComponent({hparamsEnabled: true});
115
114
fixture.debugElement
116
115
.query(By.directive(HeaderCellComponent))
117
116
.componentInstance.deleteButtonClicked.subscribe();
@@ -128,14 +127,91 @@ describe('header cell', () => {
128
127
});
129
128
130
129
it('renders delete button when hparamsEnabled is true', () => {
130
+ const fixture = createComponent({hparamsEnabled: true});
131
+
131
132
expect(fixture.debugElement.query(By.css('.delete-icon'))).toBeTruthy();
132
133
});
133
134
134
135
it('does not render delete button when hparamsEnabled is false', () => {
135
- fixture.componentInstance.hparamsEnabled = false;
136
- fixture.detectChanges();
136
+ const fixture = createComponent({hparamsEnabled: false});
137
137
138
138
expect(fixture.debugElement.query(By.css('.delete-icon'))).toBeFalsy();
139
139
});
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
+ });
140
216
});
141
217
});
0 commit comments