44 defaultFilterSortState ,
55 filterAndSortRepositoriesWithResults ,
66 filterAndSortRepositoriesWithResultsByName ,
7+ FilterKey ,
78 matchesFilter ,
89 SortKey ,
910} from "../../src/pure/variant-analysis-filter-sort" ;
@@ -42,6 +43,60 @@ describe(matchesFilter.name, () => {
4243 ) . toBe ( matches ) ;
4344 } ,
4445 ) ;
46+
47+ it ( "returns true if filterKey is all and resultCount is positive" , ( ) => {
48+ expect (
49+ matchesFilter (
50+ { repository, resultCount : 1 } ,
51+ { ...defaultFilterSortState , filterKey : FilterKey . All } ,
52+ ) ,
53+ ) . toBe ( true ) ;
54+ } ) ;
55+
56+ it ( "returns true if filterKey is all and resultCount is zero" , ( ) => {
57+ expect (
58+ matchesFilter (
59+ { repository, resultCount : 0 } ,
60+ { ...defaultFilterSortState , filterKey : FilterKey . All } ,
61+ ) ,
62+ ) . toBe ( true ) ;
63+ } ) ;
64+
65+ it ( "returns true if filterKey is all and resultCount is undefined" , ( ) => {
66+ expect (
67+ matchesFilter (
68+ { repository } ,
69+ { ...defaultFilterSortState , filterKey : FilterKey . All } ,
70+ ) ,
71+ ) . toBe ( true ) ;
72+ } ) ;
73+
74+ it ( "returns true if filterKey is withResults and resultCount is positive" , ( ) => {
75+ expect (
76+ matchesFilter (
77+ { repository, resultCount : 1 } ,
78+ { ...defaultFilterSortState , filterKey : FilterKey . WithResults } ,
79+ ) ,
80+ ) . toBe ( true ) ;
81+ } ) ;
82+
83+ it ( "returns false if filterKey is withResults and resultCount is zero" , ( ) => {
84+ expect (
85+ matchesFilter (
86+ { repository, resultCount : 0 } ,
87+ { ...defaultFilterSortState , filterKey : FilterKey . WithResults } ,
88+ ) ,
89+ ) . toBe ( false ) ;
90+ } ) ;
91+
92+ it ( "returns false if filterKey is withResults and resultCount is undefined" , ( ) => {
93+ expect (
94+ matchesFilter (
95+ { repository } ,
96+ { ...defaultFilterSortState , filterKey : FilterKey . WithResults } ,
97+ ) ,
98+ ) . toBe ( false ) ;
99+ } ) ;
45100} ) ;
46101
47102describe ( compareRepository . name , ( ) => {
@@ -352,7 +407,7 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => {
352407 } ,
353408 ] ;
354409
355- describe ( "when sort key is given without filter" , ( ) => {
410+ describe ( "when sort key is given without search or filter" , ( ) => {
356411 it ( "returns the correct results" , ( ) => {
357412 expect (
358413 filterAndSortRepositoriesWithResultsByName ( repositories , {
@@ -368,7 +423,7 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => {
368423 } ) ;
369424 } ) ;
370425
371- describe ( "when sort key and search filter are given" , ( ) => {
426+ describe ( "when sort key and search are given without filter " , ( ) => {
372427 it ( "returns the correct results" , ( ) => {
373428 expect (
374429 filterAndSortRepositoriesWithResultsByName ( repositories , {
@@ -379,6 +434,30 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => {
379434 ) . toEqual ( [ repositories [ 2 ] , repositories [ 0 ] ] ) ;
380435 } ) ;
381436 } ) ;
437+
438+ describe ( "when sort key and filter withResults are given without search" , ( ) => {
439+ it ( "returns the correct results" , ( ) => {
440+ expect (
441+ filterAndSortRepositoriesWithResultsByName ( repositories , {
442+ ...defaultFilterSortState ,
443+ sortKey : SortKey . ResultsCount ,
444+ filterKey : FilterKey . WithResults ,
445+ } ) ,
446+ ) . toEqual ( [ repositories [ 3 ] , repositories [ 2 ] , repositories [ 0 ] ] ) ;
447+ } ) ;
448+ } ) ;
449+
450+ describe ( "when sort key and search and filter withResults are given" , ( ) => {
451+ it ( "returns the correct results" , ( ) => {
452+ expect (
453+ filterAndSortRepositoriesWithResultsByName ( repositories , {
454+ sortKey : SortKey . ResultsCount ,
455+ filterKey : FilterKey . WithResults ,
456+ searchValue : "r" ,
457+ } ) ,
458+ ) . toEqual ( [ repositories [ 3 ] ] ) ;
459+ } ) ;
460+ } ) ;
382461} ) ;
383462
384463describe ( filterAndSortRepositoriesWithResults . name , ( ) => {
@@ -413,7 +492,7 @@ describe(filterAndSortRepositoriesWithResults.name, () => {
413492 } ,
414493 ] ;
415494
416- describe ( "when sort key is given without filter " , ( ) => {
495+ describe ( "when sort key is given" , ( ) => {
417496 it ( "returns the correct results" , ( ) => {
418497 expect (
419498 filterAndSortRepositoriesWithResults ( repositories , {
@@ -429,7 +508,7 @@ describe(filterAndSortRepositoriesWithResults.name, () => {
429508 } ) ;
430509 } ) ;
431510
432- describe ( "when sort key and search filter are given" , ( ) => {
511+ describe ( "when sort key and search are given" , ( ) => {
433512 it ( "returns the correct results" , ( ) => {
434513 expect (
435514 filterAndSortRepositoriesWithResults ( repositories , {
@@ -441,12 +520,49 @@ describe(filterAndSortRepositoriesWithResults.name, () => {
441520 } ) ;
442521 } ) ;
443522
444- describe ( "when sort key, search filter, and repository ids are given" , ( ) => {
523+ describe ( "when sort key and filter withResults are given" , ( ) => {
524+ it ( "returns the correct results" , ( ) => {
525+ expect (
526+ filterAndSortRepositoriesWithResults ( repositories , {
527+ ...defaultFilterSortState ,
528+ sortKey : SortKey . ResultsCount ,
529+ filterKey : FilterKey . WithResults ,
530+ } ) ,
531+ ) . toEqual ( [ repositories [ 3 ] , repositories [ 2 ] , repositories [ 0 ] ] ) ;
532+ } ) ;
533+ } ) ;
534+
535+ describe ( "when sort key and filter withResults are given" , ( ) => {
445536 it ( "returns the correct results" , ( ) => {
446537 expect (
447538 filterAndSortRepositoriesWithResults ( repositories , {
448539 ...defaultFilterSortState ,
449540 sortKey : SortKey . ResultsCount ,
541+ filterKey : FilterKey . WithResults ,
542+ } ) ,
543+ ) . toEqual ( [ repositories [ 3 ] , repositories [ 2 ] , repositories [ 0 ] ] ) ;
544+ } ) ;
545+ } ) ;
546+
547+ describe ( "when sort key and search and filter withResults are given" , ( ) => {
548+ it ( "returns the correct results" , ( ) => {
549+ expect (
550+ filterAndSortRepositoriesWithResults ( repositories , {
551+ ...defaultFilterSortState ,
552+ sortKey : SortKey . ResultsCount ,
553+ filterKey : FilterKey . WithResults ,
554+ searchValue : "r" ,
555+ } ) ,
556+ ) . toEqual ( [ repositories [ 3 ] ] ) ;
557+ } ) ;
558+ } ) ;
559+
560+ describe ( "when sort key, search, filter withResults, and repository ids are given" , ( ) => {
561+ it ( "returns the correct results" , ( ) => {
562+ expect (
563+ filterAndSortRepositoriesWithResults ( repositories , {
564+ sortKey : SortKey . ResultsCount ,
565+ filterKey : FilterKey . WithResults ,
450566 searchValue : "la" ,
451567 repositoryIds : [
452568 repositories [ 1 ] . repository . id ,
0 commit comments