Skip to content

Commit 58d694a

Browse files
committed
test(multiple): fix aot compilation errors in tests (#33389)
Fixes some ahead-of-time compilation errors in tests that show up when we update to the latest `next` version of Angular. (cherry picked from commit 42331fc)
1 parent 2995797 commit 58d694a

5 files changed

Lines changed: 38 additions & 33 deletions

File tree

src/cdk/drag-drop/directives/drop-list-shared.spec.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,7 +4999,7 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
49994999
<div
50005000
class="drop-list scroll-container"
50015001
cdkDropList
5002-
cdkDropListOrientation="${listOrientation}"
5002+
[cdkDropListOrientation]="_listOrientation"
50035003
[cdkDropListData]="items"
50045004
(cdkDropListDropped)="droppedSpy($event)">
50055005
@for (item of items; track item) {
@@ -5021,6 +5021,7 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
50215021
})
50225022
class DraggableInHorizontalDropZone implements AfterViewInit {
50235023
readonly _elementRef = inject(ElementRef);
5024+
readonly _listOrientation = listOrientation;
50245025

50255026
@ViewChildren(CdkDrag) dragItems!: QueryList<CdkDrag>;
50265027
@ViewChild(CdkDropList) dropInstance!: CdkDropList;
@@ -5088,7 +5089,7 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
50885089
}
50895090
`,
50905091
template: `
5091-
<div class="list" cdkDropList cdkDropListOrientation="${listOrientation}">
5092+
<div class="list" cdkDropList [cdkDropListOrientation]="_listOrientation">
50925093
@for (item of items; track item) {
50935094
<div class="item" cdkDrag>
50945095
{{item}}
@@ -5103,6 +5104,8 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
51035104
changeDetection: ChangeDetectionStrategy.Eager,
51045105
})
51055106
class DraggableInHorizontalFlexDropZoneWithMatchSizePreview {
5107+
readonly _listOrientation = listOrientation;
5108+
51065109
@ViewChildren(CdkDrag) dragItems!: QueryList<CdkDrag>;
51075110
items = ['Zero', 'One', 'Two'];
51085111
}
@@ -5170,7 +5173,7 @@ export class DraggableInDropZone implements AfterViewInit {
51705173
startedSpy = jasmine.createSpy('started spy');
51715174
previewContainer: PreviewContainer = 'global';
51725175
dropDisabled = signal(false);
5173-
dropLockAxis = signal<DragAxis | undefined>(undefined);
5176+
dropLockAxis = signal<DragAxis | null>(null);
51745177
scale = 1;
51755178

51765179
ngAfterViewInit() {
@@ -5326,31 +5329,27 @@ class DraggableInDropZoneWithContainer extends DraggableInDropZone {}
53265329
class DraggableInDropZoneWithCustomPreview {
53275330
@ViewChild(CdkDropList) dropInstance!: CdkDropList;
53285331
@ViewChildren(CdkDrag) dragItems!: QueryList<CdkDrag>;
5329-
items: {label: string; lockAxis?: DragAxis}[] = [
5330-
{label: 'Zero'},
5331-
{label: 'One'},
5332-
{label: 'Two'},
5333-
{label: 'Three'},
5332+
items: {label: string; lockAxis: DragAxis | null}[] = [
5333+
{label: 'Zero', lockAxis: null},
5334+
{label: 'One', lockAxis: null},
5335+
{label: 'Two', lockAxis: null},
5336+
{label: 'Three', lockAxis: null},
53345337
];
53355338
boundarySelector!: string;
53365339
renderCustomPreview = true;
53375340
matchPreviewSize = false;
53385341
previewClass: string | string[] = [];
53395342
constrainPosition: ((point: Point) => Point) | undefined;
5340-
dropLockAxis = signal<DragAxis | undefined>(undefined);
5343+
dropLockAxis = signal<DragAxis | null>(null);
53415344
}
53425345

53435346
@Component({
53445347
template: `
53455348
<div cdkDropList style="width: 100px; background: pink;">
53465349
@for (item of items; track item) {
5347-
<div
5348-
cdkDrag
5349-
[cdkDragConstrainPosition]="constrainPosition"
5350-
[cdkDragBoundary]="boundarySelector"
5351-
style="width: 100%; height: ${ITEM_HEIGHT}px; background: red;">
5352-
{{item}}
5353-
<ng-template cdkDragPreview>Hello {{item}}</ng-template>
5350+
<div cdkDrag style="width: 100%; height: ${ITEM_HEIGHT}px; background: red;">
5351+
{{item}}
5352+
<ng-template cdkDragPreview>Hello {{item}}</ng-template>
53545353
</div>
53555354
}
53565355
</div>
@@ -5924,10 +5923,7 @@ class NestedDragsComponent {
59245923
imports: [CdkDrag, NgTemplateOutlet],
59255924
changeDetection: ChangeDetectionStrategy.Eager,
59265925
})
5927-
class NestedDragsThroughTemplate {
5928-
@ViewChild('container') container!: ElementRef;
5929-
@ViewChild('item') item!: ElementRef;
5930-
}
5926+
class NestedDragsThroughTemplate extends NestedDragsComponent {}
59315927

59325928
@Component({
59335929
styles: `

src/cdk/drag-drop/directives/standalone-drag.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import {_supportsShadowDom} from '../../platform';
2222
import {CdkDragHandle} from './drag-handle';
2323
import {CdkDrag} from './drag';
24-
import {CDK_DRAG_CONFIG, DragAxis, DragDropConfig} from './config';
24+
import {CDK_DRAG_CONFIG, DragAxis, DragDropConfig, DragStartDelay} from './config';
2525
import {DragRef, Point} from '../drag-ref';
2626
import {
2727
createComponent,
@@ -1337,7 +1337,7 @@ describe('Standalone CdkDrag', () => {
13371337
let currentTime = 0;
13381338

13391339
const fixture = createComponent(StandaloneDraggable);
1340-
fixture.componentInstance.dragStartDelay = '500';
1340+
fixture.componentInstance.dragStartDelay = '500' as any;
13411341
fixture.detectChanges();
13421342
const dragElement = fixture.componentInstance.dragElement.nativeElement;
13431343

@@ -1880,8 +1880,8 @@ class StandaloneDraggable {
18801880
startedSpy = jasmine.createSpy('started spy');
18811881
endedSpy = jasmine.createSpy('ended spy');
18821882
releasedSpy = jasmine.createSpy('released spy');
1883-
boundary: string | HTMLElement | undefined;
1884-
dragStartDelay: number | string | {touch: number; mouse: number} | undefined;
1883+
boundary!: string | HTMLElement;
1884+
dragStartDelay!: DragStartDelay;
18851885
constrainPosition:
18861886
| ((
18871887
userPointerPosition: Point,
@@ -1890,9 +1890,9 @@ class StandaloneDraggable {
18901890
pickupPositionInElement: Point,
18911891
) => Point)
18921892
| undefined;
1893-
freeDragPosition?: {x: number; y: number};
1893+
freeDragPosition!: {x: number; y: number};
18941894
dragDisabled = signal(false);
1895-
dragLockAxis = signal<DragAxis | undefined>(undefined);
1895+
dragLockAxis = signal<DragAxis | null>(null);
18961896
scale = 1;
18971897
}
18981898

@@ -2067,7 +2067,7 @@ class DraggableWithAlternateRoot {
20672067
@ViewChild('dragElement') dragElement!: ElementRef<HTMLElement>;
20682068
@ViewChild('dragRoot') dragRoot!: ElementRef<HTMLElement>;
20692069
@ViewChild(CdkDrag) dragInstance!: CdkDrag;
2070-
rootElementSelector: string | undefined;
2070+
rootElementSelector!: string;
20712071
}
20722072

20732073
@Component({

src/cdk/drag-drop/directives/standalone-drag.zone.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Point} from '../drag-ref';
1111
import {CdkDrag} from './drag';
1212
import {createComponent as _createComponent, dragElementViaMouse} from './test-utils.spec';
1313
import {ComponentFixture} from '@angular/core/testing';
14+
import {DragStartDelay} from './config';
1415

1516
describe('Standalone CdkDrag Zone.js integration', () => {
1617
function createComponent<T>(type: Type<T>): ComponentFixture<T> {
@@ -61,8 +62,8 @@ class StandaloneDraggable {
6162
startedSpy = jasmine.createSpy('started spy');
6263
endedSpy = jasmine.createSpy('ended spy');
6364
releasedSpy = jasmine.createSpy('released spy');
64-
boundary: string | HTMLElement | undefined;
65-
dragStartDelay: number | string | {touch: number; mouse: number} | undefined;
66-
constrainPosition: ((point: Point) => Point) | undefined;
67-
freeDragPosition: {x: number; y: number} | undefined;
65+
boundary!: string | HTMLElement;
66+
dragStartDelay!: DragStartDelay;
67+
constrainPosition!: (point: Point) => Point;
68+
freeDragPosition!: {x: number; y: number};
6869
}

src/cdk/testing/private/fake-directionality.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
*/
88

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10-
import {EventEmitter, signal, WritableSignal} from '@angular/core';
10+
import {EventEmitter, OnDestroy, Service, signal, WritableSignal} from '@angular/core';
1111
import {toObservable} from '@angular/core/rxjs-interop';
1212
import {skip} from 'rxjs/operators';
1313

1414
// Note: ngOnDestroy not needed, but must include it to match the Directionality interface.
1515
// Implementing the interface ensures the fake stays in sync with the real API.
1616
// tslint:disable-next-line:no-undecorated-class-with-angular-features lifecycle-hook-interface
17-
class FakeDirectionality implements Directionality {
17+
@Service()
18+
class FakeDirectionality implements Directionality, OnDestroy {
1819
readonly change: EventEmitter<Direction>;
1920

2021
get value(): Direction {

src/material-experimental/column-resize/column-resize.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ abstract class BaseTestComponentRtl extends BaseTestComponent {
278278
template: getTableTemplate(false),
279279
imports: [BidiModule, MatTableModule, MatColumnResizeModule],
280280
changeDetection: ChangeDetectionStrategy.Eager,
281+
jit: true, // Due to dynamic template
281282
})
282283
class MatResizeTest extends BaseTestComponent {
283284
@ViewChild(MatColumnResize) columnResize!: AbstractMatColumnResize;
@@ -286,13 +287,15 @@ class MatResizeTest extends BaseTestComponent {
286287
@Component({
287288
template: getTableTemplate(false),
288289
imports: [BidiModule, MatTableModule, MatColumnResizeModule],
290+
jit: true, // Due to dynamic template
289291
})
290292
class MatResizeOnPushTest extends MatResizeTest {}
291293

292294
@Component({
293295
template: getTableTemplate(true),
294296
imports: [BidiModule, MatTableModule, MatDefaultEnabledColumnResizeModule],
295297
changeDetection: ChangeDetectionStrategy.Eager,
298+
jit: true, // Due to dynamic template
296299
})
297300
class MatResizeDefaultTest extends BaseTestComponent {
298301
@ViewChild(MatDefaultEnabledColumnResize) columnResize!: AbstractMatColumnResize;
@@ -302,6 +305,7 @@ class MatResizeDefaultTest extends BaseTestComponent {
302305
template: getTableTemplate(true),
303306
imports: [BidiModule, MatTableModule, MatDefaultEnabledColumnResizeModule],
304307
changeDetection: ChangeDetectionStrategy.Eager,
308+
jit: true, // Due to dynamic template
305309
})
306310
class MatResizeDefaultRtlTest extends BaseTestComponentRtl {
307311
@ViewChild(MatDefaultEnabledColumnResize) columnResize!: AbstractMatColumnResize;
@@ -311,6 +315,7 @@ class MatResizeDefaultRtlTest extends BaseTestComponentRtl {
311315
template: getFlexTemplate(false),
312316
imports: [BidiModule, MatTableModule, MatColumnResizeModule],
313317
changeDetection: ChangeDetectionStrategy.Eager,
318+
jit: true, // Due to dynamic template
314319
})
315320
class MatResizeFlexTest extends BaseTestComponent {
316321
@ViewChild(MatColumnResizeFlex) columnResize!: AbstractMatColumnResize;
@@ -320,6 +325,7 @@ class MatResizeFlexTest extends BaseTestComponent {
320325
template: getFlexTemplate(true),
321326
imports: [BidiModule, MatTableModule, MatDefaultEnabledColumnResizeModule],
322327
changeDetection: ChangeDetectionStrategy.Eager,
328+
jit: true, // Due to dynamic template
323329
})
324330
class MatResizeDefaultFlexTest extends BaseTestComponent {
325331
@ViewChild(MatDefaultEnabledColumnResizeFlex)
@@ -330,6 +336,7 @@ class MatResizeDefaultFlexTest extends BaseTestComponent {
330336
template: getFlexTemplate(true),
331337
imports: [BidiModule, MatTableModule, MatDefaultEnabledColumnResizeModule],
332338
changeDetection: ChangeDetectionStrategy.Eager,
339+
jit: true, // Due to dynamic template
333340
})
334341
class MatResizeDefaultFlexRtlTest extends BaseTestComponentRtl {
335342
@ViewChild(MatDefaultEnabledColumnResizeFlex)

0 commit comments

Comments
 (0)