@@ -86,6 +86,79 @@ describe('computePivot', () => {
8686 expect ( res . cells [ rKeyWest ] [ cKeyGadget ] . value ) . toBe ( 90 )
8787 } )
8888
89+ it ( 'computes minimum aggregator' , ( ) => {
90+ const res = computePivot < Row > ( {
91+ data : rows ,
92+ rowFields : [ 'region' ] ,
93+ columnFields : [ 'product' ] ,
94+ valueField : 'amount' ,
95+ aggregator : 'min' ,
96+ } )
97+
98+ const rKeyEast = 'East'
99+ const rKeyWest = 'West'
100+ const cKeyGadget = 'Gadget'
101+ const cKeyWidget = 'Widget'
102+
103+ // East Gadget: values -> [10] => min 10
104+ expect ( res . cells [ rKeyEast ] [ cKeyGadget ] . value ) . toBe ( 10 )
105+ // West Gadget: values -> [90] => min 90
106+ expect ( res . cells [ rKeyWest ] [ cKeyGadget ] . value ) . toBe ( 90 )
107+ // East Widget: values -> [200] => min 200
108+ expect ( res . cells [ rKeyEast ] [ cKeyWidget ] . value ) . toBe ( 200 )
109+ // West Widget: values -> [120] => min 120
110+ expect ( res . cells [ rKeyWest ] [ cKeyWidget ] . value ) . toBe ( 120 )
111+ } )
112+
113+ it ( 'computes maximum aggregator' , ( ) => {
114+ const res = computePivot < Row > ( {
115+ data : rows ,
116+ rowFields : [ 'region' ] ,
117+ columnFields : [ 'product' ] ,
118+ valueField : 'amount' ,
119+ aggregator : 'max' ,
120+ } )
121+
122+ const rKeyEast = 'East'
123+ const rKeyWest = 'West'
124+ const cKeyGadget = 'Gadget'
125+ const cKeyWidget = 'Widget'
126+
127+ // East Gadget: values -> [10] => max 10
128+ expect ( res . cells [ rKeyEast ] [ cKeyGadget ] . value ) . toBe ( 10 )
129+ // West Gadget: values -> [90] => max 90
130+ expect ( res . cells [ rKeyWest ] [ cKeyGadget ] . value ) . toBe ( 90 )
131+ // East Widget: values -> [200] => max 200
132+ expect ( res . cells [ rKeyEast ] [ cKeyWidget ] . value ) . toBe ( 200 )
133+ // West Widget: values -> [120] => max 120
134+ expect ( res . cells [ rKeyWest ] [ cKeyWidget ] . value ) . toBe ( 120 )
135+ } )
136+
137+ it ( 'handles empty cells for min/max aggregators' , ( ) => {
138+ // Add a row with no valid numeric values
139+ const rowsWithEmpty = [
140+ ...rows ,
141+ { region : 'North' , rep : 'C' , product : 'Widget' , amount : 'not-a-number' } ,
142+ { region : 'North' , rep : 'D' , product : 'Gadget' , amount : 'also-not-a-number' } ,
143+ ]
144+
145+ const res = computePivot < Row > ( {
146+ data : rowsWithEmpty ,
147+ rowFields : [ 'region' ] ,
148+ columnFields : [ 'product' ] ,
149+ valueField : 'amount' ,
150+ aggregator : 'min' ,
151+ } )
152+
153+ const rKeyNorth = 'North'
154+ const cKeyWidget = 'Widget'
155+ const cKeyGadget = 'Gadget'
156+
157+ // North region has no valid numeric values, should return 0 for min
158+ expect ( res . cells [ rKeyNorth ] [ cKeyWidget ] . value ) . toBe ( 0 )
159+ expect ( res . cells [ rKeyNorth ] [ cKeyGadget ] . value ) . toBe ( 0 )
160+ } )
161+
89162 it ( 'supports custom aggregator' , ( ) => {
90163 const maxAgg : Aggregator < Row > = ( values ) =>
91164 values . length ? Math . max ( ...values ) : 0
0 commit comments