-
Notifications
You must be signed in to change notification settings - Fork 213
@W-18407137 Trigger a modal if new bonus products exist in AddToCart response #2541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sf-madhuri-uppu
merged 19 commits into
feature/bonus-products
from
t/cc-shark/W-18407137V2
Jun 12, 2025
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
968f1bb
@W-18670270 update unit test
yhsieh1 4259a1b
skip changelog
yhsieh1 58ad8fe
remove un-needed assertion
yhsieh1 8c44ea7
Merge pull request #2538 from SalesforceCommerceCloud/t/commerce/W-18…
yhsieh1 802b9d3
Trigger a modal if bonus products exist in AddToCart response
sf-madhuri-uppu 790a72b
skip changelog
sf-madhuri-uppu c2021fa
skip changelog
sf-madhuri-uppu 0aadd8b
fixed import issue
sf-madhuri-uppu 83b1dbb
removed localstorage and updated bonus products info from current basket
sf-madhuri-uppu 0a697ef
removed unnecessary code
sf-madhuri-uppu 4a0950c
nit space
sf-madhuri-uppu afb7dc9
fixed 2 failing tests
sf-madhuri-uppu bd8f645
fixed a unit test
sf-madhuri-uppu 392c52f
fixed lint errors
sf-madhuri-uppu 9414838
Addressed PR comments
sf-madhuri-uppu f8fd65e
use current basket query
sf-madhuri-uppu e441ee9
nit
sf-madhuri-uppu 4848f14
removed unnecessary code
sf-madhuri-uppu 9f6cfe5
fixed infinite re-render issue
sf-madhuri-uppu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,9 +46,13 @@ afterEach(() => { | |
| sessionStorage.clear() | ||
| }) | ||
|
|
||
| const mockBasket = {bonusDiscountLineItems: []} | ||
sf-madhuri-uppu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| test('ProductView Component renders properly', async () => { | ||
| const addToCart = jest.fn() | ||
| renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />) | ||
| renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />, { | ||
| wrapperProps: {basket: mockBasket} | ||
| }) | ||
| expect(screen.getAllByText(/Black Single Pleat Athletic Fit Wool Suit/i)).toHaveLength(2) | ||
| expect(screen.getAllByText(/299\.99/)).toHaveLength(4) | ||
| expect(screen.getAllByText(/Add to cart/i)).toHaveLength(2) | ||
|
|
@@ -58,7 +62,9 @@ test('ProductView Component renders properly', async () => { | |
|
|
||
| test('ProductView Component renders with addToCart event handler', async () => { | ||
| const addToCart = jest.fn() | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />) | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />, { | ||
| wrapperProps: {basket: mockBasket} | ||
| }) | ||
|
|
||
| const addToCartButton = screen.getAllByText(/add to cart/i)[0] | ||
| fireEvent.click(addToCartButton) | ||
|
|
@@ -72,7 +78,10 @@ test('ProductView Component renders with addToWishList event handler', async () | |
| const addToWishlist = jest.fn() | ||
|
|
||
| await renderWithProviders( | ||
| <MockComponent product={mockProductDetail} addToWishlist={addToWishlist} /> | ||
| <MockComponent product={mockProductDetail} addToWishlist={addToWishlist} />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| await waitFor(() => { | ||
|
|
@@ -91,7 +100,10 @@ test('ProductView Component renders with updateWishlist event handler', async () | |
| const updateWishlist = jest.fn() | ||
|
|
||
| await renderWithProviders( | ||
| <MockComponent product={mockProductDetail} updateWishlist={updateWishlist} /> | ||
| <MockComponent product={mockProductDetail} updateWishlist={updateWishlist} />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| await waitFor(() => { | ||
|
|
@@ -109,7 +121,9 @@ test('ProductView Component renders with updateWishlist event handler', async () | |
| test('Product View can update quantity', async () => { | ||
| const user = userEvent.setup() | ||
| const addToCart = jest.fn() | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />) | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} addToCart={addToCart} />, { | ||
| wrapperProps: {basket: mockBasket} | ||
| }) | ||
|
|
||
| let quantityBox | ||
| await waitFor(() => { | ||
|
|
@@ -132,7 +146,9 @@ test('Product View handles invalid quantity inputs', async () => { | |
| const user = userEvent.setup() | ||
|
|
||
| // Any invalid input should be reset to minOrderQuantity | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} />) | ||
| await renderWithProviders(<MockComponent product={mockProductDetail} />, { | ||
| wrapperProps: {basket: mockBasket} | ||
| }) | ||
|
|
||
| const quantityInput = screen.getByRole('spinbutton', {name: /quantity/i}) | ||
| const minQuantity = mockProductDetail.minOrderQuantity.toString() | ||
|
|
@@ -156,7 +172,9 @@ test('Product View handles invalid quantity inputs', async () => { | |
| describe('ProductView Component', () => { | ||
| test('increases quantity when increment button is clicked', async () => { | ||
| const user = userEvent.setup() | ||
| renderWithProviders(<ProductView product={mockProductDetail} />) | ||
| renderWithProviders(<ProductView product={mockProductDetail} />, { | ||
| wrapperProps: {basket: mockBasket} | ||
| }) | ||
|
|
||
| const quantityInput = await screen.findByRole('spinbutton') | ||
| const incrementButton = screen.getByTestId('quantity-increment') | ||
|
|
@@ -179,7 +197,10 @@ describe('ProductView Component', () => { | |
| test('renders a product set properly - parent item', () => { | ||
| const parent = mockProductSet | ||
| renderWithProviders( | ||
| <MockComponent product={parent} addToCart={() => {}} addToWishlist={() => {}} /> | ||
| <MockComponent product={parent} addToCart={() => {}} addToWishlist={() => {}} />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| // NOTE: there can be duplicates of the same element, due to mobile and desktop views | ||
|
|
@@ -204,7 +225,10 @@ test('renders a product set properly - parent item', () => { | |
| test('renders a product set properly - child item', () => { | ||
| const child = mockProductSet.setProducts[0] | ||
| renderWithProviders( | ||
| <MockComponent product={child} addToCart={() => {}} addToWishlist={() => {}} /> | ||
| <MockComponent product={child} addToCart={() => {}} addToWishlist={() => {}} />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
|
||
| ) | ||
|
|
||
| // NOTE: there can be duplicates of the same element, due to mobile and desktop views | ||
|
|
@@ -239,7 +263,10 @@ test('validateOrderability callback is called when adding a set to cart', async | |
| validateOrderability={validateOrderability} | ||
| addToCart={() => {}} | ||
| addToWishlist={() => {}} | ||
| /> | ||
| />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| const button = screen.getByRole('button', {name: /add set to cart/i}) | ||
|
|
@@ -262,7 +289,10 @@ test('onVariantSelected callback is called after successfully selected a variant | |
| onVariantSelected={onVariantSelected} | ||
| addToCart={() => {}} | ||
| addToWishlist={() => {}} | ||
| /> | ||
| />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| const size = screen.getByRole('radio', {name: /xl/i}) | ||
|
|
@@ -280,7 +310,10 @@ describe('add to cart button loading tests', () => { | |
| product={mockProductDetail} | ||
| addToCart={() => {}} | ||
| isBasketLoading={true} | ||
| /> | ||
| />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
| expect(screen.getByRole('button', {name: /add to cart/i})).toBeDisabled() | ||
| }) | ||
|
|
@@ -291,7 +324,10 @@ describe('add to cart button loading tests', () => { | |
| product={mockProductDetail} | ||
| addToCart={() => {}} | ||
| isBasketLoading={false} | ||
| /> | ||
| />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
| expect(screen.getByRole('button', {name: /add to cart/i})).toBeEnabled() | ||
| }) | ||
|
|
@@ -300,7 +336,10 @@ describe('add to cart button loading tests', () => { | |
| test('renders a product bundle properly - parent item', () => { | ||
| const parent = mockProductBundle | ||
| renderWithProviders( | ||
| <MockComponent product={parent} addToCart={() => {}} addToWishlist={() => {}} /> | ||
| <MockComponent product={parent} addToCart={() => {}} addToWishlist={() => {}} />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| // NOTE: there can be duplicates of the same element, due to mobile and desktop views | ||
|
|
@@ -330,7 +369,10 @@ test('renders a product bundle properly - child item', () => { | |
| addToWishlist={() => {}} | ||
| isProductPartOfBundle={true} | ||
| setChildProductOrderability={() => {}} | ||
| /> | ||
| />, | ||
| { | ||
| wrapperProps: {basket: mockBasket} | ||
| } | ||
| ) | ||
|
|
||
| const addToCartButton = screen.queryByRole('button', {name: /add to cart/i}) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change name to bonusItem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this to within the "isValidResponse" check, right?