Skip to content

Commit

Permalink
Product Out of Stock Message (#1229)
Browse files Browse the repository at this point in the history
* Fixed #1159 

Fixed #1159 [bug]: If user tries to access product page after it goes to out of stock then system enters a infinite loop.

* Updates Product to show out of stock message when appropriate

* Adds Unit Tests to ErrorView
  • Loading branch information
sudeep-cedcoss authored and dpatil-magento committed Jun 6, 2019
1 parent d2b5a8a commit 5544164
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/venia-concept/src/RootComponents/Product/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { string, func } from 'prop-types';

import { connect, Query } from 'src/drivers';
import { addItemToCart } from 'src/actions/cart';
import ErrorView from 'src/components/ErrorView';
import { loadingIndicator } from 'src/components/LoadingIndicator';
import ProductFullDetail from 'src/components/ProductFullDetail';
import getUrlKey from 'src/util/getUrlKey';
Expand Down Expand Up @@ -52,6 +53,10 @@ class Product extends Component {

const product = data.productDetail.items[0];

if (!product) {
return <ErrorView outOfStock={true} />;
}

return (
<ProductFullDetail
product={this.mapProduct(product)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`it renders the correct tree when loading 1`] = `
<h1>
<Classify(LoadingIndicator)>
<span>
Fetching Data...
</span>
</Classify(LoadingIndicator)>
</h1>
`;

exports[`it renders the correct tree when out of stock 1`] = `
<h1>
This Product is currently out of stock. Please try again later.
</h1>
`;

exports[`it renders the correct tree when page not found 1`] = `
<h1>
That page could not be found. Please try again.
</h1>
`;

exports[`it renders the internal error tree otherwise 1`] = `
<h1>
Something went wrong. Please try again.
</h1>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import ShallowRenderer from 'react-test-renderer/shallow';

import ErrorView from '../errorView';

const renderer = new ShallowRenderer();

test('it renders the correct tree when loading', () => {
const tree = renderer.render(<ErrorView loading={true} />);

expect(tree).toMatchSnapshot();
});

test('it renders the correct tree when page not found', () => {
const tree = renderer.render(<ErrorView notFound={true} />);

expect(tree).toMatchSnapshot();
});

test('it renders the correct tree when out of stock', () => {
const tree = renderer.render(<ErrorView outOfStock={true} />);

expect(tree).toMatchSnapshot();
});

test('it renders the internal error tree otherwise', () => {
const tree = renderer.render(<ErrorView />);

expect(tree).toMatchSnapshot();
});
10 changes: 8 additions & 2 deletions packages/venia-concept/src/components/ErrorView/errorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import { loadingIndicator } from 'src/components/LoadingIndicator';
const messages = new Map()
.set('loading', loadingIndicator)
.set('notFound', 'That page could not be found. Please try again.')
.set('internalError', 'Something went wrong. Please try again.');
.set('internalError', 'Something went wrong. Please try again.')
.set(
'outOfStock',
'This Product is currently out of stock. Please try again later.'
);

class ErrorView extends Component {
render() {
const { loading, notFound } = this.props;
const { loading, notFound, outOfStock } = this.props;
const message = loading
? messages.get('loading')
: notFound
? messages.get('notFound')
: outOfStock
? messages.get('outOfStock')
: messages.get('internalError');

return <h1>{message}</h1>;
Expand Down

1 comment on commit 5544164

@vercel
Copy link

@vercel vercel bot commented on 5544164 Jun 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.