|
1 | 1 | import { visit } from '@ember/test-helpers'; |
2 | 2 | import { module, test } from 'qunit'; |
3 | 3 |
|
| 4 | +import { http, HttpResponse } from 'msw'; |
| 5 | + |
4 | 6 | import { setupApplicationTest } from 'crates-io/tests/helpers'; |
5 | 7 |
|
6 | 8 | module('Route | crate.version | docs link', function (hooks) { |
7 | | - setupApplicationTest(hooks); |
| 9 | + setupApplicationTest(hooks, { msw: true }); |
8 | 10 |
|
9 | 11 | test('shows regular documentation link', async function (assert) { |
10 | | - let crate = this.server.create('crate', { name: 'foo', documentation: 'https://foo.io/docs' }); |
11 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 12 | + let crate = this.db.crate.create({ name: 'foo', documentation: 'https://foo.io/docs' }); |
| 13 | + this.db.version.create({ crate, num: '1.0.0' }); |
12 | 14 |
|
13 | 15 | await visit('/crates/foo'); |
14 | 16 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://foo.io/docs'); |
15 | 17 | }); |
16 | 18 |
|
17 | 19 | test('show no docs link if `documentation` is unspecified and there are no related docs.rs builds', async function (assert) { |
18 | | - let crate = this.server.create('crate', { name: 'foo' }); |
19 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 20 | + let crate = this.db.crate.create({ name: 'foo' }); |
| 21 | + this.db.version.create({ crate, num: '1.0.0' }); |
20 | 22 |
|
21 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404); |
| 23 | + let error = HttpResponse.text('not found', { status: 404 }); |
| 24 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
22 | 25 |
|
23 | 26 | await visit('/crates/foo'); |
24 | 27 | assert.dom('[data-test-docs-link] a').doesNotExist(); |
25 | 28 | }); |
26 | 29 |
|
27 | 30 | test('show docs link if `documentation` is unspecified and there are related docs.rs builds', async function (assert) { |
28 | | - let crate = this.server.create('crate', { name: 'foo' }); |
29 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 31 | + let crate = this.db.crate.create({ name: 'foo' }); |
| 32 | + this.db.version.create({ crate, num: '1.0.0' }); |
30 | 33 |
|
31 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', { |
32 | | - doc_status: true, |
33 | | - version: '1.0.0', |
34 | | - }); |
| 34 | + let response = HttpResponse.json({ doc_status: true, version: '1.0.0' }); |
| 35 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
35 | 36 |
|
36 | 37 | await visit('/crates/foo'); |
37 | 38 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0'); |
38 | 39 | }); |
39 | 40 |
|
40 | 41 | test('show original docs link if `documentation` points to docs.rs and there are no related docs.rs builds', async function (assert) { |
41 | | - let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
42 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 42 | + let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 43 | + this.db.version.create({ crate, num: '1.0.0' }); |
43 | 44 |
|
44 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'not found', 404); |
| 45 | + let error = HttpResponse.text('not found', { status: 404 }); |
| 46 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
45 | 47 |
|
46 | 48 | await visit('/crates/foo'); |
47 | 49 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2'); |
48 | 50 | }); |
49 | 51 |
|
50 | 52 | test('show updated docs link if `documentation` points to docs.rs and there are related docs.rs builds', async function (assert) { |
51 | | - let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
52 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 53 | + let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 54 | + this.db.version.create({ crate, num: '1.0.0' }); |
53 | 55 |
|
54 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', { |
55 | | - doc_status: true, |
56 | | - version: '1.0.0', |
57 | | - }); |
| 56 | + let response = HttpResponse.json({ doc_status: true, version: '1.0.0' }); |
| 57 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
58 | 58 |
|
59 | 59 | await visit('/crates/foo'); |
60 | 60 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/1.0.0'); |
61 | 61 | }); |
62 | 62 |
|
63 | 63 | test('ajax errors are ignored', async function (assert) { |
64 | | - let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
65 | | - this.server.create('version', { crate, num: '1.0.0' }); |
| 64 | + let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 65 | + this.db.version.create({ crate, num: '1.0.0' }); |
66 | 66 |
|
67 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', 'error', 500); |
| 67 | + let error = HttpResponse.text('error', { status: 500 }); |
| 68 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => error)); |
68 | 69 |
|
69 | 70 | await visit('/crates/foo'); |
70 | 71 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2'); |
71 | 72 | }); |
72 | 73 |
|
73 | 74 | test('empty docs.rs responses are ignored', async function (assert) { |
74 | | - let crate = this.server.create('crate', { name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
75 | | - this.server.create('version', { crate, num: '0.6.2' }); |
| 75 | + let crate = this.db.crate.create({ name: 'foo', documentation: 'https://docs.rs/foo/0.6.2' }); |
| 76 | + this.db.version.create({ crate, num: '0.6.2' }); |
76 | 77 |
|
77 | | - this.server.get('https://docs.rs/crate/:crate/:version/status.json', {}); |
| 78 | + let response = HttpResponse.json({}); |
| 79 | + this.worker.use(http.get('https://docs.rs/crate/:crate/:version/status.json', () => response)); |
78 | 80 |
|
79 | 81 | await visit('/crates/foo'); |
80 | 82 | assert.dom('[data-test-docs-link] a').hasAttribute('href', 'https://docs.rs/foo/0.6.2'); |
|
0 commit comments