@@ -7,7 +7,13 @@ import {
77import { OrganizationFixture } from 'sentry-fixture/organization' ;
88import { ProjectFixture } from 'sentry-fixture/project' ;
99
10- import { render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
10+ import {
11+ render ,
12+ screen ,
13+ userEvent ,
14+ waitFor ,
15+ within ,
16+ } from 'sentry-test/reactTestingLibrary' ;
1117import { selectEvent } from 'sentry-test/selectEvent' ;
1218
1319import { OrganizationStore } from 'sentry/stores/organizationStore' ;
@@ -103,6 +109,27 @@ describe('DetectorEdit', () => {
103109 } ) ;
104110 } ) ;
105111
112+ it ( 'selects the first project when an invalid project is provided in the URL' , async ( ) => {
113+ render ( < DetectorNewSettings /> , {
114+ organization,
115+ initialRouterConfig : {
116+ ...initialRouterConfig ,
117+ location : {
118+ ...initialRouterConfig . location ,
119+ query : { detectorType : 'metric_issue' , project : 'not-a-project-id' } ,
120+ } ,
121+ } ,
122+ } ) ;
123+
124+ await screen . findByText ( 'New Monitor' ) ;
125+
126+ // Verify the project dropdown has the first project selected
127+ const projectSection = screen
128+ . getByText ( / C h o o s e t h e P r o j e c t a n d E n v i r o n m e n t / )
129+ . closest ( 'section' ) ! ;
130+ expect ( within ( projectSection ) . getByText ( project . slug ) ) . toBeInTheDocument ( ) ;
131+ } ) ;
132+
106133 describe ( 'Metric Detector' , ( ) => {
107134 const metricRouterConfig = {
108135 ...initialRouterConfig ,
0 commit comments