Skip to content

Commit 456565f

Browse files
add tests
1 parent 42ab00f commit 456565f

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

packages/template-retail-react-app/app/pages/account/order-detail.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ const AccountOrderDetail = () => {
115115
const {formatMessage, formatDate} = useIntl()
116116
const storeLocatorEnabled = getConfig()?.app?.storeLocatorEnabled ?? STORE_LOCATOR_IS_ENABLED
117117

118+
// expand: 'oms' returns order data from OMS if the order is successfully
119+
// ingested to OMS, otherwise returns data from ECOM
120+
// For regular non-oms orders, the order data is returned from ECOM
118121
const {data: order, isLoading: isOrderLoading} = useOrder(
119122
{
120123
parameters: {

packages/template-retail-react-app/app/pages/account/orders.test.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,122 @@ describe('Handles order with missing or partial data gracefully', () => {
239239
})
240240
})
241241

242+
// Helper to setup order details page with mock order data
243+
const setupOrderDetailsPage = (mockOrder) => {
244+
global.server.use(
245+
rest.get('*/orders/:orderNo', (req, res, ctx) => {
246+
return res(ctx.delay(0), ctx.json(mockOrder))
247+
})
248+
)
249+
window.history.pushState(
250+
{},
251+
'Order Details',
252+
createPathWithDefaults(`/account/orders/${mockOrder.orderNo}`)
253+
)
254+
renderWithProviders(<MockedComponent history={history} />, {
255+
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
256+
})
257+
}
258+
259+
describe('Order with ECOM status (non-OMS)', () => {
260+
beforeEach(async () => {
261+
const ecomOrder = {
262+
...mockOrderHistory.data[0],
263+
status: 'new'
264+
}
265+
setupOrderDetailsPage(ecomOrder)
266+
})
267+
268+
test('should display ECOM status when present', async () => {
269+
const statusBadge = await screen.findByText('new')
270+
expect(statusBadge).toBeInTheDocument()
271+
})
272+
})
273+
274+
describe('Order with OMS data', () => {
275+
beforeEach(async () => {
276+
const omsOrder = {
277+
...mockOrderHistory.data[0],
278+
status: undefined,
279+
omsData: {status: 'SHIPPED'}
280+
}
281+
setupOrderDetailsPage(omsOrder)
282+
})
283+
284+
test('should display OMS status when ECOM status is not present', async () => {
285+
const statusBadge = await screen.findByText('SHIPPED')
286+
expect(statusBadge).toBeInTheDocument()
287+
})
288+
})
289+
290+
describe('Order without payment data', () => {
291+
beforeEach(async () => {
292+
const orderWithoutPayment = {
293+
...mockOrderHistory.data[0],
294+
paymentInstruments: []
295+
}
296+
setupOrderDetailsPage(orderWithoutPayment)
297+
})
298+
299+
test('should render order details page', async () => {
300+
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
301+
})
302+
303+
test('should not display payment method section', async () => {
304+
await screen.findByTestId('account-order-details-page')
305+
expect(screen.queryByText(/payment method/i)).not.toBeInTheDocument()
306+
})
307+
})
308+
309+
describe('Order with firstName and lastName for shipping address', () => {
310+
beforeEach(async () => {
311+
const orderWithNames = {
312+
...mockOrderHistory.data[0],
313+
shipments: [
314+
{
315+
...mockOrderHistory.data[0].shipments[0],
316+
shippingAddress: {
317+
...mockOrderHistory.data[0].shipments[0].shippingAddress,
318+
firstName: 'Jane',
319+
lastName: 'Doe',
320+
fullName: 'Should Not Display'
321+
}
322+
}
323+
]
324+
}
325+
setupOrderDetailsPage(orderWithNames)
326+
})
327+
328+
test('should display firstName + lastName when both present', async () => {
329+
expect(await screen.findByText(/Jane Doe/i)).toBeInTheDocument()
330+
expect(screen.queryByText(/Should Not Display/i)).not.toBeInTheDocument()
331+
})
332+
})
333+
334+
describe('Order with fullName fallback for shipping address', () => {
335+
beforeEach(async () => {
336+
const orderWithFullName = {
337+
...mockOrderHistory.data[0],
338+
shipments: [
339+
{
340+
...mockOrderHistory.data[0].shipments[0],
341+
shippingAddress: {
342+
...mockOrderHistory.data[0].shipments[0].shippingAddress,
343+
firstName: undefined,
344+
lastName: undefined,
345+
fullName: 'John Smith'
346+
}
347+
}
348+
]
349+
}
350+
setupOrderDetailsPage(orderWithFullName)
351+
})
352+
353+
test('should display fullName when firstName and lastName are not present', async () => {
354+
expect(await screen.findByText(/John Smith/i)).toBeInTheDocument()
355+
})
356+
})
357+
242358
describe('Order with multiple shipments (pickup and delivery)', () => {
243359
let orderNo
244360

0 commit comments

Comments
 (0)