Skip to content

Commit 27f92bd

Browse files
@W-18942954 BOPIS revert unneeded swatch change (#2700)
* @W-18942954 BOPIS revert unneeded swatch change * @W-18942954 BOPIS revert unneeded add to cart test change * @W-18942954 BOPIS constant for radio labels
1 parent 0c02e08 commit 27f92bd

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

packages/template-retail-react-app/app/components/product-view/index.jsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import {
2424
RadioGroup,
2525
useTheme
2626
} from '@salesforce/retail-react-app/app/components/shared/ui'
27+
28+
// Constants
29+
const DELIVERY_OPTIONS = {
30+
SHIP: 'ship',
31+
PICKUP: 'pickup'
32+
}
2733
import {useCurrency, useDerivedProduct} from '@salesforce/retail-react-app/app/hooks'
2834
import {useAddToCartModalContext} from '@salesforce/retail-react-app/app/hooks/use-add-to-cart-modal'
2935
import {STORE_LOCATOR_IS_ENABLED} from '@salesforce/retail-react-app/app/constants'
@@ -425,7 +431,7 @@ const ProductView = forwardRef(
425431
}, [selectedStore])
426432

427433
const handleDeliveryOptionChange = (value) => {
428-
setPickupInStore(value === 'pickup')
434+
setPickupInStore(value === DELIVERY_OPTIONS.PICKUP)
429435
}
430436

431437
return (
@@ -681,20 +687,27 @@ const ProductView = forwardRef(
681687
/>
682688
</Text>
683689
<RadioGroup
684-
value={pickupInStore ? 'pickup' : 'ship'}
690+
value={
691+
pickupInStore
692+
? DELIVERY_OPTIONS.PICKUP
693+
: DELIVERY_OPTIONS.SHIP
694+
}
685695
onChange={handleDeliveryOptionChange}
686696
mb={1}
687697
>
688698
<Stack direction="column" spacing={2}>
689-
<Radio value="ship" isDisabled={disableButton}>
699+
<Radio
700+
value={DELIVERY_OPTIONS.SHIP}
701+
isDisabled={disableButton}
702+
>
690703
<FormattedMessage
691704
defaultMessage="Ship to Address"
692705
id="product_view.label.ship_to_address"
693706
/>
694707
</Radio>
695708
{STORE_LOCATOR_IS_ENABLED && (
696709
<Radio
697-
value="pickup"
710+
value={DELIVERY_OPTIONS.PICKUP}
698711
isDisabled={
699712
!pickupEnabled ||
700713
(storeName &&

packages/template-retail-react-app/app/components/swatch-group/index.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,17 @@ const SwatchGroup = (props) => {
7575
return
7676
}
7777
const childrenArray = Children.toArray(children)
78-
const index = childrenArray.findIndex((child) => child?.props?.value === value)
78+
const index = childrenArray.findIndex(({props}) => props?.value === value)
7979

80-
setSelectedIndex(index >= 0 ? index : 0)
80+
setSelectedIndex(index)
8181
}, [])
8282

8383
// Whenever the selected index changes ensure that we call the change handler.
8484
useEffect(() => {
8585
const childrenArray = Children.toArray(children)
86-
const selectedChild = childrenArray[selectedIndex]
86+
const newValue = childrenArray[selectedIndex].props.value
8787

88-
if (selectedChild?.props?.value) {
89-
const newValue = selectedChild.props.value
90-
handleChange(newValue)
91-
}
88+
handleChange(newValue)
9289
}, [selectedIndex])
9390

9491
return (
@@ -108,7 +105,6 @@ const SwatchGroup = (props) => {
108105
)}
109106
<Flex ref={wrapperRef} {...styles.swatchesWrapper}>
110107
{Children.toArray(children).map((child, index) => {
111-
if (!child?.props) return null
112108
const selected = child.props.value === value
113109
return React.cloneElement(child, {
114110
handleSelect: handleChange,

packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,20 +650,21 @@ test('renders product bundle', () => {
650650
expect(screen.getByText(mockProductBundle.name)).toBeInTheDocument()
651651
expect(screen.getByRole('dialog', {name: /1 item added to cart/i})).toBeInTheDocument()
652652

653+
// bundle data is displayed in 1 row
653654
const numOfRowsRendered = screen.getAllByTestId('product-added').length
654655
expect(numOfRowsRendered).toBe(1)
655656

657+
// modal displays product name of children and variant selection
656658
mockBundleItemsAdded.forEach(({product, variant, quantity}) => {
657-
expect(
658-
screen.getByText((content) => content.trim().includes(product.name))
659-
).toBeInTheDocument()
660-
const quantityText = `(${quantity})`
661-
const found = !!screen.queryByText((content) => content.includes(quantityText))
662-
expect(found).toBe(quantity > 1)
659+
const displayedName = quantity > 1 ? `${product.name} (${quantity})` : product.name
660+
expect(screen.getByText(displayedName)).toBeInTheDocument()
661+
663662
const variationAttributeValues = getDisplayVariationValues(
664663
product.variationAttributes,
665664
variant.variationValues
666665
)
666+
667+
// Looks for text displaying variant ('Color: Black' or 'Size: S') in modal
667668
Object.entries(variationAttributeValues).forEach(([name, value]) => {
668669
expect(screen.getAllByText(`${name}: ${value}`)[0]).toBeInTheDocument()
669670
})

0 commit comments

Comments
 (0)