Skip to content

Commit 49d0ccc

Browse files
authored
test(cdk/drag-drop): avoid flakes in scrolling tests (#23087)
A recent change (#23026) appears to have introduced flakiness in our unit tests on Firefox. These changes apply a similar workaround to some of the other scrolling tests.
1 parent 91fa44e commit 49d0ccc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6099,7 +6099,11 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
60996099
}
61006100

61016101
@Component({
6102-
template: '<div class="scroll-container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>',
6102+
template: `
6103+
<div
6104+
#scrollContainer
6105+
class="scroll-container"
6106+
cdkScrollable>${DROP_ZONE_FIXTURE_TEMPLATE}</div>`,
61036107

61046108
// Note that it needs a margin to ensure that it's not flush against the viewport
61056109
// edge which will cause the viewport to scroll, rather than the list.
@@ -6111,14 +6115,25 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
61116115
}
61126116
`]
61136117
})
6114-
class DraggableInScrollableParentContainer extends DraggableInDropZone {
6118+
class DraggableInScrollableParentContainer extends DraggableInDropZone implements AfterViewInit {
6119+
@ViewChild('scrollContainer') scrollContainer: ElementRef<HTMLElement>;
6120+
61156121
constructor(elementRef: ElementRef) {
61166122
super(elementRef);
61176123

61186124
for (let i = 0; i < 60; i++) {
61196125
this.items.push({value: `Extra item ${i}`, height: ITEM_HEIGHT, margin: 0});
61206126
}
61216127
}
6128+
6129+
override ngAfterViewInit() {
6130+
super.ngAfterViewInit();
6131+
6132+
// Firefox preserves the `scrollTop` value from previous similar containers. This
6133+
// could throw off test assertions and result in flaky results.
6134+
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=959812.
6135+
this.scrollContainer.nativeElement.scrollTop = 0;
6136+
}
61226137
}
61236138

61246139

0 commit comments

Comments
 (0)