|
| 1 | +import { expect, test } from '@/e2e/helper'; |
| 2 | +import { http, HttpResponse } from 'msw'; |
| 3 | + |
| 4 | +test.describe('Route | crate.version | source link', { tag: '@routes' }, () => { |
| 5 | + test('show docs.rs source link even if non-docs.rs documentation link is specified', async ({ page, msw }) => { |
| 6 | + let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://foo.io/docs' }); |
| 7 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 8 | + |
| 9 | + await page.goto('/crates/foo'); |
| 10 | + await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( |
| 11 | + 'href', |
| 12 | + 'https://docs.rs/crate/foo/1.0.0/source/', |
| 13 | + ); |
| 14 | + }); |
| 15 | + |
| 16 | + test('show no source link if there are no related docs.rs builds', async ({ page, msw }) => { |
| 17 | + let crate = await msw.db.crate.create({ name: 'foo' }); |
| 18 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 19 | + |
| 20 | + let error = HttpResponse.text('not found', { status: 404 }); |
| 21 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
| 22 | + |
| 23 | + await page.goto('/crates/foo'); |
| 24 | + await expect(page.getByRole('link', { name: 'crates.io', exact: true })).toHaveCount(1); |
| 25 | + |
| 26 | + await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); |
| 27 | + }); |
| 28 | + |
| 29 | + test('show source link if `documentation` is unspecified and there are related docs.rs builds', async ({ |
| 30 | + page, |
| 31 | + msw, |
| 32 | + }) => { |
| 33 | + let crate = await msw.db.crate.create({ name: 'foo' }); |
| 34 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 35 | + |
| 36 | + let response = HttpResponse.json({ |
| 37 | + doc_status: true, |
| 38 | + version: '1.0.0', |
| 39 | + }); |
| 40 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
| 41 | + |
| 42 | + await page.goto('/crates/foo'); |
| 43 | + await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( |
| 44 | + 'href', |
| 45 | + 'https://docs.rs/crate/foo/1.0.0/source/', |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + test('show no source link if `documentation` points to docs.rs and there are no related docs.rs builds', async ({ |
| 50 | + page, |
| 51 | + msw, |
| 52 | + }) => { |
| 53 | + let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 54 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 55 | + |
| 56 | + let error = HttpResponse.text('not found', { status: 404 }); |
| 57 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
| 58 | + |
| 59 | + await page.goto('/crates/foo'); |
| 60 | + await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); |
| 61 | + }); |
| 62 | + |
| 63 | + test('show source link if `documentation` points to docs.rs and there are related docs.rs builds', async ({ |
| 64 | + page, |
| 65 | + msw, |
| 66 | + }) => { |
| 67 | + let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 68 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 69 | + |
| 70 | + let response = HttpResponse.json({ |
| 71 | + doc_status: true, |
| 72 | + version: '1.0.0', |
| 73 | + }); |
| 74 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
| 75 | + |
| 76 | + await page.goto('/crates/foo'); |
| 77 | + await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( |
| 78 | + 'href', |
| 79 | + 'https://docs.rs/crate/foo/1.0.0/source', |
| 80 | + ); |
| 81 | + }); |
| 82 | + |
| 83 | + test('ajax errors are ignored, but show no source link', async ({ page, msw }) => { |
| 84 | + let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 85 | + await msw.db.version.create({ crate, num: '1.0.0' }); |
| 86 | + |
| 87 | + let error = HttpResponse.text('error', { status: 500 }); |
| 88 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
| 89 | + |
| 90 | + await page.goto('/crates/foo'); |
| 91 | + await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); |
| 92 | + }); |
| 93 | + |
| 94 | + test('empty docs.rs responses are ignored, still show source link', async ({ page, msw }) => { |
| 95 | + let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 96 | + await msw.db.version.create({ crate, num: '0.6.2' }); |
| 97 | + |
| 98 | + let response = HttpResponse.json({}); |
| 99 | + msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
| 100 | + |
| 101 | + await page.goto('/crates/foo'); |
| 102 | + await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( |
| 103 | + 'href', |
| 104 | + 'https://docs.rs/crate/foo/0.6.2/source/', |
| 105 | + ); |
| 106 | + }); |
| 107 | +}); |
0 commit comments