-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day 3: Created error and loading routes
- Loading branch information
Showing
8 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
import Controller from '@ember/controller'; | ||
|
||
export default class ErrorController extends Controller { | ||
declare model: any; | ||
} |
This file contains 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 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,5 @@ | ||
<Ui::Page @title="error.hbs"> | ||
<p data-test-error-message> | ||
{{or this.model (t "routes.error.default-message")}} | ||
</p> | ||
</Ui::Page> |
This file contains 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,7 @@ | ||
<Ui::Page @title="loading.hbs"> | ||
<img | ||
alt="" | ||
data-test-loading-icon | ||
src="/assets/loading.svg" | ||
/> | ||
</Ui::Page> |
This file contains 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,5 @@ | ||
<div class={{this.styles.container}}> | ||
<p data-test-error-message> | ||
{{or this.model (t "routes.error.default-message")}} | ||
</p> | ||
</div> |
This file contains 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,7 @@ | ||
<div class={{this.styles.container}}> | ||
<img | ||
alt="" | ||
data-test-loading-icon | ||
src="/assets/loading.svg" | ||
/> | ||
</div> |
This file contains 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,43 @@ | ||
import { visit } from '@ember/test-helpers'; | ||
import { Response } from 'miragejs'; | ||
import { | ||
type ApplicationTestContext, | ||
setupApplicationTest, | ||
setupExperiments, | ||
} from 'my-app/tests/helpers'; | ||
import { module, test } from 'qunit'; | ||
|
||
interface TestContext extends ApplicationTestContext {} | ||
|
||
module('Acceptance | products/error', function (hooks) { | ||
setupApplicationTest(hooks); | ||
setupExperiments(hooks, { | ||
'nest-product-details': 'v1', | ||
}); | ||
|
||
hooks.beforeEach(function (this: TestContext) { | ||
this.server.get('/products/:id', () => { | ||
return new Response(500, {}, { errors: ['Some server error'] }); | ||
}); | ||
|
||
this.server.create('product', { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: Assume that Mirage works | ||
categoryId: 'cake', | ||
description: 'Made with organic herbs', | ||
name: 'Vanilla Ice Cream Cake', | ||
price: 40, | ||
rating: 4.5, | ||
seller: "Amy's", | ||
shortDescription: 'Made with organic herbs', | ||
}); | ||
}); | ||
|
||
test('A user can see the error message', async function (assert) { | ||
await visit('/products/1'); | ||
|
||
assert | ||
.dom('[data-test-error-message]') | ||
.exists({ count: 1 }, 'The user sees the error message.'); | ||
}); | ||
}); |
This file contains 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,42 @@ | ||
import { settled, visit, waitFor } from '@ember/test-helpers'; | ||
import { | ||
type ApplicationTestContext, | ||
setupApplicationTest, | ||
setupExperiments, | ||
} from 'my-app/tests/helpers'; | ||
import { module, test } from 'qunit'; | ||
|
||
interface TestContext extends ApplicationTestContext {} | ||
|
||
module('Acceptance | products/loading', function (hooks) { | ||
setupApplicationTest(hooks); | ||
setupExperiments(hooks, { | ||
'nest-product-details': 'v1', | ||
}); | ||
|
||
hooks.beforeEach(function (this: TestContext) { | ||
this.server.create('product', { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore: Assume that Mirage works | ||
categoryId: 'cake', | ||
description: 'Made with organic herbs', | ||
name: 'Vanilla Ice Cream Cake', | ||
price: 40, | ||
rating: 4.5, | ||
seller: "Amy's", | ||
shortDescription: 'Made with organic herbs', | ||
}); | ||
}); | ||
|
||
test('A user can see the loading icon', async function (assert) { | ||
visit('/products/1'); | ||
|
||
await waitFor('[data-test-loading-icon]'); | ||
|
||
assert | ||
.dom('[data-test-loading-icon]') | ||
.exists({ count: 1 }, 'The user can see the loading icon.'); | ||
|
||
await settled(); | ||
}); | ||
}); |