@@ -4,6 +4,7 @@ import {initializeOrg} from 'sentry-test/initializeOrg';
4
4
import { act , render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
5
5
6
6
import { addErrorMessage } from 'sentry/actionCreators/indicator' ;
7
+ import ProjectsStore from 'sentry/stores/projectsStore' ;
7
8
import { metric } from 'sentry/utils/analytics' ;
8
9
import RuleFormContainer from 'sentry/views/alerts/rules/metric/ruleForm' ;
9
10
import { permissionAlertText } from 'sentry/views/settings/project/permissionAlert' ;
@@ -38,6 +39,7 @@ describe('Incident Rules Form', () => {
38
39
} ) ;
39
40
organization = initialData . organization ;
40
41
project = initialData . project ;
42
+ ProjectsStore . loadInitialData ( [ project ] ) ;
41
43
routerContext = initialData . routerContext ;
42
44
MockApiClient . addMockResponse ( {
43
45
url : '/organizations/org-slug/tags/' ,
@@ -113,10 +115,22 @@ describe('Incident Rules Form', () => {
113
115
describe ( 'Creating a new rule' , ( ) => {
114
116
let createRule ;
115
117
beforeEach ( ( ) => {
118
+ ProjectsStore . loadInitialData ( [
119
+ project ,
120
+ {
121
+ ...project ,
122
+ id : '10' ,
123
+ slug : 'project-slug-2' ,
124
+ } ,
125
+ ] ) ;
116
126
createRule = MockApiClient . addMockResponse ( {
117
127
url : '/organizations/org-slug/alert-rules/' ,
118
128
method : 'POST' ,
119
129
} ) ;
130
+ MockApiClient . addMockResponse ( {
131
+ url : '/projects/org-slug/project-slug-2/environments/' ,
132
+ body : [ ] ,
133
+ } ) ;
120
134
} ) ;
121
135
122
136
/**
@@ -160,6 +174,43 @@ describe('Incident Rules Form', () => {
160
174
expect ( metric . startTransaction ) . toHaveBeenCalledWith ( { name : 'saveAlertRule' } ) ;
161
175
} ) ;
162
176
177
+ it ( 'can create a rule for a different project' , async ( ) => {
178
+ const rule = TestStubs . MetricRule ( ) ;
179
+ createWrapper ( {
180
+ rule : {
181
+ ...rule ,
182
+ id : undefined ,
183
+ eventTypes : [ 'default' ] ,
184
+ } ,
185
+ } ) ;
186
+
187
+ // Clear field
188
+ await userEvent . clear ( screen . getByPlaceholderText ( 'Enter Alert Name' ) ) ;
189
+
190
+ // Enter in name so we can submit
191
+ await userEvent . type (
192
+ screen . getByPlaceholderText ( 'Enter Alert Name' ) ,
193
+ 'Incident Rule'
194
+ ) ;
195
+
196
+ // Change project
197
+ await userEvent . click ( screen . getByText ( 'project-slug' ) ) ;
198
+ await userEvent . click ( screen . getByText ( 'project-slug-2' ) ) ;
199
+
200
+ await userEvent . click ( screen . getByLabelText ( 'Save Rule' ) ) ;
201
+
202
+ expect ( createRule ) . toHaveBeenCalledWith (
203
+ expect . anything ( ) ,
204
+ expect . objectContaining ( {
205
+ data : expect . objectContaining ( {
206
+ name : 'Incident Rule' ,
207
+ projects : [ 'project-slug-2' ] ,
208
+ } ) ,
209
+ } )
210
+ ) ;
211
+ expect ( metric . startTransaction ) . toHaveBeenCalledWith ( { name : 'saveAlertRule' } ) ;
212
+ } ) ;
213
+
163
214
it ( 'creates a rule with generic_metrics dataset' , async ( ) => {
164
215
organization . features = [ ...organization . features , 'mep-rollout-flag' ] ;
165
216
const rule = TestStubs . MetricRule ( ) ;
0 commit comments