|
1 | | -import { click, currentURL, visit } from '@ember/test-helpers'; |
| 1 | +import { click, currentURL } from '@ember/test-helpers'; |
2 | 2 | import { module, test } from 'qunit'; |
3 | 3 |
|
4 | 4 | import { loadFixtures } from '@crates-io/msw/fixtures.js'; |
5 | 5 | import percySnapshot from '@percy/ember'; |
6 | 6 | import a11yAudit from 'ember-a11y-testing/test-support/audit'; |
7 | 7 | import { getPageTitle } from 'ember-page-title/test-support'; |
| 8 | +import { http, HttpResponse } from 'msw'; |
8 | 9 |
|
9 | 10 | import { setupApplicationTest } from 'crates-io/tests/helpers'; |
10 | 11 |
|
11 | 12 | import axeConfig from '../axe-config'; |
| 13 | +import { visit } from '../helpers/visit-ignoring-abort'; |
12 | 14 |
|
13 | 15 | module('Acceptance | crates page', function (hooks) { |
14 | 16 | setupApplicationTest(hooks, { msw: true }); |
@@ -92,4 +94,25 @@ module('Acceptance | crates page', function (hooks) { |
92 | 94 | let formatted = Number(2000).toLocaleString(); |
93 | 95 | assert.dom('[data-test-crate-row="0"] [data-test-recent-downloads]').hasText(`Recent: ${formatted}`); |
94 | 96 | }); |
| 97 | + |
| 98 | + test('shows error message screen', async function (assert) { |
| 99 | + loadFixtures(this.db); |
| 100 | + |
| 101 | + let detail = |
| 102 | + 'Page 1 is unavailable for performance reasons. Please take a look at https://crates.io/data-access for alternatives.'; |
| 103 | + let error = HttpResponse.json({ errors: [{ detail }] }, { status: 400 }); |
| 104 | + this.worker.use(http.get('/api/v1/crates', () => error)); |
| 105 | + |
| 106 | + await visit('/crates'); |
| 107 | + assert.dom('[data-test-404-page]').exists(); |
| 108 | + assert.dom('[data-test-title]').hasText('Failed to load crate list'); |
| 109 | + assert.dom('[data-test-details]').hasText(detail); |
| 110 | + assert.dom('[data-test-try-again]').exists(); |
| 111 | + assert.dom('[data-test-go-back]').doesNotExist(); |
| 112 | + |
| 113 | + this.worker.resetHandlers(); |
| 114 | + await click('[data-test-try-again]'); |
| 115 | + assert.dom('[data-test-404-page]').doesNotExist(); |
| 116 | + assert.dom('[data-test-crate-row]').exists({ count: 23 }); |
| 117 | + }); |
95 | 118 | }); |
0 commit comments