Skip to content

Commit 60efce8

Browse files
committed
day-3-hw: Added tests for v1 group
1 parent e04b4b5 commit 60efce8

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

my-app/tests/acceptance/product-details-test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,18 @@ module('Acceptance | product-details', function (hooks) {
124124
'nest-product-details': 'v1',
125125
});
126126

127-
/*
128-
TODO: Write tests
129-
*/
127+
test('We cannot visit the page', async function (assert) {
128+
await visit('/product-details/1');
129+
130+
assert.strictEqual(currentURL(), '/products/1', 'We are redirected.');
131+
132+
assertProductDetails(assert, {
133+
description: 'Made with organic herbs',
134+
name: 'Vanilla Ice Cream Cake',
135+
price: '$40',
136+
rating: '4.5 out of 5 stars',
137+
seller: "Amy's",
138+
});
139+
});
130140
});
131141
});

my-app/tests/acceptance/products/product-test.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { currentURL, visit } from '@ember/test-helpers';
1+
import { click, currentURL, findAll, visit } from '@ember/test-helpers';
22
import {
33
type ApplicationTestContext,
44
assertProductDetails,
5+
assertProducts,
56
setupApplicationTest,
67
setupExperiments,
78
} from 'my-app/tests/helpers';
@@ -76,8 +77,48 @@ module('Acceptance | products/product', function (hooks) {
7677
'nest-product-details': 'v1',
7778
});
7879

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+
});
82123
});
83124
});

0 commit comments

Comments
 (0)