Skip to content

Commit 339f739

Browse files
authored
W-18672755 - W-18397045 - Chakra UI order history and order detail (#2730)
* Order history and order detail
1 parent 55facea commit 339f739

File tree

22 files changed

+490
-561
lines changed

22 files changed

+490
-561
lines changed

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ module.exports = {
5959
// createTestGlob('pages/registration'), // TODO: enable after Account page has been migrated
6060
'<rootDir>/src/pages/checkout/partials/contact-info.test.js',
6161
'<rootDir>/src/pages/checkout/partials/login-state.test.js',
62+
'<rootDir>/src/pages/account/orders.test.js',
6263
'<rootDir>/src/utils/responsive-image.test.js',
6364
'<rootDir>/src/hooks/use-toast.test.js',
6465
'<rootDir>/src/pages/product-detail/metadata.test.js',
6566
'<rootDir>/src/pages/product-list/metadata.test.js',
66-
'<rootDir>/src/hooks/use-toast.test.js'
67+
'<rootDir>/src/hooks/use-toast.test.js',
68+
'<rootDir>/src/hooks/use-dnt-notification.test.js'
6769
// '<rootDir>/src/hooks/use-auth-modal.test.js' // TODO: enable after Account page has been migrated
6870
],
6971
moduleNameMapper: {

src/components/field/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const Field = ({
6060
const _inputProps =
6161
typeof inputProps === 'function' ? inputProps({value, onChange}) : inputProps
6262

63+
const {endElement, ...restOfInputProps} = _inputProps || {}
64+
6365
return (
6466
<ChakraField.Root id={name} invalid={!!error}>
6567
{!['checkbox', 'radio', 'hidden'].includes(type) &&
@@ -77,7 +79,7 @@ const Field = ({
7779
<PasswordIcon color="gray.500" boxSize={6} />
7880
</IconButton>
7981
) : (
80-
_inputProps?.endElement
82+
endElement
8183
)
8284
}
8385
>
@@ -92,7 +94,7 @@ const Field = ({
9294
type={inputType}
9395
placeholder={placeholder}
9496
autoComplete={autoComplete}
95-
{..._inputProps}
97+
{...restOfInputProps}
9698
/>
9799
{children}
98100
</>

src/components/header/index.jsx

Lines changed: 86 additions & 134 deletions
Large diffs are not rendered by default.

src/components/header/index.test.js

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ test('renders Header with event handlers', async () => {
102102
})
103103
const menu = screen.getByLabelText('Menu')
104104
const logo = screen.getByLabelText('Logo')
105-
const account = screen.getByLabelText(/Open account menu/i)
105+
const account = screen.getByLabelText(/My Account/i)
106106
const cart = screen.getByLabelText(/My cart, number of items: 2/)
107-
108107
await act(async () => {
109108
fireEvent.click(menu)
110109
})
@@ -121,13 +120,7 @@ test('renders Header with event handlers', async () => {
121120
expect(onMyCartClick).toHaveBeenCalledTimes(1)
122121

123122
await act(async () => {
124-
fireEvent.mouseEnter(account)
125-
})
126-
// The onClick handler is on the AccountIcon inside the button,
127-
// so we need to find and click that
128-
const accountIcon = account.querySelector('svg[aria-label="account"]')
129-
await act(async () => {
130-
fireEvent.click(accountIcon)
123+
fireEvent.click(account)
131124
})
132125
expect(onMyAccountClick).toHaveBeenCalledTimes(1)
133126
})
@@ -174,34 +167,18 @@ test('renders cart badge when basket is loaded', async () => {
174167
test('route to account page when an authenticated users click on account icon', async () => {
175168
const history = createMemoryHistory()
176169
history.push = jest.fn()
177-
renderWithProviders(<MockedComponent history={history} />)
170+
const {user} = renderWithProviders(<MockedComponent history={history} />)
178171

179172
await waitFor(() => {
180173
// Look for account button
181-
const accountTrigger = screen.getByLabelText(/Open account menu/)
174+
const accountTrigger = screen.getByLabelText(/My account/)
182175
expect(accountTrigger).toBeInTheDocument()
183176
})
184177

185-
const accountButton = screen.getByLabelText(/Open account menu/)
186-
187-
await act(async () => {
188-
// Use mouseEnter to open the popover, then click on the AccountIcon inside
189-
fireEvent.mouseEnter(accountButton)
190-
})
191-
192-
// The onClick handler is on the AccountIcon inside the button,
193-
// so we need to find and click that
194-
const accountIcon = accountButton.querySelector('svg[aria-label="account"]')
195-
await act(async () => {
196-
fireEvent.click(accountIcon)
197-
})
198-
await waitFor(() => {
199-
expect(history.push).toHaveBeenCalledWith(createPathWithDefaults('/account'))
200-
})
178+
const accountButton = screen.getByLabelText(/My account/)
201179

202-
// Test keyDown on the AccountIcon
203180
await act(async () => {
204-
fireEvent.keyDown(accountIcon, {key: 'Enter', code: 'Enter'})
181+
await user.click(accountButton)
205182
})
206183
await waitFor(() => {
207184
expect(history.push).toHaveBeenCalledWith(createPathWithDefaults('/account'))
@@ -228,41 +205,3 @@ test('route to wishlist page when an authenticated users click on wishlist icon'
228205
expect(history.push).toHaveBeenCalledWith(createPathWithDefaults('/account/wishlist'))
229206
})
230207
})
231-
232-
test('shows dropdown menu when an authenticated users hover on the account icon', async () => {
233-
global.server.use(
234-
rest.post('*/customers/action/login', (req, res, ctx) => {
235-
return res(ctx.delay(0), ctx.status(200), ctx.json(mockedRegisteredCustomer))
236-
})
237-
)
238-
const history = createMemoryHistory()
239-
history.push = jest.fn()
240-
241-
await act(async () => {
242-
renderWithProviders(<MockedComponent history={history} />)
243-
})
244-
245-
await waitFor(() => {
246-
// Look for account button
247-
const accountTrigger = screen.getByLabelText(/Open account menu/i)
248-
expect(accountTrigger).toBeInTheDocument()
249-
})
250-
251-
const accountButton = screen.getByLabelText(/Open account menu/i)
252-
253-
// Use mouseEnter to open the popover/dropdown
254-
await act(async () => {
255-
fireEvent.mouseEnter(accountButton)
256-
})
257-
258-
// Now check that the dropdown menu items are visible
259-
await waitFor(() => {
260-
expect(screen.getByText(/account details/i)).toBeInTheDocument()
261-
expect(screen.getByText(/addresses/i)).toBeInTheDocument()
262-
expect(screen.getByText(/wishlist/i)).toBeInTheDocument()
263-
expect(screen.getByText(/order history/i)).toBeInTheDocument()
264-
const logOutIcon = screen.getByLabelText('signout')
265-
expect(logOutIcon).toBeInTheDocument()
266-
expect(logOutIcon).toHaveAttribute('aria-hidden', 'true')
267-
})
268-
})

src/components/order-summary/index.jsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ const CartItems = ({basket}) => {
5757
</Box>
5858
<Accordion.ItemIndicator />
5959
</Accordion.ItemTrigger>
60-
<Accordion.ItemContent px={0} py={4}>
61-
<Stack gap={5} align="flex-start" separator={<Separator />}>
60+
<Accordion.ItemContent px="0" py="4">
61+
<Stack gap="5" alignItems="flex-start" separator={<Separator w="full" />}>
6262
{basket.productItems?.map((product, idx) => {
6363
const variant = {
6464
...product,
@@ -72,8 +72,8 @@ const CartItems = ({basket}) => {
7272
variant={variant}
7373
>
7474
<Flex width="full" alignItems="flex-start">
75-
<CartItemVariantImage width="80px" mr={2} />
76-
<Stack width="full" gap={1} marginTop="-3px">
75+
<CartItemVariantImage width="80px" mr="2" />
76+
<Stack width="full" gap="1" marginTop="-3px">
7777
<CartItemVariantName />
7878
<CartItemVariantAttributes includeQuantity />
7979
<CartItemVariantPrice
@@ -86,11 +86,13 @@ const CartItems = ({basket}) => {
8686
)
8787
})}
8888

89-
<Button as={Link} to="/cart" variant="link-blue" width="full">
90-
<FormattedMessage
91-
defaultMessage="Edit cart"
92-
id="order_summary.cart_items.link.edit_cart"
93-
/>
89+
<Button asChild to="/cart" variant="link-blue" width="full">
90+
<Link>
91+
<FormattedMessage
92+
defaultMessage="Edit cart"
93+
id="order_summary.cart_items.link.edit_cart"
94+
/>
95+
</Link>
9496
</Button>
9597
</Stack>
9698
</Accordion.ItemContent>
@@ -119,17 +121,15 @@ const OrderSummary = ({
119121
const hasShippingPromos = shippingItem?.priceAdjustments?.length > 0
120122

121123
return (
122-
<Stack data-testid="sf-order-summary" gap={5}>
123-
<Heading fontSize={fontSize} pt={1} id="order-summary-heading">
124+
<Stack data-testid="sf-order-summary" gap="5">
125+
<Heading fontSize={fontSize} pt="1" id="order-summary-heading">
124126
<FormattedMessage
125127
defaultMessage="Order Summary"
126128
id="order_summary.heading.order_summary"
127129
/>
128130
</Heading>
129-
130-
<Stack gap={4} align="flex-start" role="region" aria-labelledby="order-summary-heading">
131+
<Stack gap="4" align="flex-start" role="region" aria-labelledby="order-summary-heading">
131132
{showCartItems && <CartItems basket={basket} />}
132-
133133
<Stack w="full">
134134
<Flex justifyContent="space-between" aria-live="polite" aria-atomic="true">
135135
<Text fontWeight="bold" fontSize={fontSize}>
@@ -246,10 +246,9 @@ const OrderSummary = ({
246246
<PromoCode {...promoCodeProps} />
247247
</Box>
248248
) : (
249-
<Separator />
249+
<Separator w="full" />
250250
)}
251-
252-
<Stack gap={4} w="full">
251+
<Stack gap="4" w="full">
253252
<Flex
254253
w="full"
255254
justifyContent="space-between"
@@ -282,7 +281,7 @@ const OrderSummary = ({
282281

283282
{basket.couponItems?.length > 0 && (
284283
<Stack
285-
p={4}
284+
p="4"
286285
border="1px solid"
287286
borderColor="gray.100"
288287
borderRadius="base"
@@ -305,7 +304,7 @@ const OrderSummary = ({
305304
<Button
306305
variant="link-red"
307306
size="sm"
308-
colorPallete="red"
307+
colorPalete="red"
309308
onClick={() => removePromoCode(item.couponItemId)}
310309
>
311310
<FormattedMessage

src/components/section/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Section = ({title, subtitle, actions, maxWidth, children, ...props}) => {
2020
<Box as="section" paddingBottom="16" {...props}>
2121
<Stack gap={6} as={Container} maxW={sectionMaxWidth} textAlign="center">
2222
{title && (
23-
<Heading as="h2" fontSize={40} textAlign="center" fontWeight="bold">
23+
<Heading as="h2" fontSize={40} textAlign="center">
2424
{title}
2525
</Heading>
2626
)}

src/components/with-layout/with-layout.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {
2626
Flex,
2727
Heading,
2828
Spinner,
29+
30+
//hooks
2931
useDisclosure,
3032
useSlotRecipe,
3133
useToken
@@ -55,7 +57,7 @@ import {useExtensionConfig, useCurrentCustomer, useCurrentBasket} from '../../ho
5557
import {watchOnlineStatus, flatten} from '../../utils/utils'
5658
import useActiveData from '../../hooks/use-active-data'
5759
import useMultiSite from '../../hooks/use-multi-site'
58-
// import {DntNotification, useDntNotification} from '../../hooks/use-dnt-notification'
60+
import {DntNotification, useDntNotification} from '../../hooks/use-dnt-notification'
5961

6062
import {UserConfig} from '../../types/config'
6163

@@ -118,13 +120,17 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
118120
const history = useHistory()
119121
const location = useLocation()
120122
const authModal = useAuthModal()
121-
// const dntNotification = useDntNotification()
123+
const dntNotification = useDntNotification()
122124
const {site, locale, buildUrl} = useMultiSite()
123125
const [isOnline, setIsOnline] = useState<boolean>(true)
124126

125127
// https://www.chakra-ui.com/docs/theming/overview#tokens-1
126128
const [themeColor] = useToken('colors.blue', '600')
127-
const {open, onOpen, onClose} = useDisclosure()
129+
const {
130+
open: isDrawerMenuOpen,
131+
onOpen: onDrawerMenuOpen,
132+
onClose: onDrawerMenuClose
133+
} = useDisclosure()
128134

129135
// Used to conditionally render header/footer for checkout page
130136
const isCheckout = /\/checkout$/.test(location?.pathname)
@@ -179,7 +185,7 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
179185
useEffect(() => {
180186
// Lets automatically close the mobile navigation when the
181187
// location path is changed.
182-
onClose()
188+
onDrawerMenuClose()
183189
}, [location])
184190

185191
const onLogoClick = () => {
@@ -191,15 +197,15 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
191197
history.push(path)
192198

193199
// Close the drawer.
194-
onClose()
200+
onDrawerMenuClose()
195201
}
196202

197203
const onCartClick = () => {
198204
const path = buildUrl('/cart', site.id, locale.id)
199205
history.push(path)
200206

201207
// Close the drawer.
202-
onClose()
208+
onDrawerMenuClose()
203209
}
204210

205211
const onAccountClick = () => {
@@ -283,7 +289,7 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
283289
<>
284290
<AboveHeader />
285291
<Header
286-
onMenuClick={onOpen}
292+
onMenuClick={onDrawerMenuOpen}
287293
onLogoClick={onLogoClick}
288294
onMyCartClick={onCartClick}
289295
onMyAccountClick={onAccountClick}
@@ -292,8 +298,8 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
292298
{/* TODO: mobile menu */}
293299
<HideOnDesktop>
294300
<DrawerMenu
295-
isOpen={open}
296-
onClose={onClose}
301+
isOpen={isDrawerMenuOpen}
302+
onClose={onDrawerMenuClose}
297303
onLogoClick={onLogoClick}
298304
root={categories?.[CAT_MENU_DEFAULT_ROOT_CATEGORY]}
299305
itemsKey="categories"
@@ -343,7 +349,7 @@ const withLayout = <P extends object>(WrappedComponent: React.ComponentType<P>)
343349

344350
{!isCheckout ? <Footer /> : <CheckoutFooter />}
345351
<AuthModal {...(authModal as any)} />
346-
{/*<DntNotification {...dntNotification} />*/}
352+
<DntNotification {...dntNotification} />
347353
</AddToCartModalProvider>
348354
</Box>
349355
{(config.activeDataEnabled as boolean) && (

0 commit comments

Comments
 (0)