@@ -354,40 +354,60 @@ describe("groupByRepository", () => {
354354} ) ;
355355
356356describe ( "findGroupFolder" , ( ) => {
357- const mainClone = {
357+ interface GroupFolder {
358+ path : string ;
359+ remoteUrl : string | null ;
360+ mainRepoPath ?: string | null ;
361+ }
362+
363+ const mainClone : GroupFolder = {
358364 path : "/repos/code" ,
359365 remoteUrl : "posthog/code" ,
360366 mainRepoPath : null ,
361367 } ;
362- const worktree = {
368+ const worktree : GroupFolder = {
363369 path : "/repos/code-wt" ,
364370 remoteUrl : "posthog/code" ,
365371 mainRepoPath : "/repos/code" ,
366372 } ;
367- const unrelated = {
373+ const unrelated : GroupFolder = {
368374 path : "/repos/other" ,
369375 remoteUrl : "acme/other" ,
370376 mainRepoPath : null ,
371377 } ;
372-
373- it ( "prefers the main clone when a worktree of the same repo was added first" , ( ) => {
374- expect (
375- findGroupFolder ( [ worktree , mainClone , unrelated ] , "posthog/code" ) ,
376- ) . toBe ( mainClone ) ;
377- } ) ;
378-
379- it ( "falls back to the worktree when only it is registered" , ( ) => {
380- expect ( findGroupFolder ( [ worktree , unrelated ] , "posthog/code" ) ) . toBe (
381- worktree ,
382- ) ;
383- } ) ;
384-
385- it ( "matches folders without a remote by path" , ( ) => {
386- const local = { path : "/repos/local" , remoteUrl : null } ;
387- expect ( findGroupFolder ( [ local ] , "/repos/local" ) ) . toBe ( local ) ;
388- } ) ;
389-
390- it ( "returns undefined when nothing matches" , ( ) => {
391- expect ( findGroupFolder ( [ unrelated ] , "posthog/code" ) ) . toBeUndefined ( ) ;
378+ const local : GroupFolder = { path : "/repos/local" , remoteUrl : null } ;
379+
380+ it . each < {
381+ name : string ;
382+ folders : GroupFolder [ ] ;
383+ groupId : string ;
384+ expected : GroupFolder | undefined ;
385+ } > ( [
386+ {
387+ name : "prefers the main clone when a worktree of the same repo was added first" ,
388+ folders : [ worktree , mainClone , unrelated ] ,
389+ groupId : "posthog/code" ,
390+ expected : mainClone ,
391+ } ,
392+ {
393+ name : "falls back to the worktree when only it is registered" ,
394+ folders : [ worktree , unrelated ] ,
395+ groupId : "posthog/code" ,
396+ expected : worktree ,
397+ } ,
398+ {
399+ name : "matches folders without a remote by path" ,
400+ folders : [ local ] ,
401+ groupId : "/repos/local" ,
402+ expected : local ,
403+ } ,
404+ {
405+ name : "returns undefined when nothing matches" ,
406+ folders : [ unrelated ] ,
407+ groupId : "posthog/code" ,
408+ expected : undefined ,
409+ } ,
410+ ] ) ( "$name" , ( { folders, groupId, expected } ) => {
411+ expect ( findGroupFolder ( folders , groupId ) ) . toBe ( expected ) ;
392412 } ) ;
393413} ) ;
0 commit comments