Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Only accept strings for the totalLabel filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Feb 8, 2021
1 parent 2add635 commit 9dc1690
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone
import PropTypes from 'prop-types';
import {
__experimentalApplyCheckoutFilter,
__experimentalValidateElementOrString,
TotalsItem,
} from '@woocommerce/blocks-checkout';
import { useStoreCart } from '@woocommerce/base-hooks';
Expand All @@ -32,7 +31,8 @@ const TotalsFooterItem = ( { currency, values } ) => {
args: {
extensions,
},
validate: __experimentalValidateElementOrString,
// Only accept strings.
validate: ( value ) => typeof value === 'string',
} );

return (
Expand Down
1 change: 0 additions & 1 deletion docs/blocks/feature-flags-and-experimental-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ We also have individual features or code blocks behind a feature flag, this is a
- `__experimentalDeRegisterPaymentMethod` function used to deregister a payment method, only used in tests ([experimental function](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b07883b8b76feeb439d655b255507b24fc59e091/assets/js/blocks-registry/payment-methods/registry.js#L70)).
- `__experimentalDeRegisterExpressPaymentMethod` function used to deregister an express payment method, only used in tests ([experimental function](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/b07883b8b76feeb439d655b255507b24fc59e091/assets/js/blocks-registry/payment-methods/registry.js#L74)).
- `__experimentalRegisterCheckoutFilters` and `__experimentalApplyCheckoutFilter` methods included with `@woocommerce/blocks-checkout` package. They allow registering and applying a filter to certain parts of the Cart and Checkout blocks ([experimental method 1](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/3e59ec9842464f783f6e087947e717fa0b0a7b1b/packages/checkout/registry/index.js#L2) | [experimental method 2](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/3e59ec9842464f783f6e087947e717fa0b0a7b1b/packages/checkout/registry/index.js#L17)).
- `__experimentalValidateElementOrString` method included with `@woocommerce/blocks-checkout` package. Allows validating that a value is a valid element or a string ([experimental method](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/277ad369504c38abcc68a4cdbb034c421fe4d123/packages/checkout/registry/validations.js#L6)).
- `__experimental_woocommerce_blocks_hidden` property in a Cart item data array that allows overwriting the `hidden` property. This is useful to make some cart item data visible/hidden depending if it needs to be displayed in Blocks or shortcode ([experimental property](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/9c4288b0ee46960bdc2bf8ef351d05ac23073b0c/src/StoreApi/Schemas/CartItemSchema.php#L439-L441)).
1 change: 0 additions & 1 deletion packages/checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export * from './totals';
export * from './shipping';
export * from './slot';
export * from './registry';
export * from './registry/validations.js';
export { default as ExperimentalOrderMeta } from './order-meta';
export { default as ExperimentalOrderShippingPackages } from './order-shipping-packages';
export { default as Panel } from './panel';
Expand Down
29 changes: 0 additions & 29 deletions packages/checkout/registry/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
__experimentalRegisterCheckoutFilters,
__experimentalApplyCheckoutFilter,
} from '../';
import { __experimentalValidateElementOrString } from '../validations';

describe( 'Checkout registry', () => {
const filterName = 'loremIpsum';
Expand Down Expand Up @@ -50,32 +49,4 @@ describe( 'Checkout registry', () => {

expect( newValue ).toBe( value );
} );

describe( 'validations', () => {
test( '__experimentalValidateElementOrString should invalidate if filtered value is not an element or string', () => {
__experimentalRegisterCheckoutFilters( filterName, {
[ filterName ]: ( val ) => {
if ( val === 'Hello World' ) {
return 'Valid value';
}
return [ 'invalid-value' ];
},
} );
const validValue = __experimentalApplyCheckoutFilter( {
filterName,
defaultValue: 'Hello World',
validate: __experimentalValidateElementOrString,
} );

expect( validValue ).toBe( 'Valid value' );

const invalidValue = __experimentalApplyCheckoutFilter( {
filterName,
defaultValue: 'Hello Earth',
validate: __experimentalValidateElementOrString,
} );

expect( invalidValue ).toBe( 'Hello Earth' );
} );
} );
} );
16 changes: 0 additions & 16 deletions packages/checkout/registry/validations.js

This file was deleted.

0 comments on commit 9dc1690

Please sign in to comment.