Skip to content

test(cdk/drag-drop): avoid flakes in scrolling tests #23087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6099,7 +6099,11 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
}

@Component({
template: '<div class="scroll-container" cdkScrollable>' + DROP_ZONE_FIXTURE_TEMPLATE + '</div>',
template: `
<div
#scrollContainer
class="scroll-container"
cdkScrollable>${DROP_ZONE_FIXTURE_TEMPLATE}</div>`,

// Note that it needs a margin to ensure that it's not flush against the viewport
// edge which will cause the viewport to scroll, rather than the list.
Expand All @@ -6111,14 +6115,25 @@ class DraggableInScrollableVerticalDropZone extends DraggableInDropZone {
}
`]
})
class DraggableInScrollableParentContainer extends DraggableInDropZone {
class DraggableInScrollableParentContainer extends DraggableInDropZone implements AfterViewInit {
@ViewChild('scrollContainer') scrollContainer: ElementRef<HTMLElement>;

constructor(elementRef: ElementRef) {
super(elementRef);

for (let i = 0; i < 60; i++) {
this.items.push({value: `Extra item ${i}`, height: ITEM_HEIGHT, margin: 0});
}
}

override ngAfterViewInit() {
super.ngAfterViewInit();

// Firefox preserves the `scrollTop` value from previous similar containers. This
// could throw off test assertions and result in flaky results.
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=959812.
this.scrollContainer.nativeElement.scrollTop = 0;
}
}


Expand Down