|
| 1 | +import { expect, test } from '@/e2e/helper'; |
| 2 | +import { http, HttpResponse } from 'msw'; |
| 3 | + |
| 4 | +test.describe('Acceptance | crate security page', { tag: '@acceptance' }, () => { |
| 5 | + test('show some advisories', async ({ page, msw, percy }) => { |
| 6 | + let crate = await msw.db.crate.create({ name: 'foo' }); |
| 7 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 8 | + |
| 9 | + let advisories = [ |
| 10 | + { |
| 11 | + id: 'TEST-001', |
| 12 | + summary: 'First test advisory', |
| 13 | + details: 'This is the first test advisory with **markdown** support.', |
| 14 | + }, |
| 15 | + { |
| 16 | + id: 'TEST-002', |
| 17 | + summary: 'Second test advisory', |
| 18 | + details: 'This is the second test advisory with more details.', |
| 19 | + }, |
| 20 | + ]; |
| 21 | + |
| 22 | + msw.worker.use( |
| 23 | + http.get('https://rustsec.org/packages/:crateId.json', () => HttpResponse.json(advisories)), |
| 24 | + ); |
| 25 | + |
| 26 | + await page.goto('/crates/foo/security'); |
| 27 | + |
| 28 | + await expect(page.locator('[data-test-list] li')).toHaveCount(2); |
| 29 | + |
| 30 | + // Check first advisory |
| 31 | + await expect(page.locator('[data-test-list] li').nth(0).locator('h3 a')).toHaveAttribute( |
| 32 | + 'href', |
| 33 | + 'https://rustsec.org/advisories/TEST-001.html', |
| 34 | + ); |
| 35 | + await expect(page.locator('[data-test-list] li').nth(0).locator('h3 a')).toContainText('TEST-001'); |
| 36 | + await expect(page.locator('[data-test-list] li').nth(0).locator('h3')).toContainText('First test advisory'); |
| 37 | + await expect(page.locator('[data-test-list] li').nth(0).locator('p')).toContainText('markdown'); |
| 38 | + |
| 39 | + // Check second advisory |
| 40 | + await expect(page.locator('[data-test-list] li').nth(1).locator('h3 a')).toHaveAttribute( |
| 41 | + 'href', |
| 42 | + 'https://rustsec.org/advisories/TEST-002.html', |
| 43 | + ); |
| 44 | + await expect(page.locator('[data-test-list] li').nth(1).locator('h3 a')).toContainText('TEST-002'); |
| 45 | + await expect(page.locator('[data-test-list] li').nth(1).locator('h3')).toContainText('Second test advisory'); |
| 46 | + |
| 47 | + await percy.snapshot(); |
| 48 | + }); |
| 49 | + |
| 50 | + test('show no advisory data when none exist', async ({ page, msw }) => { |
| 51 | + let crate = await msw.db.crate.create({ name: 'safe-crate' }); |
| 52 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 53 | + |
| 54 | + msw.worker.use( |
| 55 | + http.get('https://rustsec.org/packages/:crateId.json', () => HttpResponse.text('not found', { status: 404 })), |
| 56 | + ); |
| 57 | + |
| 58 | + await page.goto('/crates/safe-crate/security'); |
| 59 | + |
| 60 | + await expect(page.locator('[data-no-advisories]')).toBeVisible(); |
| 61 | + await expect(page.locator('[data-no-advisories]')).toHaveText('No advisories found for this crate.'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('handles errors gracefully', async ({ page, msw }) => { |
| 65 | + let crate = await msw.db.crate.create({ name: 'error-crate' }); |
| 66 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 67 | + |
| 68 | + msw.worker.use( |
| 69 | + http.get('https://rustsec.org/packages/:crateId.json', () => |
| 70 | + HttpResponse.text('Internal Server Error', { status: 500 }), |
| 71 | + ), |
| 72 | + ); |
| 73 | + |
| 74 | + await page.goto('/crates/error-crate/security'); |
| 75 | + |
| 76 | + // When there's an error, the route catches it and returns empty advisories |
| 77 | + await expect(page.locator('[data-error]')).toBeVisible(); |
| 78 | + await expect(page.locator('[data-error]')).toHaveText('An error occurred while fetching advisories.'); |
| 79 | + }); |
| 80 | +}); |
0 commit comments