Skip to content

Commit c522837

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
ListMetricAggregator UTs - contentLength caching (#38738)
Summary: Pull Request resolved: #38738 UTs about returned cached content length and cached content length requirement in RTL. Changelog: [Internal] Reviewed By: rozele Differential Revision: D47978634 fbshipit-source-id: 509b2b60cae4a8755745710fb5872da27c8ce7a3
1 parent 298d297 commit c522837

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

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

+65
Original file line numberDiff line numberDiff line change
@@ -1038,4 +1038,69 @@ describe('ListMetricsAggregator', () => {
10381038

10391039
expect(listMetrics.getCellOffsetApprox(2.5, props)).toEqual(37.5);
10401040
});
1041+
1042+
it('remembers most recent content length', () => {
1043+
const listMetrics = new ListMetricsAggregator();
1044+
const orientation = {horizontal: false, rtl: false};
1045+
1046+
expect(listMetrics.hasContentLength()).toBe(false);
1047+
expect(listMetrics.getContentLength()).toBe(0);
1048+
1049+
listMetrics.notifyListContentLayout({
1050+
layout: {height: 10, width: 20},
1051+
orientation,
1052+
});
1053+
expect(listMetrics.getContentLength()).toBe(10);
1054+
1055+
listMetrics.notifyListContentLayout({
1056+
layout: {height: 15, width: 25},
1057+
orientation,
1058+
});
1059+
expect(listMetrics.getContentLength()).toBe(15);
1060+
});
1061+
1062+
it('remembers most recent horizontal content length', () => {
1063+
const listMetrics = new ListMetricsAggregator();
1064+
const orientation = {horizontal: true, rtl: false};
1065+
1066+
expect(listMetrics.hasContentLength()).toBe(false);
1067+
expect(listMetrics.getContentLength()).toBe(0);
1068+
1069+
listMetrics.notifyListContentLayout({
1070+
layout: {height: 10, width: 20},
1071+
orientation,
1072+
});
1073+
expect(listMetrics.getContentLength()).toBe(20);
1074+
1075+
listMetrics.notifyListContentLayout({
1076+
layout: {height: 15, width: 25},
1077+
orientation,
1078+
});
1079+
expect(listMetrics.getContentLength()).toBe(25);
1080+
});
1081+
1082+
it('requires contentLength to resolve RTL metrics', () => {
1083+
const listMetrics = new ListMetricsAggregator();
1084+
const orientation = {horizontal: true, rtl: true};
1085+
1086+
const props: CellMetricProps = {
1087+
data: [1, 2, 3, 4, 5],
1088+
getItemCount: () => nullthrows(props.data).length,
1089+
getItem: (i: number) => nullthrows(props.data)[i],
1090+
};
1091+
1092+
listMetrics.notifyCellLayout({
1093+
cellIndex: 0,
1094+
cellKey: '0',
1095+
orientation,
1096+
layout: {
1097+
height: 10,
1098+
width: 5,
1099+
x: 0,
1100+
y: 0,
1101+
},
1102+
});
1103+
1104+
expect(() => listMetrics.getCellMetrics(0, props)).toThrow();
1105+
});
10411106
});

0 commit comments

Comments
 (0)