3131 'team_id ' => $ this ->team ->id ,
3232 ]);
3333
34- $ this ->githubApp = GithubApp::create ([
34+ $ this ->githubApp = GithubApp::forceCreate ([
3535 'name ' => 'Test GitHub App ' ,
3636 'api_url ' => 'https://api.github.com ' ,
3737 'html_url ' => 'https://github.com ' ,
@@ -86,25 +86,63 @@ function fakeGithubHttp(array $repositories): void
8686 ['id ' => 1 , 'name ' => 'alpha-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
8787 ];
8888
89- fakeGithubHttp ($ initialRepos );
89+ $ updatedRepos = [
90+ ['id ' => 1 , 'name ' => 'alpha-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
91+ ['id ' => 2 , 'name ' => 'beta-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
92+ ['id ' => 3 , 'name ' => 'gamma-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
93+ ];
94+
95+ $ callCount = 0 ;
96+ Http::fake ([
97+ 'https://api.github.com/zen ' => Http::response ('Keep it logically awesome. ' , 200 , [
98+ 'Date ' => now ()->toRfc7231String (),
99+ ]),
100+ 'https://api.github.com/app/installations/67890/access_tokens ' => Http::response ([
101+ 'token ' => 'fake-installation-token ' ,
102+ ], 201 ),
103+ 'https://api.github.com/installation/repositories* ' => function () use (&$ callCount , $ initialRepos , $ updatedRepos ) {
104+ $ callCount ++;
105+ $ repos = $ callCount === 1 ? $ initialRepos : $ updatedRepos ;
106+
107+ return Http::response ([
108+ 'total_count ' => count ($ repos ),
109+ 'repositories ' => $ repos ,
110+ ], 200 );
111+ },
112+ ]);
90113
91114 $ component = Livewire::test (GithubPrivateRepository::class, ['type ' => 'private-gh-app ' ])
92115 ->call ('loadRepositories ' , $ this ->githubApp ->id )
93116 ->assertSet ('total_repositories_count ' , 1 );
94117
95118 // Simulate new repos becoming available after changing access on GitHub
96- $ updatedRepos = [
119+ $ component
120+ ->call ('loadRepositories ' , $ this ->githubApp ->id )
121+ ->assertSet ('total_repositories_count ' , 3 )
122+ ->assertSet ('current_step ' , 'repository ' );
123+ });
124+
125+ test ('loadRepositories resets branches when refreshing ' , function () {
126+ $ repos = [
97127 ['id ' => 1 , 'name ' => 'alpha-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
98- ['id ' => 2 , 'name ' => 'beta-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
99- ['id ' => 3 , 'name ' => 'gamma-repo ' , 'owner ' => ['login ' => 'testuser ' ]],
100128 ];
101129
102- fakeGithubHttp ($ updatedRepos );
130+ fakeGithubHttp ($ repos );
131+
132+ $ component = Livewire::test (GithubPrivateRepository::class, ['type ' => 'private-gh-app ' ])
133+ ->call ('loadRepositories ' , $ this ->githubApp ->id );
134+
135+ // Manually set branches to simulate a previous branch load
136+ $ component ->set ('branches ' , collect ([['name ' => 'main ' ], ['name ' => 'develop ' ]]));
137+ $ component ->set ('total_branches_count ' , 2 );
138+
139+ // Refresh repositories should reset branches
140+ fakeGithubHttp ($ repos );
103141
104142 $ component
105143 ->call ('loadRepositories ' , $ this ->githubApp ->id )
106- ->assertSet ('total_repositories_count ' , 3 )
107- ->assertSet ('current_step ' , ' repository ' );
144+ ->assertSet ('total_branches_count ' , 0 )
145+ ->assertSet ('branches ' , collect () );
108146 });
109147
110148 test ('refresh button is visible when repositories are loaded ' , function () {
@@ -116,11 +154,11 @@ function fakeGithubHttp(array $repositories): void
116154
117155 Livewire::test (GithubPrivateRepository::class, ['type ' => 'private-gh-app ' ])
118156 ->call ('loadRepositories ' , $ this ->githubApp ->id )
119- ->assertSeeHtml ( ' title=" Refresh Repository List" ' );
157+ ->assertSee ( ' Refresh Repository List ' );
120158 });
121159
122160 test ('refresh button is not visible before repositories are loaded ' , function () {
123161 Livewire::test (GithubPrivateRepository::class, ['type ' => 'private-gh-app ' ])
124- ->assertDontSeeHtml ( ' title=" Refresh Repository List" ' );
162+ ->assertDontSee ( ' Refresh Repository List ' );
125163 });
126164});
0 commit comments