This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Honor hidden property of cart item data and add support for experimen…
…al property (#3732) * Honor hidden property of cart item data and add support for experimental property * Add docs to experimental property * Typo * Add protection in ProductDetails for the case where 'details' is not an array * Update ProductDetails so it works properly in cases where 'name' is not provided * Add snapshot testing to ProductDetails
- Loading branch information
Showing
5 changed files
with
153 additions
and
6 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
76 changes: 76 additions & 0 deletions
76
assets/js/base/components/cart-checkout/product-details/test/__snapshots__/index.js.snap
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,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ProductDetails should not render hidden details 1`] = ` | ||
<ul | ||
className="wc-block-components-product-details" | ||
> | ||
<li | ||
className="wc-block-components-product-details__lorem" | ||
> | ||
<span | ||
className="wc-block-components-product-details__name" | ||
> | ||
LOREM | ||
: | ||
</span> | ||
<span | ||
className="wc-block-components-product-details__value" | ||
> | ||
IPSUM | ||
</span> | ||
</li> | ||
</ul> | ||
`; | ||
|
||
exports[`ProductDetails should not rendering anything if all details are hidden 1`] = `null`; | ||
|
||
exports[`ProductDetails should not rendering anything if details is an empty array 1`] = `null`; | ||
|
||
exports[`ProductDetails should render details 1`] = ` | ||
<ul | ||
className="wc-block-components-product-details" | ||
> | ||
<li | ||
className="wc-block-components-product-details__lorem" | ||
> | ||
<span | ||
className="wc-block-components-product-details__name" | ||
> | ||
Lorem | ||
: | ||
</span> | ||
<span | ||
className="wc-block-components-product-details__value" | ||
> | ||
Ipsum | ||
</span> | ||
</li> | ||
<li | ||
className="wc-block-components-product-details__lorem" | ||
> | ||
<span | ||
className="wc-block-components-product-details__name" | ||
> | ||
LOREM | ||
: | ||
</span> | ||
<span | ||
className="wc-block-components-product-details__value" | ||
> | ||
IPSUM | ||
</span> | ||
</li> | ||
<li | ||
className="" | ||
> | ||
<span | ||
className="wc-block-components-product-details__value" | ||
> | ||
Ipsum | ||
</span> | ||
</li> | ||
</ul> | ||
`; |
57 changes: 57 additions & 0 deletions
57
assets/js/base/components/cart-checkout/product-details/test/index.js
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,57 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import TestRenderer from 'react-test-renderer'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ProductDetails from '..'; | ||
|
||
describe( 'ProductDetails', () => { | ||
test( 'should render details', () => { | ||
const details = [ | ||
{ name: 'Lorem', value: 'Ipsum' }, | ||
{ name: 'LOREM', value: 'Ipsum', display: 'IPSUM' }, | ||
{ value: 'Ipsum' }, | ||
]; | ||
const component = TestRenderer.create( | ||
<ProductDetails details={ details } /> | ||
); | ||
|
||
expect( component.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should not render hidden details', () => { | ||
const details = [ | ||
{ name: 'Lorem', value: 'Ipsum', hidden: true }, | ||
{ name: 'LOREM', value: 'Ipsum', display: 'IPSUM' }, | ||
]; | ||
const component = TestRenderer.create( | ||
<ProductDetails details={ details } /> | ||
); | ||
|
||
expect( component.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should not rendering anything if all details are hidden', () => { | ||
const details = [ | ||
{ name: 'Lorem', value: 'Ipsum', hidden: true }, | ||
{ name: 'LOREM', value: 'Ipsum', display: 'IPSUM', hidden: true }, | ||
]; | ||
const component = TestRenderer.create( | ||
<ProductDetails details={ details } /> | ||
); | ||
|
||
expect( component.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
|
||
test( 'should not rendering anything if details is an empty array', () => { | ||
const details = []; | ||
const component = TestRenderer.create( | ||
<ProductDetails details={ details } /> | ||
); | ||
|
||
expect( component.toJSON() ).toMatchSnapshot(); | ||
} ); | ||
} ); |
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