-
Notifications
You must be signed in to change notification settings - Fork 689
Add a link to browse crate source on docs.rs #12550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { expect, test } from '@/e2e/helper'; | ||
| import { http, HttpResponse } from 'msw'; | ||
|
|
||
| test.describe('Route | crate.version | source link', { tag: '@routes' }, () => { | ||
| test('show docs.rs source link even if non-docs.rs documentation link is specified', async ({ page, msw }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://foo.io/docs' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ | ||
| doc_status: false, | ||
| version: '1.0.0', | ||
| }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( | ||
| 'href', | ||
| 'https://docs.rs/crate/foo/1.0.0/source/', | ||
| ); | ||
| }); | ||
|
|
||
| test('show no source link if there are no related docs.rs builds', async ({ page, msw }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('not found', { status: 404 }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.getByRole('link', { name: 'crates.io', exact: true })).toHaveCount(1); | ||
|
|
||
| await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('show source link if `documentation` is unspecified and there are related docs.rs builds', async ({ | ||
| page, | ||
| msw, | ||
| }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ | ||
| doc_status: true, | ||
| version: '1.0.0', | ||
| }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( | ||
| 'href', | ||
| 'https://docs.rs/crate/foo/1.0.0/source/', | ||
| ); | ||
| }); | ||
|
|
||
| test('show no source link if `documentation` points to docs.rs and there are no related docs.rs builds', async ({ | ||
| page, | ||
| msw, | ||
| }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('not found', { status: 404 }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('show source link if `documentation` points to docs.rs and there are related docs.rs builds', async ({ | ||
| page, | ||
| msw, | ||
| }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ | ||
| doc_status: true, | ||
| version: '1.0.0', | ||
| }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( | ||
| 'href', | ||
| 'https://docs.rs/crate/foo/1.0.0/source/', | ||
| ); | ||
| }); | ||
|
|
||
| test('ajax errors are ignored, but show no source link', async ({ page, msw }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await msw.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('error', { status: 500 }); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('empty docs.rs responses are ignored, still show source link', async ({ page, msw }) => { | ||
| let crate = await msw.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await msw.db.version.create({ crate, num: '0.6.2' }); | ||
|
|
||
| let response = HttpResponse.json({}); | ||
| msw.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await page.goto('/crates/foo'); | ||
| await expect(page.locator('[data-test-source-link] a')).toHaveAttribute( | ||
| 'href', | ||
| 'https://docs.rs/crate/foo/0.6.2/source/', | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { visit } from '@ember/test-helpers'; | ||
| import { module, test } from 'qunit'; | ||
|
|
||
| import { http, HttpResponse } from 'msw'; | ||
|
|
||
| import { setupApplicationTest } from 'crates-io/tests/helpers'; | ||
|
|
||
| module('Route | crate.version | source link', function (hooks) { | ||
| setupApplicationTest(hooks); | ||
|
|
||
| test('shows docs.rs source link even if non-docs.rs documentation link is specified', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo', documentation: 'https://foo.io/docs' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ doc_status: false, version: '1.0.0' }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').hasAttribute('href', 'https://docs.rs/crate/foo/1.0.0/source/'); | ||
| }); | ||
|
|
||
| test('show no source link if there are no related docs.rs builds', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('not found', { status: 404 }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').doesNotExist(); | ||
| }); | ||
|
|
||
| test('show source link if `documentation` is unspecified and there are related docs.rs builds', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ doc_status: true, version: '1.0.0' }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').hasAttribute('href', 'https://docs.rs/crate/foo/1.0.0/source/'); | ||
| }); | ||
|
|
||
| test('show no source link if `documentation` points to docs.rs and there are no related docs.rs builds', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('not found', { status: 404 }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').doesNotExist(); | ||
| }); | ||
|
|
||
| test('show source link if `documentation` points to docs.rs and there is a successful docs.rs response', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let response = HttpResponse.json({ doc_status: false, version: '1.0.0' }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').hasAttribute('href', 'https://docs.rs/crate/foo/1.0.0/source/'); | ||
| }); | ||
|
|
||
| test('ajax errors are ignored, but show no source link', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await this.db.version.create({ crate, num: '1.0.0' }); | ||
|
|
||
| let error = HttpResponse.text('error', { status: 500 }); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').doesNotExist(); | ||
| }); | ||
|
|
||
| test('empty docs.rs responses are ignored, still show source link', async function (assert) { | ||
| let crate = await this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); | ||
| await this.db.version.create({ crate, num: '0.6.2' }); | ||
|
|
||
| let response = HttpResponse.json({}); | ||
| this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); | ||
|
|
||
| await visit('/crates/foo'); | ||
| assert.dom('[data-test-source-link] a').hasAttribute('href', 'https://docs.rs/crate/foo/0.6.2/source/'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.