@@ -177,6 +177,66 @@ describe("SecurityPage", () => {
177177 await waitFor ( ( ) => expect ( analyticsOverviewMock ) . toHaveBeenCalledWith ( "acme" , "" ) ) ;
178178 } ) ;
179179
180+ it ( "drops the previous owner's scan results and stops querying for them when the owner changes (#549)" , async ( ) => {
181+ analyticsOverviewMock . mockResolvedValue ( {
182+ owner : "acme" , score : 50 , total_checks : 1 , failed_checks : 1 , repo_count : 1 ,
183+ checks : [ { id : "c1" , title : "Acme-only check" , severity : "high" , remediation : "" , status : "fail" , value : { type : "boolean" , enabled : false } } ] ,
184+ } ) ;
185+ securityMatrixMock . mockResolvedValue ( {
186+ owner : "acme" ,
187+ repos : [ {
188+ repo : "acme-repo" , branch_protection : true , secret_scanning : true , dependabot_enabled : true ,
189+ dependabot_critical_count : 0 , dependabot_high_count : 0 , code_scanning : true , force_push_allowed : false ,
190+ score : 100 , unknown_dimensions : [ ] , alerts_source : "github" ,
191+ } ] ,
192+ summary : { fully_compliant_count : 1 , critical_risk_count : 0 , secret_hits_count : 0 , vuln_by_severity : { critical : 0 , high : 0 , medium : 0 , low : 0 } } ,
193+ } ) ;
194+
195+ renderPage ( ) ;
196+ const ownerInput = screen . getByPlaceholderText ( "e.g. octocat" ) ;
197+ fireEvent . change ( ownerInput , { target : { value : "acme" } } ) ;
198+ const scanButton = screen . getByRole ( "button" , { name : / r u n s c a n / i } ) ;
199+ await waitFor ( ( ) => expect ( scanButton ) . not . toBeDisabled ( ) ) ;
200+ fireEvent . click ( scanButton ) ;
201+ expect ( await screen . findByText ( "Acme-only check" ) ) . toBeInTheDocument ( ) ;
202+ await waitFor ( ( ) => expect ( secretScanningMock ) . toHaveBeenCalledWith ( "acme" , "acme-repo" , "" ) ) ;
203+
204+ secretScanningMock . mockClear ( ) ;
205+ fireEvent . change ( ownerInput , { target : { value : "beta" } } ) ;
206+
207+ await waitFor ( ( ) => expect ( screen . queryByText ( "Acme-only check" ) ) . not . toBeInTheDocument ( ) ) ;
208+ expect ( secretScanningMock ) . not . toHaveBeenCalled ( ) ;
209+ } ) ;
210+
211+ it ( "shows a scan failure for the owner it was run for, and drops it once the owner changes (#549)" , async ( ) => {
212+ analyticsOverviewMock . mockRejectedValue ( new Error ( "scan exploded" ) ) ;
213+
214+ renderPage ( ) ;
215+ const ownerInput = screen . getByPlaceholderText ( "e.g. octocat" ) ;
216+ fireEvent . change ( ownerInput , { target : { value : "acme" } } ) ;
217+ const scanButton = screen . getByRole ( "button" , { name : / r u n s c a n / i } ) ;
218+ await waitFor ( ( ) => expect ( scanButton ) . not . toBeDisabled ( ) ) ;
219+ fireEvent . click ( scanButton ) ;
220+
221+ expect ( await screen . findByTestId ( "scan-error" ) ) . toHaveTextContent ( "scan exploded" ) ;
222+
223+ fireEvent . change ( ownerInput , { target : { value : "beta" } } ) ;
224+ await waitFor ( ( ) => expect ( screen . queryByTestId ( "scan-error" ) ) . not . toBeInTheDocument ( ) ) ;
225+ } ) ;
226+
227+ it ( "shows the results card with a pending state while a scan is running (#549)" , async ( ) => {
228+ analyticsOverviewMock . mockReturnValue ( new Promise ( ( ) => { } ) ) ; // never settles
229+
230+ renderPage ( ) ;
231+ fireEvent . change ( screen . getByPlaceholderText ( "e.g. octocat" ) , { target : { value : "acme" } } ) ;
232+ const scanButton = screen . getByRole ( "button" , { name : / r u n s c a n / i } ) ;
233+ await waitFor ( ( ) => expect ( scanButton ) . not . toBeDisabled ( ) ) ;
234+ fireEvent . click ( scanButton ) ;
235+
236+ await waitFor ( ( ) => expect ( screen . getByRole ( "button" , { name : / s c a n n i n g / i } ) ) . toBeInTheDocument ( ) ) ;
237+ expect ( analyticsOverviewMock ) . toHaveBeenCalledWith ( "acme" , "" ) ;
238+ } ) ;
239+
180240 it ( "runs a scan on Enter in the organization field with no token entered" , async ( ) => {
181241 analyticsOverviewMock . mockResolvedValue ( {
182242 owner : "acme" ,
0 commit comments