|
1 |
| -import { currentURL, visit } from '@ember/test-helpers'; |
| 1 | +import { currentURL } from '@ember/test-helpers'; |
2 | 2 | import { module, test } from 'qunit';
|
3 | 3 |
|
4 | 4 | import { setupApplicationTest } from 'cargo/tests/helpers';
|
5 | 5 |
|
| 6 | +import { visit } from '../../helpers/visit-ignoring-abort'; |
| 7 | + |
6 | 8 | module('Route | crate.range', function (hooks) {
|
7 | 9 | setupApplicationTest(hooks);
|
8 | 10 |
|
@@ -76,17 +78,58 @@ module('Route | crate.range', function (hooks) {
|
76 | 78 | assert.dom('[data-test-notification-message]').doesNotExist();
|
77 | 79 | });
|
78 | 80 |
|
79 |
| - test('redirects to main crate page if no match found', async function (assert) { |
| 81 | + test('shows an error page if crate not found', async function (assert) { |
| 82 | + await visit('/crates/foo/range/^3'); |
| 83 | + assert.equal(currentURL(), '/crates/foo/range/%5E3'); |
| 84 | + assert.dom('[data-test-404-page]').exists(); |
| 85 | + assert.dom('[data-test-title]').hasText('Crate not found'); |
| 86 | + assert.dom('[data-test-go-back]').exists(); |
| 87 | + assert.dom('[data-test-try-again]').doesNotExist(); |
| 88 | + }); |
| 89 | + |
| 90 | + test('shows an error page if crate fails to load', async function (assert) { |
| 91 | + this.server.get('/api/v1/crates/:crate_name', {}, 500); |
| 92 | + |
| 93 | + await visit('/crates/foo/range/^3'); |
| 94 | + assert.equal(currentURL(), '/crates/foo/range/%5E3'); |
| 95 | + assert.dom('[data-test-404-page]').exists(); |
| 96 | + assert.dom('[data-test-title]').hasText('Crate failed to load'); |
| 97 | + assert.dom('[data-test-go-back]').doesNotExist(); |
| 98 | + assert.dom('[data-test-try-again]').exists(); |
| 99 | + }); |
| 100 | + |
| 101 | + test('shows an error page if no match found', async function (assert) { |
80 | 102 | let crate = this.server.create('crate', { name: 'foo' });
|
81 | 103 | this.server.create('version', { crate, num: '1.0.0' });
|
82 | 104 | this.server.create('version', { crate, num: '1.1.0' });
|
83 | 105 | this.server.create('version', { crate, num: '1.1.1' });
|
84 | 106 | this.server.create('version', { crate, num: '2.0.0' });
|
85 | 107 |
|
86 | 108 | await visit('/crates/foo/range/^3');
|
87 |
| - assert.equal(currentURL(), `/crates/foo`); |
88 |
| - assert.dom('[data-test-crate-name]').hasText('foo'); |
89 |
| - assert.dom('[data-test-crate-version]').hasText('2.0.0'); |
90 |
| - assert.dom('[data-test-notification-message="error"]').hasText("No matching version of crate 'foo' found for: ^3"); |
| 109 | + assert.equal(currentURL(), '/crates/foo/range/%5E3'); |
| 110 | + assert.dom('[data-test-404-page]').exists(); |
| 111 | + assert.dom('[data-test-title]').hasText('foo: No matching version found for ^3'); |
| 112 | + assert.dom('[data-test-go-back]').exists(); |
| 113 | + assert.dom('[data-test-try-again]').doesNotExist(); |
| 114 | + }); |
| 115 | + |
| 116 | + test('shows an error page if versions fail to load', async function (assert) { |
| 117 | + let crate = this.server.create('crate', { name: 'foo' }); |
| 118 | + this.server.create('version', { crate, num: '3.2.1' }); |
| 119 | + |
| 120 | + this.server.get('/api/v1/crates/:crate_name/versions', {}, 500); |
| 121 | + |
| 122 | + // Load `crate` and then explicitly unload the side-loaded `versions`. |
| 123 | + let store = this.owner.lookup('service:store'); |
| 124 | + let crateRecord = await store.findRecord('crate', 'foo'); |
| 125 | + let versions = crateRecord.hasMany('versions').value(); |
| 126 | + versions.forEach(record => record.unloadRecord()); |
| 127 | + |
| 128 | + await visit('/crates/foo/range/^3'); |
| 129 | + assert.equal(currentURL(), '/crates/foo/range/%5E3'); |
| 130 | + assert.dom('[data-test-404-page]').exists(); |
| 131 | + assert.dom('[data-test-title]').hasText('foo: Failed to load version data'); |
| 132 | + assert.dom('[data-test-go-back]').doesNotExist(); |
| 133 | + assert.dom('[data-test-try-again]').exists(); |
91 | 134 | });
|
92 | 135 | });
|
0 commit comments