From 3c424992a4db23ff54ff1fdf14c156c978082d6c Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 18 Jan 2022 10:46:10 -0300 Subject: [PATCH] Refactor selling options - OBW - Business Details (https://github.com/woocommerce/woocommerce-admin/pull/8081) Co-authored-by: Fernando Marichal --- .../flows/selective-bundle/index.js | 54 +++++++++---------- .../steps/business-details/test/index.js | 23 ++++++++ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js index a81b89d02e4..23fb3982330 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js @@ -81,6 +81,17 @@ export const prepareExtensionTrackingData = ( return installedExtensions; }; +export const isSellingElsewhere = ( selectedOption ) => + [ + 'other', + 'brick-mortar', + 'brick-mortar-other', + 'other-woocommerce', + ].includes( selectedOption ); + +export const isSellingOtherPlatformInPerson = ( selectedOption ) => + [ 'other', 'brick-mortar-other' ].includes( selectedOption ); + class BusinessDetails extends Component { constructor() { super(); @@ -219,7 +230,7 @@ class BusinessDetails extends Component { if ( ! values.other_platform.length && - [ 'other', 'brick-mortar-other' ].includes( values.selling_venues ) + isSellingOtherPlatformInPerson( values.selling_venues ) ) { errors.other_platform = __( 'This field is required', @@ -229,7 +240,7 @@ class BusinessDetails extends Component { if ( ! values.other_platform_name.trim().length && values.other_platform === 'other' && - [ 'other', 'brick-mortar-other' ].includes( values.selling_venues ) + isSellingOtherPlatformInPerson( values.selling_venues ) ) { errors.other_platform_name = __( 'This field is required', @@ -239,12 +250,7 @@ class BusinessDetails extends Component { if ( ! values.number_employees.length && - [ - 'other', - 'brick-mortar', - 'brick-mortar-other', - 'other-woocommerce', - ].includes( values.selling_venues ) + isSellingElsewhere( values.selling_venues ) ) { errors.number_employees = __( 'This field is required', @@ -254,12 +260,7 @@ class BusinessDetails extends Component { if ( ! values.revenue.length && - [ - 'other', - 'brick-mortar', - 'brick-mortar-other', - 'other-woocommerce', - ].includes( values.selling_venues ) + isSellingElsewhere( values.selling_venues ) ) { errors.revenue = __( 'This field is required', @@ -391,12 +392,9 @@ class BusinessDetails extends Component { ) } /> - { [ - 'other', - 'brick-mortar', - 'brick-mortar-other', - 'other-woocommerce', - ].includes( values.selling_venues ) && ( + { isSellingElsewhere( + values.selling_venues + ) && ( ) } - { [ - 'other', - 'brick-mortar', - 'brick-mortar-other', - 'other-woocommerce', - ].includes( values.selling_venues ) && ( + { isSellingElsewhere( + values.selling_venues + ) && ( ) } - { [ - 'other', - 'brick-mortar-other', - ].includes( values.selling_venues ) && ( + { isSellingOtherPlatformInPerson( + values.selling_venues + ) && ( <>
{ expect( values ).not.toContain( 'this-should-not-show-at-all' ); } ); } ); + + describe( 'Currently selling elsewhere', () => { + test( 'isSellingElsewhere', () => { + const sellingElsewhere = isSellingElsewhere( 'other' ); + const notSellingElsewhere = isSellingElsewhere( 'no' ); + + expect( sellingElsewhere ).toBeTruthy(); + expect( notSellingElsewhere ).toBeFalsy(); + } ); + test( 'isSellingOtherPlatformInPerson', () => { + const sellingAnotherPlatformAndInPerson = isSellingOtherPlatformInPerson( + 'brick-mortar-other' + ); + const notSellingAnotherPlatformAndInPerson = isSellingOtherPlatformInPerson( + 'no' + ); + + expect( sellingAnotherPlatformAndInPerson ).toBeTruthy(); + expect( notSellingAnotherPlatformAndInPerson ).toBeFalsy(); + } ); + } ); } );