Skip to content

Commit be2bb51

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
ListMetricAggregator UTs - cell offset APIs (#38732)
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
1 parent 966f97a commit be2bb51

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

packages/virtualized-lists/Lists/__tests__/ListMetricsAggregator-test.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,4 +894,148 @@ describe('ListMetricsAggregator', () => {
894894
isMounted: false,
895895
});
896896
});
897+
898+
it('resolves integral offset of already measured cell', () => {
899+
const listMetrics = new ListMetricsAggregator();
900+
const orientation = {horizontal: false, rtl: false};
901+
const props: CellMetricProps = {
902+
data: [1, 2, 3, 4, 5],
903+
getItemCount: () => nullthrows(props.data).length,
904+
getItem: (i: number) => nullthrows(props.data)[i],
905+
};
906+
907+
listMetrics.notifyCellLayout({
908+
cellIndex: 0,
909+
cellKey: '0',
910+
orientation,
911+
layout: {
912+
height: 10,
913+
width: 5,
914+
x: 0,
915+
y: 0,
916+
},
917+
});
918+
919+
listMetrics.notifyCellLayout({
920+
cellIndex: 1,
921+
cellKey: '1',
922+
orientation,
923+
layout: {
924+
height: 20,
925+
width: 5,
926+
x: 0,
927+
y: 10,
928+
},
929+
});
930+
931+
expect(listMetrics.getCellOffsetApprox(1, props)).toEqual(10);
932+
});
933+
934+
it('estimates integral offset of unmeasured cell', () => {
935+
const listMetrics = new ListMetricsAggregator();
936+
const orientation = {horizontal: false, rtl: false};
937+
const props: CellMetricProps = {
938+
data: [1, 2, 3, 4, 5],
939+
getItemCount: () => nullthrows(props.data).length,
940+
getItem: (i: number) => nullthrows(props.data)[i],
941+
};
942+
943+
listMetrics.notifyCellLayout({
944+
cellIndex: 0,
945+
cellKey: '0',
946+
orientation,
947+
layout: {
948+
height: 10,
949+
width: 5,
950+
x: 0,
951+
y: 0,
952+
},
953+
});
954+
955+
listMetrics.notifyCellLayout({
956+
cellIndex: 1,
957+
cellKey: '1',
958+
orientation,
959+
layout: {
960+
height: 20,
961+
width: 5,
962+
x: 0,
963+
y: 10,
964+
},
965+
});
966+
967+
expect(listMetrics.getCellOffsetApprox(2, props)).toEqual(30);
968+
});
969+
970+
it('resolves fractional offset of already measured cell', () => {
971+
const listMetrics = new ListMetricsAggregator();
972+
const orientation = {horizontal: false, rtl: false};
973+
const props: CellMetricProps = {
974+
data: [1, 2, 3, 4, 5],
975+
getItemCount: () => nullthrows(props.data).length,
976+
getItem: (i: number) => nullthrows(props.data)[i],
977+
};
978+
979+
listMetrics.notifyCellLayout({
980+
cellIndex: 0,
981+
cellKey: '0',
982+
orientation,
983+
layout: {
984+
height: 10,
985+
width: 5,
986+
x: 0,
987+
y: 0,
988+
},
989+
});
990+
991+
listMetrics.notifyCellLayout({
992+
cellIndex: 1,
993+
cellKey: '1',
994+
orientation,
995+
layout: {
996+
height: 20,
997+
width: 5,
998+
x: 0,
999+
y: 10,
1000+
},
1001+
});
1002+
1003+
expect(listMetrics.getCellOffsetApprox(1.5, props)).toEqual(20);
1004+
});
1005+
1006+
it('estimates fractional offset of unmeasured cell', () => {
1007+
const listMetrics = new ListMetricsAggregator();
1008+
const orientation = {horizontal: false, rtl: false};
1009+
const props: CellMetricProps = {
1010+
data: [1, 2, 3, 4, 5],
1011+
getItemCount: () => nullthrows(props.data).length,
1012+
getItem: (i: number) => nullthrows(props.data)[i],
1013+
};
1014+
1015+
listMetrics.notifyCellLayout({
1016+
cellIndex: 0,
1017+
cellKey: '0',
1018+
orientation,
1019+
layout: {
1020+
height: 10,
1021+
width: 5,
1022+
x: 0,
1023+
y: 0,
1024+
},
1025+
});
1026+
1027+
listMetrics.notifyCellLayout({
1028+
cellIndex: 1,
1029+
cellKey: '1',
1030+
orientation,
1031+
layout: {
1032+
height: 20,
1033+
width: 5,
1034+
x: 0,
1035+
y: 10,
1036+
},
1037+
});
1038+
1039+
expect(listMetrics.getCellOffsetApprox(2.5, props)).toEqual(37.5);
1040+
});
8971041
});

0 commit comments

Comments
 (0)