@@ -16,13 +16,7 @@ vi.mock("@/entities/branches/ui/queries/get-branches.query");
1616const defaultBranch = generateBranch ( { id : "branch-default" , name : "primary" , is_default : true } ) ;
1717const featureBranch = generateBranch ( { id : "branch-feature" , name : "feature-1" } ) ;
1818
19- type BranchesQueryState = {
20- data ?: Array < BranchListItem > ;
21- isPending : boolean ;
22- error : Error | null ;
23- } ;
24-
25- const mockBranchesQuery = ( state : BranchesQueryState ) =>
19+ const mockBranchesQuery = ( state : Partial < ReturnType < typeof useGetBranches > > ) =>
2620 vi . mocked ( useGetBranches ) . mockReturnValue ( state as ReturnType < typeof useGetBranches > ) ;
2721
2822const mockFetchedBranches = ( ) =>
@@ -85,6 +79,23 @@ describe("BranchesProvider", () => {
8579 await expect . element ( component . getByText ( "Current branch: feature-1" ) ) . toBeVisible ( ) ;
8680 } ) ;
8781
82+ test ( "resolves the default branch when the URL names it explicitly" , async ( ) => {
83+ // GIVEN
84+ mockFetchedBranches ( ) ;
85+ seedBranchInUrl ( defaultBranch . name ) ;
86+
87+ // WHEN
88+ const component = await render (
89+ < BranchesProvider >
90+ < BranchProbe />
91+ </ BranchesProvider >
92+ ) ;
93+
94+ // THEN
95+ await expect . element ( component . getByText ( "Current branch: primary" ) ) . toBeVisible ( ) ;
96+ expect ( getBranchInUrl ( ) ) . toBe ( "primary" ) ;
97+ } ) ;
98+
8899 test ( "hides its children while the branches are being fetched" , async ( ) => {
89100 // GIVEN
90101 mockBranchesQuery ( { isPending : true , error : null } ) ;
@@ -101,6 +112,27 @@ describe("BranchesProvider", () => {
101112 expect ( component . getByText ( / C u r r e n t b r a n c h / ) . query ( ) ) . toBeNull ( ) ;
102113 } ) ;
103114
115+ test ( "keeps its children mounted while the branches are refetched in the background" , async ( ) => {
116+ // GIVEN
117+ mockBranchesQuery ( {
118+ data : [ defaultBranch , featureBranch ] ,
119+ isPending : false ,
120+ isFetching : true ,
121+ error : null ,
122+ } ) ;
123+
124+ // WHEN
125+ const component = await render (
126+ < BranchesProvider >
127+ < BranchProbe />
128+ </ BranchesProvider >
129+ ) ;
130+
131+ // THEN
132+ await expect . element ( component . getByText ( "Current branch: primary" ) ) . toBeVisible ( ) ;
133+ expect ( component . getByText ( "Loading branches..." ) . query ( ) ) . toBeNull ( ) ;
134+ } ) ;
135+
104136 test ( "shows an error screen when the branches cannot be fetched" , async ( ) => {
105137 // GIVEN
106138 mockBranchesQuery ( { isPending : false , error : new Error ( "Branches are unreachable" ) } ) ;
0 commit comments