|
1 | | -import { currentURL, visit } from '@ember/test-helpers'; |
| 1 | +import { click, currentURL, findAll, visit } from '@ember/test-helpers'; |
2 | 2 | import { |
3 | 3 | type ApplicationTestContext, |
4 | 4 | assertProductDetails, |
| 5 | + assertProducts, |
5 | 6 | setupApplicationTest, |
6 | 7 | setupExperiments, |
7 | 8 | } from 'my-app/tests/helpers'; |
@@ -76,8 +77,48 @@ module('Acceptance | products/product', function (hooks) { |
76 | 77 | 'nest-product-details': 'v1', |
77 | 78 | }); |
78 | 79 |
|
79 | | - /* |
80 | | - TODO: Write tests |
81 | | - */ |
| 80 | + test('We can visit the page', async function (assert) { |
| 81 | + await visit('/products/1'); |
| 82 | + |
| 83 | + assert.strictEqual(currentURL(), '/products/1'); |
| 84 | + |
| 85 | + assertProductDetails(assert, { |
| 86 | + description: 'Made with organic herbs', |
| 87 | + name: 'Vanilla Ice Cream Cake', |
| 88 | + price: '$40', |
| 89 | + rating: '4.5 out of 5 stars', |
| 90 | + seller: "Amy's", |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + test('We can check the details of another product', async function (assert) { |
| 95 | + await visit('/products/1'); |
| 96 | + |
| 97 | + const products = findAll('[data-test-product-card]'); |
| 98 | + |
| 99 | + await click(products[2]!.querySelector('[data-test-link="Learn More"]')!); |
| 100 | + |
| 101 | + assert.strictEqual(currentURL(), '/products/3'); |
| 102 | + |
| 103 | + assertProductDetails(assert, { |
| 104 | + description: 'A chocolate sponge cake with a rich cherry filling', |
| 105 | + name: 'Black Forest Cake', |
| 106 | + price: '$70', |
| 107 | + rating: '5 out of 5 stars', |
| 108 | + seller: 'The local Konditorei', |
| 109 | + }); |
| 110 | + }); |
| 111 | + |
| 112 | + test('When we check a product that does not exist, we are redirected to the products route', async function (assert) { |
| 113 | + await visit('/products/not-a-valid-id'); |
| 114 | + |
| 115 | + assert.strictEqual(currentURL(), '/products', 'We are redirected.'); |
| 116 | + |
| 117 | + assertProducts(assert, [ |
| 118 | + 'Vanilla Ice Cream Cake', |
| 119 | + 'Ember.js Mug', |
| 120 | + 'Black Forest Cake', |
| 121 | + ]); |
| 122 | + }); |
82 | 123 | }); |
83 | 124 | }); |
0 commit comments