-
Notifications
You must be signed in to change notification settings - Fork 212
@W-17442945 BOPIS Shop the Store PLP and PDP SteelThread #2226
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
hajinsuha1
merged 17 commits into
feature-bopis
from
W-17442945-bopis-shop-the-store-steelthread
Feb 14, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
051d825
initial PLP implementation
hajinsuha1 8cad090
initial implementation PDP
hajinsuha1 82a91f3
check inventoryId is in list of productInventories for checking inStock
hajinsuha1 626b051
Merge branch 'feature-bopis' into W-17442945-bopis-shop-the-store-ste…
hajinsuha1 c8bcbeb
clean up StoreAvailabilityText
hajinsuha1 304346a
add unit tests for StoreAvailabilityRefinement
hajinsuha1 47322e7
Merge branch 'W-17442945-bopis-shop-the-store-steelthread' of github.…
hajinsuha1 407f91d
update unit tests
hajinsuha1 16958ae
move StoreLocatorProvider to app level to ensure selectedStore is sav…
hajinsuha1 9bca83a
cleanup and update unit tests
hajinsuha1 30d4563
update changelog
hajinsuha1 369d2c7
add transaltions
hajinsuha1 b2fffc4
update PDP StoreAvailabilityText to display Out of Stock when selecte…
hajinsuha1 d926f3f
lint
hajinsuha1 a3cd356
move useStoreLocator to hooks
hajinsuha1 a1a10e7
fix unit tests
hajinsuha1 9842042
update use-store-locator unit tests
hajinsuha1 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
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
67 changes: 67 additions & 0 deletions
67
packages/template-retail-react-app/app/components/store-availability-text/index.jsx
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2024, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import React, {useContext} from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import {FormattedMessage} from 'react-intl' | ||
|
|
||
| // Components | ||
| import {Box, Link} from '@salesforce/retail-react-app/app/components/shared/ui' | ||
|
|
||
| // Others | ||
| import {StoreLocatorContext} from '@salesforce/retail-react-app/app/components/store-locator-modal' | ||
|
|
||
| const StoreAvailabilityText = ({productInventories}) => { | ||
| const {selectedStore, isStoreSelected} = useContext(StoreLocatorContext) | ||
| const inStock = | ||
| selectedStore.inventoryId && | ||
| Boolean( | ||
| productInventories?.find( | ||
| (inventory) => inventory.id === selectedStore.inventoryId && inventory.orderable | ||
| ) | ||
| ) | ||
|
|
||
| return ( | ||
| <Box gap={1} fontWeight={400} display="flex"> | ||
| {isStoreSelected ? ( | ||
| <> | ||
| {inStock ? ( | ||
| <FormattedMessage | ||
| id={'product_view.store_availability.in_stock_at'} | ||
| defaultMessage={'In Stock at'} | ||
| /> | ||
| ) : ( | ||
| <FormattedMessage | ||
| id={'product_view.store_availability.out_of_stock_at'} | ||
| defaultMessage={'Out of Stock at'} | ||
| /> | ||
| )} | ||
|
|
||
| <Link>{selectedStore.name}</Link> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <FormattedMessage | ||
| id={'product_view.store_availability.in_stock_at'} | ||
| defaultMessage={'In Stock at'} | ||
| /> | ||
| <Link> | ||
| <FormattedMessage | ||
| id={'product_view.link.select_store'} | ||
| defaultMessage={'Select Store'} | ||
| /> | ||
| </Link> | ||
| </> | ||
| )} | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| StoreAvailabilityText.propTypes = { | ||
| productInventories: PropTypes.arrayOf(PropTypes.object) | ||
| } | ||
|
|
||
| export default StoreAvailabilityText | ||
93 changes: 93 additions & 0 deletions
93
packages/template-retail-react-app/app/components/store-availability-text/index.test.js
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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright (c) 2024, Salesforce, Inc. | ||
| * All rights reserved. | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import React from 'react' | ||
| import {screen} from '@testing-library/react' | ||
| import PropTypes from 'prop-types' | ||
|
|
||
| import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils' | ||
| import StoreAvailabilityText from '@salesforce/retail-react-app/app/components/store-availability-text' | ||
| import {StoreLocatorContext} from '@salesforce/retail-react-app/app/components/store-locator-modal' | ||
|
|
||
| const selectedStore = { | ||
| name: 'Test Store', | ||
| id: 'test_store', | ||
| inventoryId: 'inventory_1' | ||
| } | ||
|
|
||
| const MockComponent = ({selectedStore, isStoreSelected = true, productInventories}) => { | ||
| return ( | ||
| <StoreLocatorContext.Provider value={{selectedStore, isStoreSelected}}> | ||
| <StoreAvailabilityText productInventories={productInventories} /> | ||
| </StoreLocatorContext.Provider> | ||
| ) | ||
| } | ||
| MockComponent.propTypes = { | ||
| selectedStore: PropTypes.object, | ||
| isStoreSelected: PropTypes.bool, | ||
| productInventories: PropTypes.array | ||
| } | ||
|
|
||
| describe('StoreAvailability', () => { | ||
| describe('store is not selected', () => { | ||
| test('renders "In Stock at Select Store"', () => { | ||
| renderWithProviders(<MockComponent selectedStore={{}} isStoreSelected={false} />) | ||
| expect(screen.getByText(/In Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(/Select Store/i)).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('store is selected', () => { | ||
| test('renders "Out of Stock at Test Store" when productInventories is undefined', () => { | ||
| renderWithProviders(<MockComponent selectedStore={selectedStore} />) | ||
| expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(selectedStore.name)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders "Out of Stock at Test Store" when selectedStore does not have an inventoryId', () => { | ||
| const storeWithNoInventoryId = {...selectedStore, inventoryId: null} | ||
| renderWithProviders(<MockComponent selectedStore={storeWithNoInventoryId} />) | ||
| expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(selectedStore.name)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders "Out of Stock at Test Store" if selectedStore inventoryId is not in productInventories', () => { | ||
| const productInventories = [{id: 'inventory_99', orderable: true}] | ||
| renderWithProviders( | ||
| <MockComponent | ||
| selectedStore={selectedStore} | ||
| productInventories={productInventories} | ||
| /> | ||
| ) | ||
| expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(selectedStore.name)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders "Out of Stock at Test Store" if orderable is false', () => { | ||
| const productInventories = [{id: 'inventory_1', orderable: false}] | ||
| renderWithProviders( | ||
| <MockComponent | ||
| selectedStore={selectedStore} | ||
| productInventories={productInventories} | ||
| /> | ||
| ) | ||
| expect(screen.getByText(/Out of Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(selectedStore.name)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders "In Stock at Test Store" if orderable is true', () => { | ||
| const productInventories = [{id: 'inventory_1', orderable: true}] | ||
| renderWithProviders( | ||
| <MockComponent | ||
| selectedStore={selectedStore} | ||
| productInventories={productInventories} | ||
| /> | ||
| ) | ||
| expect(screen.getByText(/In Stock at/i)).toBeInTheDocument() | ||
| expect(screen.getByText(selectedStore.name)).toBeInTheDocument() | ||
| }) | ||
| }) | ||
| }) |
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.
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.
it's possible to create a store with no name. Should we throw an error in that case?
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.
If a store is created with no name, that should be a concern on the BM/store creation side and not an error that the shoppers' UX should have to deal with. I think it would be fine to keep it simple and just display what the API gives.