Skip to content

Commit 3b96730

Browse files
committed
test(cdk/drag-drop): convert tests to standalone
Converts the `drag-drop` tests to standalone to avoid some AoT compilation issues on the CI.
1 parent 664ab79 commit 3b96730

File tree

5 files changed

+150
-81
lines changed

5 files changed

+150
-81
lines changed

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

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Directionality} from '@angular/cdk/bidi';
22
import {_supportsShadowDom} from '@angular/cdk/platform';
3-
import {ViewportRuler} from '@angular/cdk/scrolling';
3+
import {CdkScrollable, ViewportRuler} from '@angular/cdk/scrolling';
44
import {
55
createMouseEvent,
66
createTouchEvent,
@@ -47,7 +47,9 @@ import {
4747
stopDraggingViaTouch,
4848
tickAnimationFrames,
4949
} from './test-utils.spec';
50-
import {NgFor} from '@angular/common';
50+
import {NgClass, NgFor, NgIf, NgTemplateOutlet} from '@angular/common';
51+
import {CdkDragPreview} from './drag-preview';
52+
import {CdkDragPlaceholder} from './drag-placeholder';
5153

5254
export const ITEM_HEIGHT = 25;
5355
export const ITEM_WIDTH = 75;
@@ -4026,9 +4028,7 @@ export function defineCommonDropListTests(config: {
40264028
);
40274029

40284030
it('should set the receiving class when the list is wrapped in an OnPush component', fakeAsync(() => {
4029-
const fixture = createComponent(ConnectedDropListsInOnPush, {
4030-
extraDeclarations: [DraggableInOnPushDropZone],
4031-
});
4031+
const fixture = createComponent(ConnectedDropListsInOnPush);
40324032
fixture.detectChanges();
40334033

40344034
const dropZones = Array.from<HTMLElement>(
@@ -4369,9 +4369,7 @@ export function defineCommonDropListTests(config: {
43694369
'should toggle a class when dragging an item inside a wrapper component component ' +
43704370
'with OnPush change detection',
43714371
fakeAsync(() => {
4372-
const fixture = createComponent(ConnectedWrappedDropZones, {
4373-
extraDeclarations: [WrappedDropContainerComponent],
4374-
});
4372+
const fixture = createComponent(ConnectedWrappedDropZones);
43754373
fixture.detectChanges();
43764374

43774375
const [startZone, targetZone] = fixture.nativeElement.querySelectorAll('.cdk-drop-list');
@@ -4832,6 +4830,8 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
48324830
encapsulation: ViewEncapsulation.None,
48334831
styles: HORIZONTAL_FIXTURE_STYLES,
48344832
template: HORIZONTAL_FIXTURE_TEMPLATE,
4833+
standalone: true,
4834+
imports: [CdkDropList, CdkDrag],
48354835
})
48364836
class DraggableInHorizontalDropZone implements AfterViewInit {
48374837
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -4858,6 +4858,8 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
48584858
}
48594859

48604860
@Component({
4861+
standalone: true,
4862+
imports: [CdkDropList, CdkDrag],
48614863
template: HORIZONTAL_FIXTURE_TEMPLATE,
48624864

48634865
// Note that it needs a margin to ensure that it's not flush against the viewport
@@ -4911,6 +4913,8 @@ export function getHorizontalFixtures(listOrientation: Exclude<DropListOrientati
49114913
}
49124914
</div>
49134915
`,
4916+
standalone: true,
4917+
imports: [CdkDropList, CdkDrag, CdkDragPreview],
49144918
})
49154919
class DraggableInHorizontalFlexDropZoneWithMatchSizePreview {
49164920
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -4993,6 +4997,8 @@ export class DraggableInDropZone implements AfterViewInit {
49934997
selector: 'draggable-in-on-push-zone',
49944998
template: DROP_ZONE_FIXTURE_TEMPLATE,
49954999
changeDetection: ChangeDetectionStrategy.OnPush,
5000+
standalone: true,
5001+
imports: [CdkDropList, CdkDrag, NgFor],
49965002
})
49975003
class DraggableInOnPushDropZone extends DraggableInDropZone {}
49985004

@@ -5003,6 +5009,8 @@ class DraggableInOnPushDropZone extends DraggableInDropZone {}
50035009
<draggable-in-on-push-zone></draggable-in-on-push-zone>
50045010
</div>
50055011
`,
5012+
standalone: true,
5013+
imports: [CdkDropListGroup, DraggableInOnPushDropZone],
50065014
})
50075015
class ConnectedDropListsInOnPush {}
50085016

@@ -5018,6 +5026,8 @@ class ConnectedDropListsInOnPush {}
50185026
margin: 10vw 0 0 10vw;
50195027
}
50205028
`,
5029+
standalone: true,
5030+
imports: [CdkDropList, CdkDrag, NgFor],
50215031
})
50225032
export class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
50235033
constructor(elementRef: ElementRef) {
@@ -5045,6 +5055,8 @@ export class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
50455055
margin: 10vw 0 0 10vw;
50465056
}
50475057
`,
5058+
standalone: true,
5059+
imports: [CdkDropList, CdkDrag, NgFor, CdkScrollable],
50485060
})
50495061
class DraggableInScrollableParentContainer extends DraggableInDropZone implements AfterViewInit {
50505062
@ViewChild('scrollContainer') scrollContainer: ElementRef<HTMLElement>;
@@ -5091,6 +5103,8 @@ class DraggableInScrollableParentContainer extends DraggableInDropZone implement
50915103
}
50925104
</div>
50935105
`,
5106+
standalone: true,
5107+
imports: [CdkDropList, CdkDrag],
50945108
})
50955109
class DraggableInDropZoneWithContainer extends DraggableInDropZone {}
50965110

@@ -5120,6 +5134,8 @@ class DraggableInDropZoneWithContainer extends DraggableInDropZone {}
51205134
}
51215135
</div>
51225136
`,
5137+
standalone: true,
5138+
imports: [CdkDropList, CdkDrag, CdkDragPreview, NgIf],
51235139
})
51245140
class DraggableInDropZoneWithCustomPreview {
51255141
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@@ -5153,6 +5169,8 @@ class DraggableInDropZoneWithCustomPreview {
51535169
}
51545170
</div>
51555171
`,
5172+
standalone: true,
5173+
imports: [CdkDropList, CdkDrag, CdkDragPreview],
51565174
})
51575175
class DraggableInDropZoneWithCustomTextOnlyPreview {
51585176
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@@ -5174,6 +5192,8 @@ class DraggableInDropZoneWithCustomTextOnlyPreview {
51745192
}
51755193
</div>
51765194
`,
5195+
standalone: true,
5196+
imports: [CdkDropList, CdkDrag, CdkDragPreview],
51775197
})
51785198
class DraggableInDropZoneWithCustomMultiNodePreview {
51795199
@ViewChild(CdkDropList) dropInstance: CdkDropList;
@@ -5205,6 +5225,8 @@ class DraggableInDropZoneWithCustomMultiNodePreview {
52055225
height: ${ITEM_HEIGHT * 3}px;
52065226
}
52075227
`,
5228+
standalone: true,
5229+
imports: [CdkDropList, CdkDrag, CdkDragPlaceholder, NgClass],
52085230
})
52095231
class DraggableInDropZoneWithCustomPlaceholder {
52105232
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -5225,6 +5247,8 @@ class DraggableInDropZoneWithCustomPlaceholder {
52255247
}
52265248
</div>
52275249
`,
5250+
standalone: true,
5251+
imports: [CdkDropList, CdkDrag, CdkDragPlaceholder],
52285252
})
52295253
class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
52305254
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -5245,6 +5269,8 @@ class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
52455269
}
52465270
</div>
52475271
`,
5272+
standalone: true,
5273+
imports: [CdkDropList, CdkDrag, CdkDragPlaceholder],
52485274
})
52495275
class DraggableInDropZoneWithCustomMultiNodePlaceholder {
52505276
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -5319,6 +5345,8 @@ const CONNECTED_DROP_ZONES_TEMPLATE = `
53195345
encapsulation: ViewEncapsulation.None,
53205346
styles: CONNECTED_DROP_ZONES_STYLES,
53215347
template: CONNECTED_DROP_ZONES_TEMPLATE,
5348+
standalone: true,
5349+
imports: [CdkDropList, CdkDrag],
53225350
})
53235351
class ConnectedDropZones implements AfterViewInit {
53245352
@ViewChildren(CdkDrag) rawDragItems: QueryList<CdkDrag>;
@@ -5352,6 +5380,8 @@ class ConnectedDropZones implements AfterViewInit {
53525380
encapsulation: ViewEncapsulation.ShadowDom,
53535381
styles: CONNECTED_DROP_ZONES_STYLES,
53545382
template: `@if (true) {${CONNECTED_DROP_ZONES_TEMPLATE}}`,
5383+
standalone: true,
5384+
imports: [CdkDropList, CdkDrag],
53555385
})
53565386
class ConnectedDropZonesInsideShadowRootWithNgIf extends ConnectedDropZones {}
53575387

@@ -5378,8 +5408,8 @@ class ConnectedDropZonesInsideShadowRootWithNgIf extends ConnectedDropZones {}
53785408
[cdkDropListData]="todo"
53795409
(cdkDropListDropped)="droppedSpy($event)">
53805410
@for (item of todo; track item) {
5381-
<div [cdkDragData]="item" cdkDrag>{{item}}</div>
5382-
}
5411+
<div [cdkDragData]="item" cdkDrag>{{item}}</div>
5412+
}
53835413
</div>
53845414
53855415
<div
@@ -5392,6 +5422,8 @@ class ConnectedDropZonesInsideShadowRootWithNgIf extends ConnectedDropZones {}
53925422
</div>
53935423
</div>
53945424
`,
5425+
standalone: true,
5426+
imports: [CdkDropList, CdkDrag, CdkDropListGroup],
53955427
})
53965428
class ConnectedDropZonesViaGroupDirective extends ConnectedDropZones {
53975429
groupDisabled = false;
@@ -5430,6 +5462,8 @@ class ConnectedDropZonesViaGroupDirective extends ConnectedDropZones {
54305462
<div cdkDrag>Two</div>
54315463
</div>
54325464
`,
5465+
standalone: true,
5466+
imports: [CdkDropList, CdkDrag],
54335467
})
54345468
class ConnectedDropZonesWithSingleItems {
54355469
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -5449,6 +5483,8 @@ class ConnectedDropZonesWithSingleItems {
54495483
<div cdkDropList #listTwo="cdkDropList"></div>
54505484
</div>
54515485
`,
5486+
standalone: true,
5487+
imports: [CdkDropList, CdkDropListGroup],
54525488
})
54535489
class NestedDropListGroups {
54545490
@ViewChild('group') group: CdkDropListGroup<CdkDropList>;
@@ -5460,11 +5496,15 @@ class NestedDropListGroups {
54605496
template: `
54615497
<ng-container cdkDropList></ng-container>
54625498
`,
5499+
standalone: true,
5500+
imports: [CdkDropList],
54635501
})
54645502
class DropListOnNgContainer {}
54655503

54665504
@Component({
54675505
changeDetection: ChangeDetectionStrategy.OnPush,
5506+
standalone: true,
5507+
imports: [CdkDropList, CdkDrag],
54685508
template: `
54695509
<div cdkDropList style="width: 100px; background: pink;">
54705510
@for (item of items; track item) {
@@ -5487,6 +5527,24 @@ class DraggableInDropZoneWithoutEvents {
54875527
];
54885528
}
54895529

5530+
/** Component that wraps a drop container and uses OnPush change detection. */
5531+
@Component({
5532+
selector: 'wrapped-drop-container',
5533+
template: `
5534+
<div cdkDropList [cdkDropListData]="items">
5535+
@for (item of items; track item) {
5536+
<div cdkDrag>{{item}}</div>
5537+
}
5538+
</div>
5539+
`,
5540+
standalone: true,
5541+
imports: [CdkDropList, CdkDrag],
5542+
changeDetection: ChangeDetectionStrategy.OnPush,
5543+
})
5544+
class WrappedDropContainerComponent {
5545+
@Input() items: string[];
5546+
}
5547+
54905548
@Component({
54915549
encapsulation: ViewEncapsulation.None,
54925550
styles: `
@@ -5509,6 +5567,8 @@ class DraggableInDropZoneWithoutEvents {
55095567
<wrapped-drop-container [items]="done"></wrapped-drop-container>
55105568
</div>
55115569
`,
5570+
standalone: true,
5571+
imports: [CdkDropListGroup, WrappedDropContainerComponent],
55125572
})
55135573
class ConnectedWrappedDropZones {
55145574
todo = ['Zero', 'One', 'Two', 'Three'];
@@ -5538,6 +5598,8 @@ class ConnectedWrappedDropZones {
55385598
}
55395599
</div>
55405600
`,
5601+
standalone: true,
5602+
imports: [CdkDropList, CdkDrag],
55415603
})
55425604
class DraggableWithCanvasInDropZone extends DraggableInDropZone implements AfterViewInit {
55435605
constructor(elementRef: ElementRef<HTMLElement>) {
@@ -5582,25 +5644,11 @@ class DraggableWithCanvasInDropZone extends DraggableInDropZone implements After
55825644
}
55835645
</div>
55845646
`,
5647+
standalone: true,
5648+
imports: [CdkDropList, CdkDrag],
55855649
})
55865650
class DraggableWithInvalidCanvasInDropZone extends DraggableInDropZone {}
55875651

5588-
/** Component that wraps a drop container and uses OnPush change detection. */
5589-
@Component({
5590-
selector: 'wrapped-drop-container',
5591-
template: `
5592-
<div cdkDropList [cdkDropListData]="items">
5593-
@for (item of items; track item) {
5594-
<div cdkDrag>{{item}}</div>
5595-
}
5596-
</div>
5597-
`,
5598-
changeDetection: ChangeDetectionStrategy.OnPush,
5599-
})
5600-
class WrappedDropContainerComponent {
5601-
@Input() items: string[];
5602-
}
5603-
56045652
@Component({
56055653
styles: `
56065654
:host {
@@ -5636,6 +5684,8 @@ class WrappedDropContainerComponent {
56365684
(cdkDragReleased)="itemDragReleasedSpy($event)">
56375685
</div>
56385686
</div>`,
5687+
standalone: true,
5688+
imports: [CdkDrag],
56395689
})
56405690
class NestedDragsComponent {
56415691
@ViewChild('container') container: ElementRef;
@@ -5689,6 +5739,8 @@ class NestedDragsComponent {
56895739
</div>
56905740
</ng-template>
56915741
`,
5742+
standalone: true,
5743+
imports: [CdkDrag, NgTemplateOutlet],
56925744
})
56935745
class NestedDragsThroughTemplate {
56945746
@ViewChild('container') container: ElementRef;
@@ -5713,6 +5765,8 @@ class NestedDragsThroughTemplate {
57135765
</div>
57145766
</div>
57155767
`,
5768+
standalone: true,
5769+
imports: [CdkDropList, CdkDrag],
57165770
})
57175771
class NestedDropZones {
57185772
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;
@@ -5723,6 +5777,8 @@ class NestedDropZones {
57235777

57245778
@Component({
57255779
template: `<div cdkDropList></div>`,
5780+
standalone: true,
5781+
imports: [CdkDropList],
57265782
})
57275783
class PlainStandaloneDropList {
57285784
@ViewChild(CdkDropList) dropList: CdkDropList;
@@ -5764,6 +5820,8 @@ class PlainStandaloneDropList {
57645820
</div>
57655821
</div>
57665822
`,
5823+
standalone: true,
5824+
imports: [CdkDropList, CdkDrag],
57675825
})
57685826
class ConnectedDropZonesWithIntermediateSibling extends ConnectedDropZones {}
57695827

@@ -5795,6 +5853,8 @@ class ConnectedDropZonesWithIntermediateSibling extends ConnectedDropZones {}
57955853
}
57965854
</div>
57975855
`,
5856+
standalone: true,
5857+
imports: [CdkDropList, CdkDrag],
57985858
})
57995859
class DraggableWithInputsInDropZone extends DraggableInDropZone {
58005860
inputValue = 'hello';
@@ -5816,6 +5876,8 @@ class DraggableWithInputsInDropZone extends DraggableInDropZone {
58165876
}
58175877
</div>
58185878
`,
5879+
standalone: true,
5880+
imports: [CdkDropList, CdkDrag],
58195881
})
58205882
class DraggableWithRadioInputsInDropZone {
58215883
@ViewChildren(CdkDrag) dragItems: QueryList<CdkDrag>;

0 commit comments

Comments
 (0)