@@ -1038,4 +1038,69 @@ describe('ListMetricsAggregator', () => {
1038
1038
1039
1039
expect ( listMetrics . getCellOffsetApprox ( 2.5 , props ) ) . toEqual ( 37.5 ) ;
1040
1040
} ) ;
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
+ } ) ;
1041
1106
} ) ;
0 commit comments