|
| 1 | +import { test, expect } from '@/e2e/helper'; |
| 2 | + |
| 3 | +test.describe('Acceptance | crate report dialog', { tag: '@acceptance' }, () => { |
| 4 | + test.beforeEach(async ({ mirage }) => { |
| 5 | + await mirage.addHook(server => { |
| 6 | + let crate = server.create('crate', { name: 'nanomsg' }); |
| 7 | + server.create('version', { crate, num: '0.6.0' }); |
| 8 | + }); |
| 9 | + }); |
| 10 | + |
| 11 | + test('display a report form in dialog', async ({ page, percy, a11y }) => { |
| 12 | + await page.goto('/crates/nanomsg'); |
| 13 | + await page.click('[data-test-report-button]'); |
| 14 | + |
| 15 | + const dialogContent = page.locator('[data-test-dialog-content]'); |
| 16 | + await expect(dialogContent.locator('[data-test-reasons-group]')).toBeVisible(); |
| 17 | + await expect(dialogContent.locator('[data-test-detail-group]')).toBeVisible(); |
| 18 | + await expect(dialogContent.locator('[data-test-cancel]')).toHaveText('Cancel'); |
| 19 | + await expect(dialogContent.locator('[data-test-report]')).toHaveText('Report'); |
| 20 | + |
| 21 | + await percy.snapshot(); |
| 22 | + await a11y.audit(); |
| 23 | + }); |
| 24 | + |
| 25 | + test('empty reasons selected shows an error', async ({ page }) => { |
| 26 | + await page.goto('/crates/nanomsg/'); |
| 27 | + await page.click('[data-test-report-button]'); |
| 28 | + |
| 29 | + const dialogContent = page.locator('[data-test-dialog-content]'); |
| 30 | + await dialogContent.locator('[data-test-report]').click(); |
| 31 | + await expect(dialogContent.locator('[data-test-reasons-group] [data-test-error]')).toBeVisible(); |
| 32 | + await expect(dialogContent.locator('[data-test-detail-group] [data-test-error]')).toHaveCount(0); |
| 33 | + }); |
| 34 | + |
| 35 | + test('other reason selected without given detail shows an error', async ({ page }) => { |
| 36 | + await page.goto('/crates/nanomsg/'); |
| 37 | + await page.click('[data-test-report-button]'); |
| 38 | + |
| 39 | + const dialogContent = page.locator('[data-test-dialog-content]'); |
| 40 | + await dialogContent.locator('[data-test-reason="spam"]').click(); |
| 41 | + await dialogContent.locator('[data-test-reason="other"]').click(); |
| 42 | + await dialogContent.locator('[data-test-report]').click(); |
| 43 | + await expect(dialogContent.locator('[data-test-reasons-group] [data-test-error]')).toHaveCount(0); |
| 44 | + await expect(dialogContent.locator('[data-test-detail-group] [data-test-error]')).toBeVisible(); |
| 45 | + }); |
| 46 | + |
| 47 | + test('valid report form should compose a mail and open', async ({ page }) => { |
| 48 | + // mock `window.open()` |
| 49 | + await page.addInitScript(() => { |
| 50 | + globalThis.open = (url, target, features) => { |
| 51 | + globalThis.openKwargs = { url, target, features }; |
| 52 | + return { document: { write() {}, close() {} }, close() {} } as ReturnType<(typeof globalThis)['open']>; |
| 53 | + }; |
| 54 | + }); |
| 55 | + |
| 56 | + await page.goto('/crates/nanomsg/'); |
| 57 | + await page.click('[data-test-report-button]'); |
| 58 | + |
| 59 | + const dialogContent = page.locator('[data-test-dialog-content]'); |
| 60 | + await dialogContent.locator('[data-test-reason="spam"]').click(); |
| 61 | + await dialogContent.locator('[data-test-reason="other"]').click(); |
| 62 | + await dialogContent.locator('[data-test-detail]').fill('test detail'); |
| 63 | + await dialogContent.locator('[data-test-report]').click(); |
| 64 | + |
| 65 | + let body = `I'm reporting the https://crates.io/crates/nanomsg crate because: |
| 66 | +
|
| 67 | +- [x] it contains spam |
| 68 | +- [ ] it is name-squatting (reserving a crate name without content) |
| 69 | +- [ ] it is abusive or otherwise harmful |
| 70 | +- [ ] it contains a vulnerability (please try to contact the crate author first) |
| 71 | +- [x] it is violating the usage policy in some other way (please specify below) |
| 72 | +
|
| 73 | +Additional details: |
| 74 | +
|
| 75 | +test detail |
| 76 | +`; |
| 77 | + let subject = `The "nanomsg" crate`; |
| 78 | + let address = 'help@crates.io'; |
| 79 | + let mailto = `mailto:${address}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`; |
| 80 | + // wait for `window.open()` to be called |
| 81 | + await page.waitForFunction(expect => globalThis.openKwargs.url === expect, mailto); |
| 82 | + await page.waitForFunction(expect => globalThis.openKwargs.target === expect, '_self'); |
| 83 | + await expect(dialogContent).not.toBeVisible(); |
| 84 | + }); |
| 85 | +}); |
0 commit comments