mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ListMetricAggregator UTs - cell offset APIs (#38732)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38732 Unit tests for cell offset APIs. Mostly the same as previous UTs for VirtualizedList a layer higher. Changelog: [Internal] Reviewed By: rozele Differential Revision: D47978633 fbshipit-source-id: 8cb8a2e8125bc7370eabf9f01a3f7529043171c2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
966f97acdc
commit
be2bb51c70
@@ -894,4 +894,148 @@ describe('ListMetricsAggregator', () => {
|
||||
isMounted: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('resolves integral offset of already measured cell', () => {
|
||||
const listMetrics = new ListMetricsAggregator();
|
||||
const orientation = {horizontal: false, rtl: false};
|
||||
const props: CellMetricProps = {
|
||||
data: [1, 2, 3, 4, 5],
|
||||
getItemCount: () => nullthrows(props.data).length,
|
||||
getItem: (i: number) => nullthrows(props.data)[i],
|
||||
};
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 0,
|
||||
cellKey: '0',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 10,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 1,
|
||||
cellKey: '1',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 20,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 10,
|
||||
},
|
||||
});
|
||||
|
||||
expect(listMetrics.getCellOffsetApprox(1, props)).toEqual(10);
|
||||
});
|
||||
|
||||
it('estimates integral offset of unmeasured cell', () => {
|
||||
const listMetrics = new ListMetricsAggregator();
|
||||
const orientation = {horizontal: false, rtl: false};
|
||||
const props: CellMetricProps = {
|
||||
data: [1, 2, 3, 4, 5],
|
||||
getItemCount: () => nullthrows(props.data).length,
|
||||
getItem: (i: number) => nullthrows(props.data)[i],
|
||||
};
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 0,
|
||||
cellKey: '0',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 10,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 1,
|
||||
cellKey: '1',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 20,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 10,
|
||||
},
|
||||
});
|
||||
|
||||
expect(listMetrics.getCellOffsetApprox(2, props)).toEqual(30);
|
||||
});
|
||||
|
||||
it('resolves fractional offset of already measured cell', () => {
|
||||
const listMetrics = new ListMetricsAggregator();
|
||||
const orientation = {horizontal: false, rtl: false};
|
||||
const props: CellMetricProps = {
|
||||
data: [1, 2, 3, 4, 5],
|
||||
getItemCount: () => nullthrows(props.data).length,
|
||||
getItem: (i: number) => nullthrows(props.data)[i],
|
||||
};
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 0,
|
||||
cellKey: '0',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 10,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 1,
|
||||
cellKey: '1',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 20,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 10,
|
||||
},
|
||||
});
|
||||
|
||||
expect(listMetrics.getCellOffsetApprox(1.5, props)).toEqual(20);
|
||||
});
|
||||
|
||||
it('estimates fractional offset of unmeasured cell', () => {
|
||||
const listMetrics = new ListMetricsAggregator();
|
||||
const orientation = {horizontal: false, rtl: false};
|
||||
const props: CellMetricProps = {
|
||||
data: [1, 2, 3, 4, 5],
|
||||
getItemCount: () => nullthrows(props.data).length,
|
||||
getItem: (i: number) => nullthrows(props.data)[i],
|
||||
};
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 0,
|
||||
cellKey: '0',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 10,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
});
|
||||
|
||||
listMetrics.notifyCellLayout({
|
||||
cellIndex: 1,
|
||||
cellKey: '1',
|
||||
orientation,
|
||||
layout: {
|
||||
height: 20,
|
||||
width: 5,
|
||||
x: 0,
|
||||
y: 10,
|
||||
},
|
||||
});
|
||||
|
||||
expect(listMetrics.getCellOffsetApprox(2.5, props)).toEqual(37.5);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user