@@ -178,6 +178,138 @@ Additional details:
178
178
179
179
Additional details:
180
180
181
+ test detail
182
+ ` ;
183
+ let subject = `The "nanomsg" crate` ;
184
+ let address = '[email protected] ' ;
185
+ let mailto = `mailto:${ address } ?subject=${ encodeURIComponent ( subject ) } &body=${ encodeURIComponent ( body ) } ` ;
186
+ // wait for `window.open()` to be called
187
+ await page . waitForFunction ( ( ) => ! ! globalThis . openKwargs ) ;
188
+ await page . waitForFunction ( expect => globalThis . openKwargs . url === expect , mailto ) ;
189
+ await page . waitForFunction ( expect => globalThis . openKwargs . target === expect , '_self' ) ;
190
+ } ) ;
191
+ } ) ;
192
+
193
+ test . describe ( 'reporting a crate from crate page' , ( ) => {
194
+ test . beforeEach ( async ( { page, mirage } ) => {
195
+ await mirage . config ( { trackRequests : true } ) ;
196
+ await mirage . addHook ( server => {
197
+ globalThis . _routes = server . _config . routes ;
198
+ let crate = server . create ( 'crate' , { name : 'nanomsg' } ) ;
199
+ server . create ( 'version' , { crate, num : '0.6.0' } ) ;
200
+ } ) ;
201
+ // mock `window.open()`
202
+ await page . addInitScript ( ( ) => {
203
+ globalThis . open = ( url , target , features ) => {
204
+ globalThis . openKwargs = { url, target, features } ;
205
+ return { document : { write ( ) { } , close ( ) { } } , close ( ) { } } as ReturnType < ( typeof globalThis ) [ 'open' ] > ;
206
+ } ;
207
+ } ) ;
208
+
209
+ await page . goto ( '/crates/nanomsg' ) ;
210
+ await page . getByTestId ( 'link-crate-report' ) . click ( ) ;
211
+ await expect ( page ) . toHaveURL ( '/support?crate=nanomsg&inquire=crate-violation' ) ;
212
+ await expect ( page . getByTestId ( 'crate-input' ) ) . toHaveValue ( 'nanomsg' ) ;
213
+ } ) ;
214
+
215
+ test ( 'empty crate should shows errors' , async ( { page } ) => {
216
+ const crateInput = page . getByTestId ( 'crate-input' ) ;
217
+ await crateInput . fill ( '' ) ;
218
+ await expect ( crateInput ) . toHaveValue ( '' ) ;
219
+ const reportButton = page . getByTestId ( 'report-button' ) ;
220
+ await reportButton . click ( ) ;
221
+
222
+ await expect ( page . getByTestId ( 'crate-invalid' ) ) . toBeVisible ( ) ;
223
+ await expect ( page . getByTestId ( 'reasons-invalid' ) ) . toBeVisible ( ) ;
224
+ await expect ( page . getByTestId ( 'detail-invalid' ) ) . not . toBeVisible ( ) ;
225
+
226
+ await page . waitForFunction ( ( ) => globalThis . openKwargs === undefined ) ;
227
+ } ) ;
228
+
229
+ test ( 'other reason selected without given detail shows an error' , async ( { page } ) => {
230
+ const spam = page . getByTestId ( 'spam-checkbox' ) ;
231
+ await spam . check ( ) ;
232
+ await expect ( spam ) . toBeChecked ( ) ;
233
+ const other = page . getByTestId ( 'other-checkbox' ) ;
234
+ await other . check ( ) ;
235
+ await expect ( other ) . toBeChecked ( ) ;
236
+ const detailInput = page . getByTestId ( 'detail-input' ) ;
237
+ await expect ( detailInput ) . toHaveValue ( '' ) ;
238
+ const reportButton = page . getByTestId ( 'report-button' ) ;
239
+ await reportButton . click ( ) ;
240
+
241
+ await expect ( page . getByTestId ( 'crate-invalid' ) ) . not . toBeVisible ( ) ;
242
+ await expect ( page . getByTestId ( 'reasons-invalid' ) ) . not . toBeVisible ( ) ;
243
+ await expect ( page . getByTestId ( 'detail-invalid' ) ) . toBeVisible ( ) ;
244
+
245
+ await page . waitForFunction ( ( ) => globalThis . openKwargs === undefined ) ;
246
+ } ) ;
247
+
248
+ test ( 'valid form without detail' , async ( { page } ) => {
249
+ const spam = page . getByTestId ( 'spam-checkbox' ) ;
250
+ await spam . check ( ) ;
251
+ await expect ( spam ) . toBeChecked ( ) ;
252
+ const detailInput = page . getByTestId ( 'detail-input' ) ;
253
+ await expect ( detailInput ) . toHaveValue ( '' ) ;
254
+
255
+ await page . waitForFunction ( ( ) => globalThis . openKwargs === undefined ) ;
256
+ const reportButton = page . getByTestId ( 'report-button' ) ;
257
+ await reportButton . click ( ) ;
258
+
259
+ await expect ( page . getByTestId ( 'crate-invalid' ) ) . not . toBeVisible ( ) ;
260
+ await expect ( page . getByTestId ( 'reasons-invalid' ) ) . not . toBeVisible ( ) ;
261
+ await expect ( page . getByTestId ( 'detail-invalid' ) ) . not . toBeVisible ( ) ;
262
+
263
+ let body = `I'm reporting the https://crates.io/crates/nanomsg crate because:
264
+
265
+ - [x] it contains spam
266
+ - [ ] it is name-squatting (reserving a crate name without content)
267
+ - [ ] it is abusive or otherwise harmful
268
+ - [ ] it contains a vulnerability (please try to contact the crate author first)
269
+ - [ ] it is violating the usage policy in some other way (please specify below)
270
+
271
+ Additional details:
272
+
273
+
274
+ ` ;
275
+ let subject = `The "nanomsg" crate` ;
276
+ let address = '[email protected] ' ;
277
+ let mailto = `mailto:${ address } ?subject=${ encodeURIComponent ( subject ) } &body=${ encodeURIComponent ( body ) } ` ;
278
+ // wait for `window.open()` to be called
279
+ await page . waitForFunction ( ( ) => ! ! globalThis . openKwargs ) ;
280
+ await page . waitForFunction ( expect => globalThis . openKwargs . url === expect , mailto ) ;
281
+ await page . waitForFunction ( expect => globalThis . openKwargs . target === expect , '_self' ) ;
282
+ } ) ;
283
+
284
+ test ( 'valid form with required detail' , async ( { page } ) => {
285
+ const spam = page . getByTestId ( 'spam-checkbox' ) ;
286
+ await spam . check ( ) ;
287
+ await expect ( spam ) . toBeChecked ( ) ;
288
+ const other = page . getByTestId ( 'other-checkbox' ) ;
289
+ await other . check ( ) ;
290
+ await expect ( other ) . toBeChecked ( ) ;
291
+ const detailInput = page . getByTestId ( 'detail-input' ) ;
292
+ await detailInput . fill ( 'test detail' ) ;
293
+ await expect ( detailInput ) . toHaveValue ( 'test detail' ) ;
294
+
295
+ await page . waitForFunction ( ( ) => globalThis . openKwargs === undefined ) ;
296
+ const reportButton = page . getByTestId ( 'report-button' ) ;
297
+ await reportButton . click ( ) ;
298
+
299
+ await expect ( page . getByTestId ( 'crate-invalid' ) ) . not . toBeVisible ( ) ;
300
+ await expect ( page . getByTestId ( 'reasons-invalid' ) ) . not . toBeVisible ( ) ;
301
+ await expect ( page . getByTestId ( 'detail-invalid' ) ) . not . toBeVisible ( ) ;
302
+
303
+ let body = `I'm reporting the https://crates.io/crates/nanomsg crate because:
304
+
305
+ - [x] it contains spam
306
+ - [ ] it is name-squatting (reserving a crate name without content)
307
+ - [ ] it is abusive or otherwise harmful
308
+ - [ ] it contains a vulnerability (please try to contact the crate author first)
309
+ - [x] it is violating the usage policy in some other way (please specify below)
310
+
311
+ Additional details:
312
+
181
313
test detail
182
314
` ;
183
315
let subject = `The "nanomsg" crate` ;
0 commit comments