[ACS-9106] Make the descendants false iin data column component (#12077)

* [ACS-9106] Make the descendants false iin data column component

* [ACS-9106] Add unit test

* [ACS-9106] Fix formatting

* [ACS-9106] Remove the declaration of fixture outside it
This commit is contained in:
Shivangi Shree
2026-07-24 12:25:19 +05:30
committed by GitHub
parent 40a0a67583
commit a1ee4e0d48
2 changed files with 48 additions and 2 deletions
@@ -15,9 +15,39 @@
* limitations under the License.
*/
import { Component, ViewChild } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { DataColumnComponent } from './data-column.component';
describe('DataColumnListComponent', () => {
@Component({
imports: [DataColumnComponent],
template: `
<data-column key="name">
<ng-template />
</data-column>
`
})
class DirectTemplateHostComponent {
@ViewChild(DataColumnComponent)
dataColumn: DataColumnComponent;
}
@Component({
imports: [DataColumnComponent],
template: `
<data-column key="name">
<div>
<ng-template />
</div>
</data-column>
`
})
class NestedTemplateHostComponent {
@ViewChild(DataColumnComponent)
dataColumn: DataColumnComponent;
}
describe('DataColumnComponent', () => {
it('should setup screen reader title for thumbnails', () => {
const component = new DataColumnComponent();
component.key = '$thumbnail';
@@ -25,4 +55,20 @@ describe('DataColumnListComponent', () => {
component.ngOnInit();
expect(component.srTitle).toBeTruthy();
});
describe('template ContentChild selection', () => {
it('should capture a direct ng-template child', () => {
const directFixture = TestBed.createComponent(DirectTemplateHostComponent);
directFixture.detectChanges();
expect(directFixture.componentInstance.dataColumn.template).toBeTruthy();
});
it('should not capture a nested descendant ng-template', () => {
const nestedFixture = TestBed.createComponent(NestedTemplateHostComponent);
nestedFixture.detectChanges();
expect(nestedFixture.componentInstance.dataColumn.template).toBeFalsy();
});
});
});
@@ -78,7 +78,7 @@ export class DataColumnComponent implements OnInit {
@Input()
subtitle: string = '';
@ContentChild(TemplateRef)
@ContentChild(TemplateRef, { descendants: false })
template: any;
/** Custom tooltip formatter function. */