Skip to content

Commit

Permalink
Day 3 Homework: Added application tests for the nest-product-details …
Browse files Browse the repository at this point in the history
…experiment, v1 group
  • Loading branch information
ijlee2 committed Oct 15, 2023
1 parent 451281b commit ea99fec
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 1 deletion.
24 changes: 24 additions & 0 deletions my-app/tests/acceptance/product-details-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,28 @@ module('Acceptance | product details', function (hooks) {
]);
});
});

module('nest-product-details, v1', function (nestedHooks) {
setupExperiments(nestedHooks, {
'nest-product-details': 'v1',
});

test('A user cannot visit the product-details route', async function (assert) {
await visit('/product-details/1');

assert.strictEqual(
currentURL(),
'/products/1',
'We redirect the user to the products.product route.',
);

assertProductDetails(assert, {
description: 'Made with organic herbs',
name: 'Vanilla Ice Cream Cake',
price: '$40',
rating: '4.5 out of 5 stars',
seller: "Amy's",
});
});
});
});
107 changes: 107 additions & 0 deletions my-app/tests/acceptance/products-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,111 @@ module('Acceptance | products', function (hooks) {
]);
});
});

module('nest-product-details, v1', function (nestedHooks) {
setupExperiments(nestedHooks, {
'nest-product-details': 'v1',
});

test('A user can visit the products route', async function (assert) {
await visit('/products');

assert.strictEqual(
currentURL(),
'/products',
'The user is on the products route.',
);

assert
.dom('[data-test-field="Filter by name"]')
.exists({ count: 1 }, 'The user sees the filter by name field.');

assert
.dom('[data-test-field="Sort by"]')
.exists({ count: 1 }, 'The user sees the sort by field.');

assertProducts(assert, [
'Vanilla Ice Cream Cake',
'Ember.js Mug',
'Black Forest Cake',
]);
});

test('A user can filter and sort products', async function (assert) {
await visit('/products');
await fillIn('[data-test-field="Filter by name"]', 'cake');

assert.strictEqual(
currentURL(),
'/products?name=cake',
'The user is on the products route.',
);

assertProducts(assert, ['Vanilla Ice Cream Cake', 'Black Forest Cake']);

await selectByLabel('[data-test-field="Sort by"]', 'Name: A to Z');

assert.strictEqual(
currentURL(),
'/products?name=cake&sortBy=name%3Aasc',
'The user is on the products route.',
);

assertProducts(assert, ['Black Forest Cake', 'Vanilla Ice Cream Cake']);

await fillIn('[data-test-field="Filter by name"]', '');

assert.strictEqual(
currentURL(),
'/products?sortBy=name%3Aasc',
'The user is on the products route.',
);

assertProducts(assert, [
'Black Forest Cake',
'Ember.js Mug',
'Vanilla Ice Cream Cake',
]);

await click('[data-test-button="Clear"]');

assert.strictEqual(
currentURL(),
'/products',
'The user is on the products route.',
);

assertProducts(assert, [
'Vanilla Ice Cream Cake',
'Ember.js Mug',
'Black Forest Cake',
]);
});

test('A user can check a product', async function (assert) {
await visit('/products');

const products = findAll('[data-test-product-card]');

await click(products[0]!.querySelector('[data-test-link="Learn More"]')!);

assert.strictEqual(
currentURL(),
'/products/1',
'The user is on the products.product route.',
);

assertProductDetails(assert, {
description: 'Made with organic herbs',
name: 'Vanilla Ice Cream Cake',
price: '$40',
rating: '4.5 out of 5 stars',
seller: "Amy's",
});

assert
.dom('[data-test-link="Back"]')
.doesNotExist('The user should not see the back link.');
});
});
});
78 changes: 77 additions & 1 deletion my-app/tests/acceptance/products/product-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { currentURL, visit } from '@ember/test-helpers';
import { click, currentURL, findAll, visit } from '@ember/test-helpers';
import { a11yAudit } from 'ember-a11y-testing/test-support';
import { getPageTitle } from 'ember-page-title/test-support';
import {
type ApplicationTestContext,
assertProductDetails,
assertProducts,
setupApplicationTest,
setupExperiments,
} from 'my-app/tests/helpers';
Expand Down Expand Up @@ -73,4 +76,77 @@ module('Acceptance | products/product', function (hooks) {
});
});
});

module('nest-product-details, v1', function (nestedHooks) {
setupExperiments(nestedHooks, {
'nest-product-details': 'v1',
});

test('Accessibility audit', async function (assert) {
await visit('/products/1');
await a11yAudit();

assert.strictEqual(
getPageTitle(),
'Vanilla Ice Cream Cake | Products | Ember Workshop',
'We render the correct page title.',
);
});

test('A user can visit the products.product route', async function (assert) {
await visit('/products/1');

assert.strictEqual(
currentURL(),
'/products/1',
'The user is on the products.product route.',
);

assertProductDetails(assert, {
description: 'Made with organic herbs',
name: 'Vanilla Ice Cream Cake',
price: '$40',
rating: '4.5 out of 5 stars',
seller: "Amy's",
});
});

test('A user can check another product', async function (assert) {
await visit('/products/1');

const products = findAll('[data-test-product-card]');

await click(products[2]!.querySelector('[data-test-link="Learn More"]')!);

assert.strictEqual(
currentURL(),
'/products/3',
'The user is on the products.product route.',
);

assertProductDetails(assert, {
description: 'A chocolate sponge cake with a rich cherry filling',
name: 'Black Forest Cake',
price: '$70',
rating: '5 out of 5 stars',
seller: 'The local Konditorei',
});
});

test('When a user checks a product that does not exist, we redirect them to the products route', async function (assert) {
await visit('/products/not-a-valid-id');

assert.strictEqual(
currentURL(),
'/products',
'We redirect the user to the products route.',
);

assertProducts(assert, [
'Vanilla Ice Cream Cake',
'Ember.js Mug',
'Black Forest Cake',
]);
});
});
});

0 comments on commit ea99fec

Please sign in to comment.