|
9 | 9 | Type,
|
10 | 10 | ViewChild,
|
11 | 11 | AfterViewInit,
|
| 12 | + ChangeDetectionStrategy, |
12 | 13 | } from '@angular/core';
|
13 | 14 | import {ComponentFixture, fakeAsync, flush, flushMicrotasks, TestBed} from '@angular/core/testing';
|
14 | 15 | import {BehaviorSubject, combineLatest, Observable, of as observableOf} from 'rxjs';
|
@@ -1913,6 +1914,20 @@ describe('CdkTable', () => {
|
1913 | 1914 | expect(cellElement.classList.contains('custom-cell-class-even')).toBe(true);
|
1914 | 1915 | expect(cellElement.classList.contains('custom-cell-class-odd')).toBe(false);
|
1915 | 1916 | });
|
| 1917 | + |
| 1918 | + it('should be able to show a message when no data is being displayed in the strategy ChangeDetectionOnPush', () => { |
| 1919 | + setupTableTestApp(WrapNativeHtmlTableAppOnPush, [NativeHtmlTableAppOnPush]); |
| 1920 | + |
| 1921 | + expect(tableElement.querySelector('.cdk-no-data-row')).toBeFalsy(); |
| 1922 | + |
| 1923 | + component.dataSource.data = []; |
| 1924 | + |
| 1925 | + fixture.detectChanges(); |
| 1926 | + |
| 1927 | + const noDataRow = tableElement.querySelector('.cdk-no-data-row')!; |
| 1928 | + expect(noDataRow).toBeTruthy(); |
| 1929 | + expect(noDataRow.getAttribute('colspan')).toEqual('3'); |
| 1930 | + }); |
1916 | 1931 | });
|
1917 | 1932 |
|
1918 | 1933 | interface TestData {
|
@@ -3011,6 +3026,48 @@ class TableWithIndirectDescendantDefs {
|
3011 | 3026 | dataSource = new FakeDataSource();
|
3012 | 3027 | }
|
3013 | 3028 |
|
| 3029 | +@Component({ |
| 3030 | + selector: 'cdk-table-change-detection-on-push', |
| 3031 | + template: ` |
| 3032 | + <table cdk-table [dataSource]="dataSource"> |
| 3033 | + <ng-container cdkColumnDef="column_a"> |
| 3034 | + <th cdk-header-cell *cdkHeaderCellDef> Column A</th> |
| 3035 | + <td cdk-cell *cdkCellDef="let row"> {{row.a}}</td> |
| 3036 | + </ng-container> |
| 3037 | +
|
| 3038 | + <ng-container cdkColumnDef="column_b"> |
| 3039 | + <th cdk-header-cell *cdkHeaderCellDef> Column B</th> |
| 3040 | + <td cdk-cell *cdkCellDef="let row"> {{row.b}}</td> |
| 3041 | + </ng-container> |
| 3042 | +
|
| 3043 | + <ng-container cdkColumnDef="column_c"> |
| 3044 | + <th cdk-header-cell *cdkHeaderCellDef> Column C</th> |
| 3045 | + <td cdk-cell *cdkCellDef="let row"> {{row.c}}</td> |
| 3046 | + </ng-container> |
| 3047 | +
|
| 3048 | + <tr cdk-header-row *cdkHeaderRowDef="columnsToRender"></tr> |
| 3049 | + <tr cdk-row *cdkRowDef="let row; columns: columnsToRender" class="customRowClass"></tr> |
| 3050 | + <tr *cdkNoDataRow [attr.colspan]="columnsToRender.length"> |
| 3051 | + <td>No data</td> |
| 3052 | + </tr> |
| 3053 | + </table> |
| 3054 | + `, |
| 3055 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 3056 | +}) |
| 3057 | +class NativeHtmlTableAppOnPush { |
| 3058 | + @Input() dataSource: Observable<TestData[]> | null = null; |
| 3059 | + columnsToRender = ['column_a', 'column_b', 'column_c']; |
| 3060 | +} |
| 3061 | + |
| 3062 | +@Component({ |
| 3063 | + template: ` |
| 3064 | + <cdk-table-change-detection-on-push [dataSource]="dataSource"></cdk-table-change-detection-on-push> |
| 3065 | + `, |
| 3066 | +}) |
| 3067 | +class WrapNativeHtmlTableAppOnPush { |
| 3068 | + dataSource: FakeDataSource = new FakeDataSource(); |
| 3069 | +} |
| 3070 | + |
3014 | 3071 | function getElements(element: Element, query: string): HTMLElement[] {
|
3015 | 3072 | return [].slice.call(element.querySelectorAll(query));
|
3016 | 3073 | }
|
|
0 commit comments