Skip to content

Commit

Permalink
ListMetricAggregator UTs - cell offset APIs (#38732)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Aug 16, 2023
1 parent 966f97a commit be2bb51
Showing 1 changed file with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit be2bb51

Please sign in to comment.