Commit 981a74da943 for woocommerce
commit 981a74da9439e2d8ede89b628f5956ad9af0aaeb
Author: SH Sajal Chowdhury <72102985+shsajalchowdhury@users.noreply.github.com>
Date: Thu May 14 20:59:49 2026 +0600
Export common payment method icons from @woocommerce/blocks-checkout (#64617)
* Export common payment method icons from blocks checkout package
Expose the shared payment method icon definitions and utility helper from
@woocommerce/blocks-checkout so third-party extensions can reuse the same
assets and lookup logic.
Closes #42154
* Fix checkout package export path for payment icons
* Add unit and smoke tests for payment icon exports
Add comprehensive tests for the newly exported paymentMethodCommonIcons
and getCommonIconProps from @woocommerce/blocks-checkout:
- Unit tests for commonIcons array structure and content
- Unit tests for getCommonIconProps with known and unknown IDs
- Smoke tests verifying barrel export from @woocommerce/blocks-checkout
- Tests confirm getCommonIconProps('visa') returns Visa icon props
- Tests confirm unknown brand returns {} fallback
Addresses review feedback from @mikejolley on PR #64617
* fix: address review feedback — run Prettier on common-icons.test.ts, add External dependencies comment to exports.test.ts
* Add changefile(s) from automation for the following project(s): woocommerce
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/64617-fix-42154-export-common-payment-icons b/plugins/woocommerce/changelog/64617-fix-42154-export-common-payment-icons
new file mode 100644
index 00000000000..1aaec6ff712
--- /dev/null
+++ b/plugins/woocommerce/changelog/64617-fix-42154-export-common-payment-icons
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Export shared payment method icons and `getCommonIconProps` from `@woocommerce/blocks-checkout`.
\ No newline at end of file
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/payment-method-icons/test/common-icons.test.ts b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/payment-method-icons/test/common-icons.test.ts
new file mode 100644
index 00000000000..398b5bb7bae
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/payment-method-icons/test/common-icons.test.ts
@@ -0,0 +1,54 @@
+/**
+ * Internal dependencies
+ */
+import { commonIcons, getCommonIconProps } from '../common-icons';
+
+describe( 'common-icons exports', () => {
+ describe( 'commonIcons', () => {
+ it( 'is an array of icon definitions', () => {
+ expect( Array.isArray( commonIcons ) ).toBe( true );
+ expect( commonIcons.length ).toBeGreaterThan( 0 );
+ } );
+
+ it( 'contains icon definitions with id, alt, and src', () => {
+ commonIcons.forEach( ( icon ) => {
+ expect( icon ).toHaveProperty( 'id' );
+ expect( icon ).toHaveProperty( 'alt' );
+ expect( icon ).toHaveProperty( 'src' );
+ expect( typeof icon.id ).toBe( 'string' );
+ expect( typeof icon.alt ).toBe( 'string' );
+ expect( typeof icon.src ).toBe( 'string' );
+ } );
+ } );
+
+ it( 'includes expected payment method icons', () => {
+ const ids = commonIcons.map( ( icon ) => icon.id );
+ expect( ids ).toContain( 'visa' );
+ expect( ids ).toContain( 'mastercard' );
+ expect( ids ).toContain( 'amex' );
+ } );
+ } );
+
+ describe( 'getCommonIconProps', () => {
+ it( 'returns the matching icon props for a known id', () => {
+ const result = getCommonIconProps( 'visa' );
+ expect( result ).toEqual(
+ expect.objectContaining( {
+ id: 'visa',
+ alt: 'Visa',
+ } )
+ );
+ expect( typeof ( result as { src: string } ).src ).toBe( 'string' );
+ } );
+
+ it( 'returns an empty object for an unknown id', () => {
+ const result = getCommonIconProps( 'unknown-brand' );
+ expect( result ).toEqual( {} );
+ } );
+
+ it( 'returns an empty object for an empty string', () => {
+ const result = getCommonIconProps( '' );
+ expect( result ).toEqual( {} );
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/client/blocks/packages/checkout/components/index.ts b/plugins/woocommerce/client/blocks/packages/checkout/components/index.ts
index 3c1f860b81b..c39913a27bc 100644
--- a/plugins/woocommerce/client/blocks/packages/checkout/components/index.ts
+++ b/plugins/woocommerce/client/blocks/packages/checkout/components/index.ts
@@ -16,3 +16,7 @@ export {
export { default as TextInput } from '../../components/text-input/text-input';
export { default as ValidationInputError } from '../../components/validation-input-error';
export { default as StoreNotice } from '../../components/store-notice';
+export {
+ commonIcons as paymentMethodCommonIcons,
+ getCommonIconProps,
+} from '../../../assets/js/base/components/cart-checkout/payment-method-icons/common-icons';
diff --git a/plugins/woocommerce/client/blocks/packages/checkout/components/test/exports.test.ts b/plugins/woocommerce/client/blocks/packages/checkout/components/test/exports.test.ts
new file mode 100644
index 00000000000..eabc4aa532d
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/packages/checkout/components/test/exports.test.ts
@@ -0,0 +1,41 @@
+/**
+ * Smoke tests for @woocommerce/blocks-checkout public exports.
+ *
+ * These tests verify that the barrel file correctly re-exports
+ * paymentMethodCommonIcons and getCommonIconProps so that third-party
+ * extensions can import them from the package entry point.
+ */
+
+/**
+ * External dependencies
+ */
+import {
+ paymentMethodCommonIcons,
+ getCommonIconProps,
+} from '@woocommerce/blocks-checkout';
+
+describe( '@woocommerce/blocks-checkout payment icon exports', () => {
+ it( 'exports paymentMethodCommonIcons as a non-empty array', () => {
+ expect( Array.isArray( paymentMethodCommonIcons ) ).toBe( true );
+ expect( paymentMethodCommonIcons.length ).toBeGreaterThan( 0 );
+ } );
+
+ it( 'exports getCommonIconProps as a function', () => {
+ expect( typeof getCommonIconProps ).toBe( 'function' );
+ } );
+
+ it( 'getCommonIconProps returns Visa icon props from the package export', () => {
+ const result = getCommonIconProps( 'visa' );
+ expect( result ).toEqual(
+ expect.objectContaining( {
+ id: 'visa',
+ alt: 'Visa',
+ } )
+ );
+ } );
+
+ it( 'getCommonIconProps returns empty object for unknown brand from the package export', () => {
+ const result = getCommonIconProps( 'nonexistent' );
+ expect( result ).toEqual( {} );
+ } );
+} );