11import { test , expect } from '@/e2e/helper' ;
22
33test . describe ( 'Acceptance | support page' , { tag : '@acceptance' } , ( ) => {
4+ test . beforeEach ( async ( { page, msw } ) => {
5+ let crate = msw . db . crate . create ( { name : 'nanomsg' } ) ;
6+ msw . db . version . create ( { crate, num : '0.6.0' } ) ;
7+
8+ // mock `window.open()`
9+ await page . addInitScript ( ( ) => {
10+ globalThis . open = ( url , target , features ) => {
11+ globalThis . openKwargs = { url, target, features } ;
12+ return { document : { write ( ) { } , close ( ) { } } , close ( ) { } } as ReturnType < ( typeof globalThis ) [ 'open' ] > ;
13+ } ;
14+ } ) ;
15+ } ) ;
16+
417 test ( 'shows an inquire list' , async ( { page, percy, a11y } ) => {
518 await page . goto ( '/support' ) ;
619 await expect ( page ) . toHaveURL ( '/support' ) ;
@@ -32,17 +45,6 @@ test.describe('Acceptance | support page', { tag: '@acceptance' }, () => {
3245
3346 test . describe ( 'reporting a crate from support page' , ( ) => {
3447 test . beforeEach ( async ( { page, msw } ) => {
35- let crate = msw . db . crate . create ( { name : 'nanomsg' } ) ;
36- msw . db . version . create ( { crate, num : '0.6.0' } ) ;
37-
38- // mock `window.open()`
39- await page . addInitScript ( ( ) => {
40- globalThis . open = ( url , target , features ) => {
41- globalThis . openKwargs = { url, target, features } ;
42- return { document : { write ( ) { } , close ( ) { } } , close ( ) { } } as ReturnType < ( typeof globalThis ) [ 'open' ] > ;
43- } ;
44- } ) ;
45-
4648 await page . goto ( '/support' ) ;
4749 await page . getByTestId ( 'link-crate-violation' ) . click ( ) ;
4850 await expect ( page ) . toHaveURL ( '/support?inquire=crate-violation' ) ;
@@ -130,7 +132,8 @@ test.describe('Acceptance | support page', { tag: '@acceptance' }, () => {
130132- [x] it contains spam
131133- [ ] it is name-squatting (reserving a crate name without content)
132134- [ ] it is abusive or otherwise harmful
133- - [ ] it contains a vulnerability (please try to contact the crate author first)
135+ - [ ] it contains malicious code
136+ - [ ] it contains a vulnerability
134137- [ ] it is violating the usage policy in some other way (please specify below)
135138
136139Additional details:
@@ -174,7 +177,8 @@ Additional details:
174177- [x] it contains spam
175178- [ ] it is name-squatting (reserving a crate name without content)
176179- [ ] it is abusive or otherwise harmful
177- - [ ] it contains a vulnerability (please try to contact the crate author first)
180+ - [ ] it contains malicious code
181+ - [ ] it contains a vulnerability
178182- [x] it is violating the usage policy in some other way (please specify below)
179183
180184Additional details:
@@ -193,17 +197,6 @@ test detail
193197
194198 test . describe ( 'reporting a crate from crate page' , ( ) => {
195199 test . beforeEach ( async ( { page, msw } ) => {
196- let crate = msw . db . crate . create ( { name : 'nanomsg' } ) ;
197- msw . db . version . create ( { crate, num : '0.6.0' } ) ;
198-
199- // mock `window.open()`
200- await page . addInitScript ( ( ) => {
201- globalThis . open = ( url , target , features ) => {
202- globalThis . openKwargs = { url, target, features } ;
203- return { document : { write ( ) { } , close ( ) { } } , close ( ) { } } as ReturnType < ( typeof globalThis ) [ 'open' ] > ;
204- } ;
205- } ) ;
206-
207200 await page . goto ( '/crates/nanomsg' ) ;
208201 await page . getByTestId ( 'link-crate-report' ) . click ( ) ;
209202 await expect ( page ) . toHaveURL ( '/support?crate=nanomsg&inquire=crate-violation' ) ;
@@ -263,7 +256,8 @@ test detail
263256- [x] it contains spam
264257- [ ] it is name-squatting (reserving a crate name without content)
265258- [ ] it is abusive or otherwise harmful
266- - [ ] it contains a vulnerability (please try to contact the crate author first)
259+ - [ ] it contains malicious code
260+ - [ ] it contains a vulnerability
267261- [ ] it is violating the usage policy in some other way (please specify below)
268262
269263Additional details:
@@ -303,7 +297,8 @@ Additional details:
303297- [x] it contains spam
304298- [ ] it is name-squatting (reserving a crate name without content)
305299- [ ] it is abusive or otherwise harmful
306- - [ ] it contains a vulnerability (please try to contact the crate author first)
300+ - [ ] it contains malicious code
301+ - [ ] it contains a vulnerability
307302- [x] it is violating the usage policy in some other way (please specify below)
308303
309304Additional details:
@@ -319,4 +314,65 @@ test detail
319314 await page . waitForFunction ( expect => globalThis . openKwargs . target === expect , '_self' ) ;
320315 } ) ;
321316 } ) ;
317+
318+ test ( 'valid form with required detail' , async ( { page } ) => {
319+ await page . goto ( '/support' ) ;
320+ await page . getByTestId ( 'link-crate-violation' ) . click ( ) ;
321+ await expect ( page ) . toHaveURL ( '/support?inquire=crate-violation' ) ;
322+
323+ const crateInput = page . getByTestId ( 'crate-input' ) ;
324+ await crateInput . fill ( 'nanomsg' ) ;
325+ await expect ( crateInput ) . toHaveValue ( 'nanomsg' ) ;
326+ const checkbox = page . getByTestId ( 'malicious-code-checkbox' ) ;
327+ await checkbox . check ( ) ;
328+ await expect ( checkbox ) . toBeChecked ( ) ;
329+ const detailInput = page . getByTestId ( 'detail-input' ) ;
330+ await detailInput . fill ( 'test detail' ) ;
331+ await expect ( detailInput ) . toHaveValue ( 'test detail' ) ;
332+
333+ await page . waitForFunction ( ( ) => globalThis . openKwargs === undefined ) ;
334+ const reportButton = page . getByTestId ( 'report-button' ) ;
335+ await reportButton . click ( ) ;
336+
337+ await expect ( page . getByTestId ( 'crate-invalid' ) ) . not . toBeVisible ( ) ;
338+ await expect ( page . getByTestId ( 'reasons-invalid' ) ) . not . toBeVisible ( ) ;
339+ await expect ( page . getByTestId ( 'detail-invalid' ) ) . not . toBeVisible ( ) ;
340+
341+ let body = `I'm reporting the https://crates.io/crates/nanomsg crate because:
342+
343+ - [ ] it contains spam
344+ - [ ] it is name-squatting (reserving a crate name without content)
345+ - [ ] it is abusive or otherwise harmful
346+ - [x] it contains malicious code
347+ - [ ] it contains a vulnerability
348+ - [ ] it is violating the usage policy in some other way (please specify below)
349+
350+ Additional details:
351+
352+ test detail
353+ ` ;
354+ let subject = `[SECURITY] The "nanomsg" crate` ;
355+ 356+ let mailto = `mailto:${ addresses } ?subject=${ encodeURIComponent ( subject ) } &body=${ encodeURIComponent ( body ) } ` ;
357+ // wait for `window.open()` to be called
358+ await page . waitForFunction ( ( ) => ! ! globalThis . openKwargs ) ;
359+ await page . waitForFunction ( expect => globalThis . openKwargs . url === expect , mailto ) ;
360+ await page . waitForFunction ( expect => globalThis . openKwargs . target === expect , '_self' ) ;
361+ } ) ;
362+
363+ test ( 'shows help text for vulnerability reports' , async ( { page } ) => {
364+ await page . goto ( '/support' ) ;
365+ await page . getByTestId ( 'link-crate-violation' ) . click ( ) ;
366+ await expect ( page ) . toHaveURL ( '/support?inquire=crate-violation' ) ;
367+
368+ const crateInput = page . getByTestId ( 'crate-input' ) ;
369+ await crateInput . fill ( 'nanomsg' ) ;
370+ await expect ( crateInput ) . toHaveValue ( 'nanomsg' ) ;
371+ await expect ( page . getByTestId ( 'vulnerability-report' ) ) . not . toBeVisible ( ) ;
372+
373+ const checkbox = page . getByTestId ( 'vulnerability-checkbox' ) ;
374+ await checkbox . check ( ) ;
375+ await expect ( checkbox ) . toBeChecked ( ) ;
376+ await expect ( page . getByTestId ( 'vulnerability-report' ) ) . toBeVisible ( ) ;
377+ } ) ;
322378} ) ;
0 commit comments