1- import { compareRepository , compareWithResults , defaultFilterSortState , matchesFilter , SortKey } from '../../../pure/variant-analysis-filter-sort' ;
1+ import {
2+ compareRepository ,
3+ compareWithResults ,
4+ defaultFilterSortState ,
5+ filterAndSortRepositoriesWithResults ,
6+ filterAndSortRepositoriesWithResultsByName ,
7+ matchesFilter ,
8+ SortKey ,
9+ } from '../../../pure/variant-analysis-filter-sort' ;
210
311// TODO: Move this file to the "pure" tests once it has been switched to Jest
412describe ( matchesFilter . name , ( ) => {
@@ -170,11 +178,13 @@ describe(compareWithResults.name, () => {
170178
171179 const left = {
172180 repository : {
181+ id : 10 ,
173182 fullName : 'github/galaxy' ,
174183 } ,
175184 } ;
176185 const right = {
177186 repository : {
187+ id : 12 ,
178188 fullName : 'github/world' ,
179189 } ,
180190 } ;
@@ -192,12 +202,14 @@ describe(compareWithResults.name, () => {
192202
193203 const left = {
194204 repository : {
205+ id : 11 ,
195206 fullName : 'github/galaxy' ,
196207 stargazersCount : 1 ,
197208 } ,
198209 } ;
199210 const right = {
200211 repository : {
212+ id : 12 ,
201213 fullName : 'github/world' ,
202214 stargazersCount : 10 ,
203215 } ,
@@ -216,12 +228,14 @@ describe(compareWithResults.name, () => {
216228
217229 const left = {
218230 repository : {
231+ id : 11 ,
219232 fullName : 'github/galaxy' ,
220233 updatedAt : '2020-01-01T00:00:00Z' ,
221234 } ,
222235 } ;
223236 const right = {
224237 repository : {
238+ id : 12 ,
225239 fullName : 'github/world' ,
226240 updatedAt : '2021-01-01T00:00:00Z' ,
227241 } ,
@@ -240,12 +254,14 @@ describe(compareWithResults.name, () => {
240254
241255 const left = {
242256 repository : {
257+ id : 11 ,
243258 fullName : 'github/galaxy' ,
244259 } ,
245260 resultCount : 10 ,
246261 } ;
247262 const right = {
248263 repository : {
264+ id : 12 ,
249265 fullName : 'github/world' ,
250266 } ,
251267 resultCount : 100 ,
@@ -278,3 +294,136 @@ describe(compareWithResults.name, () => {
278294 } ) ;
279295 } ) ;
280296} ) ;
297+
298+ describe ( filterAndSortRepositoriesWithResultsByName . name , ( ) => {
299+ const repositories = [
300+ {
301+ repository : {
302+ id : 10 ,
303+ fullName : 'github/galaxy' ,
304+ } ,
305+ resultCount : 10 ,
306+ } ,
307+ {
308+ repository : {
309+ id : 11 ,
310+ fullName : 'github/world' ,
311+ } ,
312+ resultCount : undefined ,
313+ } ,
314+ {
315+ repository : {
316+ id : 13 ,
317+ fullName : 'github/planet' ,
318+ } ,
319+ resultCount : 500 ,
320+ } ,
321+ {
322+ repository : {
323+ id : 783532 ,
324+ fullName : 'github/stars' ,
325+ } ,
326+ resultCount : 8000 ,
327+ }
328+ ] ;
329+
330+ describe ( 'when sort key is given without filter' , ( ) => {
331+ it ( 'returns the correct results' , ( ) => {
332+ expect ( filterAndSortRepositoriesWithResultsByName ( repositories , {
333+ ...defaultFilterSortState ,
334+ sortKey : SortKey . ResultsCount ,
335+ } ) ) . toEqual ( [ repositories [ 3 ] , repositories [ 2 ] , repositories [ 0 ] , repositories [ 1 ] ] ) ;
336+ } ) ;
337+ } ) ;
338+
339+ describe ( 'when sort key and search filter are given' , ( ) => {
340+ it ( 'returns the correct results' , ( ) => {
341+ expect ( filterAndSortRepositoriesWithResultsByName ( repositories , {
342+ ...defaultFilterSortState ,
343+ sortKey : SortKey . ResultsCount ,
344+ searchValue : 'la' ,
345+ } ) ) . toEqual ( [ repositories [ 2 ] , repositories [ 0 ] ] ) ;
346+ } ) ;
347+ } ) ;
348+ } ) ;
349+
350+ describe ( filterAndSortRepositoriesWithResults . name , ( ) => {
351+ const repositories = [
352+ {
353+ repository : {
354+ id : 10 ,
355+ fullName : 'github/galaxy' ,
356+ } ,
357+ resultCount : 10 ,
358+ } ,
359+ {
360+ repository : {
361+ id : 11 ,
362+ fullName : 'github/world' ,
363+ } ,
364+ resultCount : undefined ,
365+ } ,
366+ {
367+ repository : {
368+ id : 13 ,
369+ fullName : 'github/planet' ,
370+ } ,
371+ resultCount : 500 ,
372+ } ,
373+ {
374+ repository : {
375+ id : 783532 ,
376+ fullName : 'github/stars' ,
377+ } ,
378+ resultCount : 8000 ,
379+ }
380+ ] ;
381+
382+ describe ( 'when sort key is given without filter' , ( ) => {
383+ it ( 'returns the correct results' , ( ) => {
384+ expect ( filterAndSortRepositoriesWithResults ( repositories , {
385+ ...defaultFilterSortState ,
386+ sortKey : SortKey . ResultsCount ,
387+ } ) ) . toEqual ( [ repositories [ 3 ] , repositories [ 2 ] , repositories [ 0 ] , repositories [ 1 ] ] ) ;
388+ } ) ;
389+ } ) ;
390+
391+ describe ( 'when sort key and search filter are given' , ( ) => {
392+ it ( 'returns the correct results' , ( ) => {
393+ expect ( filterAndSortRepositoriesWithResults ( repositories , {
394+ ...defaultFilterSortState ,
395+ sortKey : SortKey . ResultsCount ,
396+ searchValue : 'la' ,
397+ } ) ) . toEqual ( [ repositories [ 2 ] , repositories [ 0 ] ] ) ;
398+ } ) ;
399+ } ) ;
400+
401+ describe ( 'when sort key, search filter, and repository ids are given' , ( ) => {
402+ it ( 'returns the correct results' , ( ) => {
403+ expect ( filterAndSortRepositoriesWithResults ( repositories , {
404+ ...defaultFilterSortState ,
405+ sortKey : SortKey . ResultsCount ,
406+ searchValue : 'la' ,
407+ repositoryIds : [ repositories [ 1 ] . repository . id , repositories [ 3 ] . repository . id ] ,
408+ } ) ) . toEqual ( [ repositories [ 3 ] , repositories [ 1 ] ] ) ;
409+ } ) ;
410+ } ) ;
411+
412+ describe ( 'when repository ids are given' , ( ) => {
413+ it ( 'returns the correct results' , ( ) => {
414+ expect ( filterAndSortRepositoriesWithResults ( repositories , {
415+ ...defaultFilterSortState ,
416+ repositoryIds : [ repositories [ 0 ] . repository . id , repositories [ 3 ] . repository . id ] ,
417+ } ) ) . toEqual ( [ repositories [ 0 ] , repositories [ 3 ] ] ) ;
418+ } ) ;
419+ } ) ;
420+
421+ describe ( 'when empty repository ids are given' , ( ) => {
422+ it ( 'returns the correct results' , ( ) => {
423+ expect ( filterAndSortRepositoriesWithResults ( repositories , {
424+ ...defaultFilterSortState ,
425+ repositoryIds : [ ] ,
426+ } ) ) . toEqual ( [ repositories [ 0 ] , repositories [ 2 ] , repositories [ 3 ] , repositories [ 1 ] ] ) ;
427+ } ) ;
428+ } ) ;
429+ } ) ;
0 commit comments