@@ -16,6 +16,7 @@ import {
16
16
import {
17
17
getContainedManualDisplayPackageInfosWithCount ,
18
18
getExternalDisplayPackageInfosWithCount ,
19
+ sortDisplayPackageInfosWithCountByCountAndPackageName ,
19
20
} from '../accordion-panel-helpers' ;
20
21
import { PanelAttributionData } from '../../../util/get-contained-packages' ;
21
22
import { PackagePanelTitle } from '../../../enums/enums' ;
@@ -195,6 +196,54 @@ describe('getExternalDisplayPackageInfosWithCount', () => {
195
196
)
196
197
) . toEqual ( [ expectedPackageCardIds , expectedDisplayPackageInfosWithCount ] ) ;
197
198
} ) ;
199
+
200
+ it ( 'sorts ordinary and merged attributions according to the count' , ( ) => {
201
+ const testAttributionIdsWithCount : Array < AttributionIdWithCount > = [
202
+ { attributionId : 'uuidToMerge1' , count : 3 } ,
203
+ { attributionId : 'uuidToMerge2' , count : 2 } ,
204
+ { attributionId : 'uuidNotToMerge' , count : 1 } ,
205
+ ] ;
206
+ const testAttributions : Attributions = {
207
+ uuidToMerge1 : { packageName : 'Typescript' } ,
208
+ uuidToMerge2 : { packageName : 'Typescript' } ,
209
+ uuidNotToMerge : { packageName : 'React' } ,
210
+ } ;
211
+ const testExternalAttributionsToHashes : AttributionsToHashes = {
212
+ uuidToMerge1 : 'a' ,
213
+ uuidToMerge2 : 'a' ,
214
+ } ;
215
+
216
+ const expectedPackageCardIds = [
217
+ `${ testPackagePanelTitle } -1` ,
218
+ `${ testPackagePanelTitle } -0` ,
219
+ ] ;
220
+
221
+ const expectedDisplayPackageInfosWithCount : DisplayPackageInfosWithCount = {
222
+ [ expectedPackageCardIds [ 0 ] ] : {
223
+ count : 5 ,
224
+ displayPackageInfo : {
225
+ attributionIds : [ 'uuidToMerge1' , 'uuidToMerge2' ] ,
226
+ packageName : 'Typescript' ,
227
+ } ,
228
+ } ,
229
+ [ expectedPackageCardIds [ 1 ] ] : {
230
+ count : 1 ,
231
+ displayPackageInfo : {
232
+ attributionIds : [ 'uuidNotToMerge' ] ,
233
+ packageName : 'React' ,
234
+ } ,
235
+ } ,
236
+ } ;
237
+
238
+ expect (
239
+ getExternalDisplayPackageInfosWithCount (
240
+ testAttributionIdsWithCount ,
241
+ testAttributions ,
242
+ testExternalAttributionsToHashes ,
243
+ testPackagePanelTitle
244
+ )
245
+ ) . toEqual ( [ expectedPackageCardIds , expectedDisplayPackageInfosWithCount ] ) ;
246
+ } ) ;
198
247
} ) ;
199
248
200
249
describe ( 'getContainedManualDisplayPackageInfosWithCount' , ( ) => {
@@ -227,11 +276,13 @@ describe('getContainedManualDisplayPackageInfosWithCount', () => {
227
276
resourcesToAttributions : testResourcesToAttributions ,
228
277
resourcesWithAttributedChildren : testResourcesWithAttributedChildren ,
229
278
} ;
279
+
230
280
const expectedPackageCardIds = [
231
- `${ testPackagePanelTitle } -0` ,
232
281
`${ testPackagePanelTitle } -1` ,
233
282
`${ testPackagePanelTitle } -2` ,
283
+ `${ testPackagePanelTitle } -0` ,
234
284
] ;
285
+
235
286
const expectedDisplayPackageInfosWithCount : DisplayPackageInfosWithCount = {
236
287
[ expectedPackageCardIds [ 0 ] ] : {
237
288
displayPackageInfo : {
@@ -265,3 +316,57 @@ describe('getContainedManualDisplayPackageInfosWithCount', () => {
265
316
) . toEqual ( [ expectedPackageCardIds , expectedDisplayPackageInfosWithCount ] ) ;
266
317
} ) ;
267
318
} ) ;
319
+
320
+ describe ( 'sortDisplayPackageInfosWithCountByCountAndPackageName' , ( ) => {
321
+ it ( 'sorts items correctly' , ( ) => {
322
+ const initialPackageCardIds : Array < string > = [
323
+ 'pcid1' ,
324
+ 'pcid2' ,
325
+ 'pcid3' ,
326
+ 'pcid4' ,
327
+ 'pcid5' ,
328
+ 'pcid6' ,
329
+ ] ;
330
+ const testDisplayPackageInfosWithCount : DisplayPackageInfosWithCount = {
331
+ pcid1 : {
332
+ displayPackageInfo : { attributionIds : [ 'uuid1' ] } ,
333
+ count : 10 ,
334
+ } ,
335
+ pcid2 : {
336
+ displayPackageInfo : { attributionIds : [ 'uuid2' ] , packageName : 'c' } ,
337
+ count : 11 ,
338
+ } ,
339
+ pcid3 : {
340
+ displayPackageInfo : { attributionIds : [ 'uuid3' ] , packageName : 'b' } ,
341
+ count : 10 ,
342
+ } ,
343
+ pcid4 : {
344
+ displayPackageInfo : { attributionIds : [ 'uuid4' ] , packageName : 'e' } ,
345
+ count : 1 ,
346
+ } ,
347
+ pcid5 : {
348
+ displayPackageInfo : { attributionIds : [ 'uuid5' ] , packageName : 'z' } ,
349
+ count : 10 ,
350
+ } ,
351
+ pcid6 : {
352
+ displayPackageInfo : { attributionIds : [ 'uuid6' ] , packageName : 'd' } ,
353
+ count : 1 ,
354
+ } ,
355
+ } ;
356
+ const expectedPackageCardIds : Array < string > = [
357
+ 'pcid2' ,
358
+ 'pcid3' ,
359
+ 'pcid5' ,
360
+ 'pcid1' ,
361
+ 'pcid6' ,
362
+ 'pcid4' ,
363
+ ] ;
364
+
365
+ const result = initialPackageCardIds . sort (
366
+ sortDisplayPackageInfosWithCountByCountAndPackageName (
367
+ testDisplayPackageInfosWithCount
368
+ )
369
+ ) ;
370
+ expect ( result ) . toEqual ( expectedPackageCardIds ) ;
371
+ } ) ;
372
+ } ) ;
0 commit comments