Skip to content

Commit 015abb4

Browse files
committed
Fixed tests
1 parent 293848d commit 015abb4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/template-retail-react-app/app/components/icons/index.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jest.mock('react-intl', () => ({
1818

1919
beforeEach(() => {
2020
jest.clearAllMocks()
21+
// Provide a proper mock implementation for useIntl
22+
useIntl.mockReturnValue({
23+
formatMessage: jest.fn((message) => message.defaultMessage || message.id || 'Mock message')
24+
})
2125
})
2226

2327
test('renders svg icons with Chakra Icon component', () => {

packages/template-retail-react-app/app/hooks/use-bonus-product-modal.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {useLocation} from 'react-router-dom'
99
import PropTypes from 'prop-types'
1010
import {BonusProductModal} from '@salesforce/retail-react-app/app/components/bonus-product-modal'
1111
import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket'
12+
import {useAddToCartModalContext} from '@salesforce/retail-react-app/app/hooks/use-add-to-cart-modal'
1213

1314
export const BonusProductModalContext = React.createContext()
1415

@@ -37,6 +38,7 @@ export const useBonusState = (basket) => {
3738
bonusProducts: basket?.bonusDiscountLineItems || []
3839
})
3940
const {pathname} = useLocation()
41+
const {onOpen: onAddToCartModalOpen} = useAddToCartModalContext()
4042

4143
useEffect(() => {
4244
if (state.isOpen) {
@@ -84,7 +86,23 @@ export const useBonusState = (basket) => {
8486
data: {}
8587
}))
8688
},
87-
onClose: () => {},
89+
onClose: () => {
90+
const currentData = state.data
91+
setState((prev) => ({
92+
...prev,
93+
isOpen: false,
94+
data: {}
95+
}))
96+
97+
// If there's data with product, itemsAdded, and selectedQuantity, call onAddToCartModalOpen
98+
if (currentData?.product && currentData?.itemsAdded !== undefined && currentData?.selectedQuantity !== undefined) {
99+
onAddToCartModalOpen({
100+
product: currentData.product,
101+
itemsAdded: currentData.itemsAdded,
102+
selectedQuantity: currentData.selectedQuantity
103+
})
104+
}
105+
},
88106
onOpen: (data) => {
89107
setState((prev) => ({
90108
...prev,

0 commit comments

Comments
 (0)