-
Notifications
You must be signed in to change notification settings - Fork 6.8k
virtual-scroll: add tests for fixed size items #11255
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
Conversation
flush(); | ||
|
||
expect((viewport._renderedContentTransform as any).changingThisBreaksApplicationSecurity) | ||
.toEqual('translateY(NaNpx)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use toBe
here.
finishInit(fixture); | ||
|
||
expect(viewport.measureRangeSize({start: 1, end: 3})) | ||
.toBe(testComponent.itemSize * 2, 'combined size of 2 50px items should be 100px'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expectation could go out of sync if we change the itemSize
. What about changing the expectation to use a hardcoded value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also fail if we hard-coded the number and then changed the item size. I would prefer to use values like this over raw numbers when possible, otherwise you have no idea what the numbers are supposed to be when you come back to it in the future. (I had this experience when I refactored the select to work inside form-field. The test file was full of numbers that meant nothing to me).
start: Math.floor(offset / testComponent.itemSize), | ||
end: Math.floor(offset / testComponent.itemSize) + 4 | ||
}; | ||
expect(viewport.getRenderedRange()).toEqual(expectedRange); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add some descriptions to the expectations? Since they're in a loop, it might be difficult to debug if things start failing.
start: Math.floor(offset / testComponent.itemSize), | ||
end: Math.floor(offset / testComponent.itemSize) + 4 | ||
}; | ||
expect(viewport.getRenderedRange()).toEqual(expectedRange); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also consider adding some descriptions to the expectations here.
fakeAsync(() => { | ||
testComponent.bufferSize = 1; | ||
finishInit(fixture); | ||
triggerScroll(viewport, testComponent.itemSize * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the testComponent.itemSize
to the actual value would make this one easier to follow. Currently anybody reading it has to go and look up the value of itemSize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. When trying to understand the test, I think what the number represents conceptually is more important than what the actual value is
</div> | ||
</cdk-virtual-scroll-viewport> | ||
`, | ||
styles: [`.cdk-virtual-scroll-content-wrapper { display: flex; flex-direction: column; }`], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it could potentially be flaky when we run the tests against IE/Edge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? IE supports flexbox AFAIK...
@ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport; | ||
@ViewChild(CdkVirtualForOf, {read: ViewContainerRef}) cdkForOfViewContainer: ViewContainerRef; | ||
|
||
@Input() viewportSize = 200; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't really inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're not inputs to the viewport, but they are inputs to my test component. I will want to create tests that check that the viewport handles re-rendering its content on size change once I add that feature
|
||
/** Finish initializing the virtual scroll component at the beginning of a test. */ | ||
function finishInit(fixture: ComponentFixture<any>) { | ||
// One the first cycle we render and measure the viewport. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one the first -> on the first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from @crisbeto's comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the CI is green.
imports: [ScrollingModule], | ||
declarations: [BasicViewport], | ||
}).compileComponents(); | ||
fdescribe('CdkVirtualScrollViewport', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgotten fdescribe.
Fixed a small bug in the |
* feat(virtual-scroll): fixed size virtual scroll (#9316) * feat(virtual-scroll): fixed size virtual scroll * address some comments * change VirtualScrollStrategy interface a bit * address some more comments * fix lint & build * chore: move virtual-scroll to cdk-experimental (#9974) * virtual-scroll: simplify scroll listener logic (#10102) * virtual-scroll: only move views that need to be moved (#10099) * virtual-scroll: only move views that need to be moved * address comments * virtual-scroll: switch `throttleTime` to `sampleTime` (#10179) * virtual-scroll: switch throttleTime to sampleTime * add comment * virtual-scroll: allow user to pass `Observable<T[]>` (#10158) * virtual-scroll: rename `Range` to `ListRange` to avoid confusion with native `Range` (#10220) * virtual-scroll: add autosize scroll strategy (#10219) * rename fixed size virtual scroll directive * add autosize virtual scroll strategy * add item size estimator class * add logic for jumping rendered content based on scroll position * address comments * virtual-scroll: add `onContentRendered` hook to `VirtualScrollStrategy` (#10290) * virtual-scroll: add `onContentRendered` hook to `VirtualScrollStrategy` * address comemnts * virtual-scroll: add incremental scroll logic in `AutosizeVirtualScrollStrategy` (#10504) * virtual-scroll: add incremental scroll logic in `AutosizeVirtualScrollStrategy`. This still has a couple issues that need to be ironed out and it doesn't have the code for correcting the error between the predicted and actual scroll position. (See various TODOs for additional things that need work). * fix lint * address comments * address comments * fix bazel * fix devapp * fix lint * cleanup * virtual-scroll: rewrite offset in terms of "to-top" and fix a bug where items were removed too soon (#10986) * rewrite offsets to the end of the rendered content as offsets to the start * add some more autosize demos for testing * make sure not to remove too many items * address comments * virtual-scroll: address amcdnl's feedback (#10988) * rewrite offsets to the end of the rendered content as offsets to the start * add some more autosize demos for testing * make sure not to remove too many items * virtual-scroll: address amcdnl's feedback * virtual-scroll: fix updating when data changes and add trackBy demos (#11085) * virtual-scroll: add logic to correct the scroll position as user move… (#11137) * virtual-scroll: add logic to correct the scroll position as user moves toward the top * address comments * fix(scrolling): adds right to fix pushed content (#11192) * fix(scrolling): adds right to fix pushed content * chore: address feedback * chore: address pr feedback * virtual-scroll: add tests for fixed size items (#11255) * virtual-scroll: add tests for fixed size items * address comments * fix bug in fixed size strategy * fix bazel build * virtual-scroll: add tests for `cdkVirtualFor` logic (#11275) * merge fixed size test components into one * add tests for cdkVirtualFor logic * allow undefined to be explicitly passed as trackBy * fix bazel build * address comments * add some basic tests (#11295) * fix lint * virtual-scroll: add e2e tests for autosize scroll strategy (#11345) * set up virtual scroll page in e2e app * add gulp task for e2e:watch * add e2e tests for autosize * address comments * address comments * fix lint and tests * fix bad rebase * fix(scrolling): scrollbar jump when data change on scroll (#11193) * fix(scrolling): data change not updating size * chore: remove todo * chore: more performant fix for jump
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
related to #10180