-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathorders.test.js
More file actions
1445 lines (1325 loc) · 58 KB
/
orders.test.js
File metadata and controls
1445 lines (1325 loc) · 58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2025, salesforce.com, 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 {Route, Switch} from 'react-router-dom'
import {screen} from '@testing-library/react'
import {rest} from 'msw'
import {
renderWithProviders,
createPathWithDefaults
} from '@salesforce/retail-react-app/app/utils/test-utils'
import {
mockCustomerBaskets,
mockOrderHistory,
mockOrderProducts,
mockStore,
mockMultiShipmentOrder
} from '@salesforce/retail-react-app/app/mocks/mock-data'
import Orders from '@salesforce/retail-react-app/app/pages/account/orders'
import mockConfig from '@salesforce/retail-react-app/config/mocks/default'
// Simple mock order for SOM integration tests
const createMockOrder = (overrides = {}) => ({
orderNo: '00099999',
orderTotal: 99.99,
currency: 'USD',
creationDate: '2025-01-15T10:00:00.000Z',
status: 'open',
productItems: [{productId: 'test-product-1', productName: 'Test Product', quantity: 1}],
shipments: [
{
shippingMethod: {name: 'Ground'},
shippingStatus: 'not_shipped',
shippingAddress: {
firstName: 'John',
lastName: 'Doe',
address1: '123 Test St',
city: 'Boston',
stateCode: 'MA',
postalCode: '02101'
}
}
],
billingAddress: {
firstName: 'Jane',
lastName: 'Smith',
address1: '456 Bill St',
city: 'Boston',
stateCode: 'MA',
postalCode: '02101'
},
paymentInstruments: [
{paymentCard: {cardType: 'Visa', numberLastDigits: '1111', holder: 'Jane Smith'}}
],
...overrides
})
// Mock OMS order (based on real API response structure)
const createMockOmsOrder = (overrides = {}) => ({
orderNo: 'dec1625xxx00000601',
orderTotal: 366.43,
currency: 'USD',
creationDate: '2026-01-14T01:43:00.000Z',
// Note: No 'status' field - OMS orders use omsData.status
omsData: {
status: 'Created',
shipments: [
{
id: '0OBLT0000000Nav4AE',
status: 'Allocated',
provider: 'UPS',
trackingNumber: '123456789',
trackingUrl: 'https://www.ups.com/track?loc=en_US&tracknum=123456789',
expectedDeliveryDate: '2026-01-16T00:00:00.000Z'
}
]
},
productItems: [
{
productId: '640188017003M',
productName: 'Charcoal Flat Front Athletic Fit Shadow Striped Wool Suit',
quantity: 1,
omsData: {status: 'allocated', quantityAvailableToCancel: 0}
}
],
shipments: [
{
shipmentId: '0agLT00000Q4Sd3YAF',
shippingMethod: {
name: 'Ground',
description: 'Order received within 7-10 business days'
},
// Note: OMS uses fullName instead of firstName/lastName
shippingAddress: {
fullName: 'Alex Johnson',
address1: '2030 NE 8th st',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98121',
countryCode: 'US'
}
}
],
billingAddress: {
fullName: 'Alex Johnson',
address1: '2030 NE 8th st',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98121'
},
// Note: OMS orders may not have payment data
paymentInstruments: [],
...overrides
})
const MockedComponent = () => {
return (
<Switch>
<Route path={createPathWithDefaults('/account/orders')}>
<Orders />
</Route>
</Switch>
)
}
// Set up and clean up
beforeEach(() => {
global.server.use(
rest.get('*/customers/:customerId/baskets', (req, res, ctx) =>
res(ctx.delay(0), ctx.json(mockCustomerBaskets))
)
)
window.history.pushState({}, 'Account', createPathWithDefaults('/account/orders'))
})
afterEach(() => {
jest.resetModules()
localStorage.clear()
})
test('Renders order history and details', async () => {
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderHistory.data[0]))
}),
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderHistory))
}),
rest.get('*/products', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderProducts))
})
)
const {user} = renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(await screen.findAllByText(/Ordered: /i)).toHaveLength(3)
expect(
await screen.findAllByAltText(
'Pleated Bib Long Sleeve Shirt, Silver Grey, small',
{},
{timeout: 500}
)
).toHaveLength(3)
await user.click((await screen.findAllByText(/view details/i))[0])
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText(/order number: 00028011/i)).toBeInTheDocument()
expect(
await screen.findByAltText(/Pleated Bib Long Sleeve Shirt, Silver Grey, small/i)
).toBeInTheDocument()
expect(
await screen.findByAltText(/Long Sleeve Crew Neck, Fire Red, small/i)
).toBeInTheDocument()
})
test('Renders order history place holder when no orders', async () => {
global.server.use(
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json({limit: 0, offset: 0, total: 0}))
})
)
await renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-place-holder')).toBeInTheDocument()
})
describe('Order with empty product list', () => {
let user
beforeEach(async () => {
const emptyProductOrder = {
...mockOrderHistory.data[0],
productItems: []
}
const mockOrderHistoryWithEmptyProduct = {
...mockOrderHistory,
data: [emptyProductOrder]
}
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(emptyProductOrder))
}),
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderHistoryWithEmptyProduct))
})
)
const renderResult = renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
user = renderResult.user
})
test('should render order history page', async () => {
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
})
test('should render order details page', async () => {
await user.click((await screen.findAllByText(/view details/i))[0])
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should show 0 items', async () => {
await user.click((await screen.findAllByText(/view details/i))[0])
expect(await screen.findByText(/0 items/i)).toBeInTheDocument()
})
test('should not render products', async () => {
await user.click((await screen.findAllByText(/view details/i))[0])
expect(screen.queryByAltText(/Pleated Bib Long Sleeve Shirt/i)).not.toBeInTheDocument()
})
})
describe('Direct navigation to order details and back to order list', () => {
let user, orderNo
beforeEach(async () => {
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderHistory.data[0]))
}),
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderHistory))
}),
rest.get('*/products', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderProducts))
})
)
orderNo = mockOrderHistory.data[0].orderNo
window.history.pushState(
{},
'Order Details',
createPathWithDefaults(`/account/orders/${orderNo}`)
)
const renderResult = renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
user = renderResult.user
})
test('should render order details page on direct navigation', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(window.location.pathname).toMatch(new RegExp(`/account/orders/${orderNo}$`))
})
test('should navigate back to order history page', async () => {
await user.click(await screen.findByRole('link', {name: /back to order history/i}))
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(window.location.pathname).toMatch(/\/account\/orders$/)
})
test('should show all orders', async () => {
await user.click(await screen.findByRole('link', {name: /back to order history/i}))
expect(await screen.findAllByText(/Ordered: /i)).toHaveLength(3)
})
test('should show all products', async () => {
await user.click(await screen.findByRole('link', {name: /back to order history/i}))
expect(
await screen.findAllByAltText(
'Pleated Bib Long Sleeve Shirt, Silver Grey, small',
{},
{timeout: 500}
)
).toHaveLength(3)
})
})
describe('Handles order with missing or partial data gracefully', () => {
let orderNo
beforeEach(async () => {
const partialOrder = {
...mockOrderHistory.data[0],
billingAddress: undefined,
shipments: undefined,
paymentInstruments: undefined,
creationDate: undefined
}
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(partialOrder))
}),
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json({...mockOrderHistory, data: [partialOrder]}))
})
)
orderNo = partialOrder.orderNo
window.history.pushState(
{},
'Order Details',
createPathWithDefaults(`/account/orders/${orderNo}`)
)
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
})
test('should render order details page', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should show the Order Details header', async () => {
expect(screen.getByRole('heading', {name: /order details/i})).toBeInTheDocument()
})
test('should not render billing, payment, or shipping sections', async () => {
expect(screen.queryByText(/billing address/i)).not.toBeInTheDocument()
expect(screen.queryByText(/payment method/i)).not.toBeInTheDocument()
expect(screen.queryByText(/shipping address/i)).not.toBeInTheDocument()
})
})
// Helper to setup order details page with mock order data
const setupOrderDetailsPage = (mockOrder) => {
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrder))
})
)
window.history.pushState(
{},
'Order Details',
createPathWithDefaults(`/account/orders/${mockOrder.orderNo}`)
)
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
}
describe('Order without payment data', () => {
beforeEach(async () => {
setupOrderDetailsPage(createMockOrder({paymentInstruments: []}))
})
test('should render order details page', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should not display payment method section', async () => {
await screen.findByTestId('account-order-details-page')
expect(screen.queryByText(/payment method/i)).not.toBeInTheDocument()
})
})
describe('OMS/SOM Integration - Order Details', () => {
// ECOM order tests - uses order.status, firstName/lastName, and has payment data
test('should display ECOM order status from order.status', async () => {
setupOrderDetailsPage(createMockOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText('open')).toBeInTheDocument()
})
test('should display firstName + lastName for ECOM shipping address', async () => {
setupOrderDetailsPage(createMockOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText(/John Doe/i)).toBeInTheDocument()
})
test('should display payment method for ECOM order', async () => {
setupOrderDetailsPage(createMockOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /payment method/i})).toBeInTheDocument()
})
// OMS order tests - uses omsData.status, fullName, and has no payment data
test('should display OMS status from omsData.status', async () => {
setupOrderDetailsPage(createMockOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText('Created')).toBeInTheDocument()
})
test('should display fullName for OMS shipping address', async () => {
setupOrderDetailsPage(createMockOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText(/Alex Johnson/i)).toBeInTheDocument()
})
test('should NOT display payment method for OMS order', async () => {
setupOrderDetailsPage(createMockOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(screen.queryByRole('heading', {name: /payment method/i})).not.toBeInTheDocument()
})
})
describe('OMS/SOM Integration - Order History', () => {
// Helper to setup order history with mock data
const setupOrderHistoryMock = (orderData) => {
global.server.use(
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(
ctx.delay(0),
ctx.json({limit: 10, offset: 0, total: 1, data: [orderData]})
)
}),
rest.get('*/products', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderProducts))
})
)
}
// ECOM order tests - uses order.status and firstName/lastName
test('should display ECOM order status from order.status', async () => {
setupOrderHistoryMock(createMockOrder())
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(await screen.findByText('open')).toBeInTheDocument()
})
test('should display firstName + lastName for ECOM shipping address', async () => {
setupOrderHistoryMock(createMockOrder())
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(await screen.findByText(/Shipped to: John Doe/i)).toBeInTheDocument()
})
// OMS order tests - uses omsData.status and fullName
test('should display OMS status from omsData.status', async () => {
setupOrderHistoryMock(createMockOmsOrder())
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(await screen.findByText('Created')).toBeInTheDocument()
})
test('should display fullName for OMS shipping address', async () => {
setupOrderHistoryMock(createMockOmsOrder())
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
expect(await screen.findByTestId('account-order-history-page')).toBeInTheDocument()
expect(await screen.findByText(/Shipped to: Alex Johnson/i)).toBeInTheDocument()
})
})
describe('Order with multiple shipments (pickup and delivery)', () => {
let orderNo
beforeEach(async () => {
global.server.use(
rest.get('*/orders/:orderNo', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockMultiShipmentOrder))
}),
rest.get('*/customers/:customerId/orders', (req, res, ctx) => {
return res(
ctx.delay(0),
ctx.json({...mockOrderHistory, data: [mockMultiShipmentOrder]})
)
}),
rest.get('*/products', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockOrderProducts))
}),
rest.get('*/stores', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockStore))
})
)
orderNo = mockMultiShipmentOrder.orderNo
window.history.pushState(
{},
'Order Details',
createPathWithDefaults(`/account/orders/${orderNo}`)
)
renderWithProviders(<MockedComponent history={history} />, {
wrapperProps: {siteAlias: 'uk', appConfig: mockConfig.app}
})
})
test('should render order details page with multiple shipments', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should display pickup address section', async () => {
expect(await screen.findByRole('heading', {name: /pickup address/i})).toBeInTheDocument()
expect(await screen.findByText(/Downtown Store/i)).toBeInTheDocument()
})
test('should display shipping method and address sections', async () => {
expect(await screen.findByRole('heading', {name: /^shipping method$/i})).toBeInTheDocument()
expect(
await screen.findByRole('heading', {name: /^shipping address$/i})
).toBeInTheDocument()
})
test('should display delivery address details', async () => {
expect(await screen.findByText(/John Doe/i)).toBeInTheDocument()
expect(await screen.findByText(/123 Main St/i)).toBeInTheDocument()
expect(await screen.findByText(/Boston/i)).toBeInTheDocument()
})
test('should display shipping method name', async () => {
expect(await screen.findByText(/Ground/i)).toBeInTheDocument()
})
test('should display tracking number', async () => {
expect(await screen.findByText(/TRACK123456/i)).toBeInTheDocument()
})
test('should display both payment method and billing address', async () => {
expect(await screen.findByRole('heading', {name: /payment method/i})).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /billing address/i})).toBeInTheDocument()
})
})
describe('OMS Multi-shipment - Shipping address hidden', () => {
// When OMS has multiple shipments, shipping address should be hidden
// (can't reliably correlate OMS shipments to ECOM addresses by index)
const omsMultiShipmentOrder = createMockOmsOrder({
shipments: [
{
shippingMethod: {name: 'Ground'},
shippingAddress: {
fullName: 'Alice Johnson',
address1: '123 First St',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98101'
}
},
{
shippingMethod: {name: 'Express'},
shippingAddress: {
fullName: 'Bob Smith',
address1: '456 Second St',
city: 'Portland',
stateCode: 'OR',
postalCode: '97201'
}
}
],
omsData: {
status: 'Processing',
shipments: [
{
status: 'SHIPPED',
trackingNumber: 'OMS-001',
trackingUrl: 'https://track.example.com/OMS-001',
provider: 'FedEx'
},
{
status: 'PENDING',
trackingNumber: 'OMS-002',
trackingUrl: 'https://track.example.com/OMS-002',
provider: 'UPS'
}
]
}
})
beforeEach(async () => {
setupOrderDetailsPage(omsMultiShipmentOrder)
})
test('should render order details page', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should display numbered shipping method headings', async () => {
expect(await screen.findByRole('heading', {name: /shipping method 1/i})).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /shipping method 2/i})).toBeInTheDocument()
})
test('should NOT display shipping address headings for OMS multi-shipment', async () => {
await screen.findByTestId('account-order-details-page')
expect(screen.queryByRole('heading', {name: /shipping address/i})).not.toBeInTheDocument()
})
test('should display OMS provider name instead of ECOM shipping method', async () => {
expect(await screen.findByText(/FedEx/i)).toBeInTheDocument()
expect(await screen.findByText(/UPS/i)).toBeInTheDocument()
})
test('should display OMS shipment status', async () => {
expect(await screen.findByText(/SHIPPED/i)).toBeInTheDocument()
expect(await screen.findByText(/PENDING/i)).toBeInTheDocument()
})
test('should display tracking numbers as clickable links', async () => {
const trackingLink1 = await screen.findByRole('link', {name: /OMS-001/i})
expect(trackingLink1).toHaveAttribute('href', 'https://track.example.com/OMS-001')
const trackingLink2 = await screen.findByRole('link', {name: /OMS-002/i})
expect(trackingLink2).toHaveAttribute('href', 'https://track.example.com/OMS-002')
})
})
describe('ECOM Multi-shipment - Shipping address shown', () => {
// When ECOM has multiple shipments but NO OMS data, shipping address should be shown
const ecomMultiShipmentOrder = createMockOrder({
shipments: [
{
shippingMethod: {name: 'Ground'},
shippingStatus: 'shipped',
trackingNumber: 'ECOM-001',
shippingAddress: {
firstName: 'John',
lastName: 'Doe',
address1: '123 First St',
city: 'Boston',
stateCode: 'MA',
postalCode: '02101'
}
},
{
shippingMethod: {name: 'Express'},
shippingStatus: 'not_shipped',
shippingAddress: {
firstName: 'Jane',
lastName: 'Smith',
address1: '456 Second St',
city: 'Chicago',
stateCode: 'IL',
postalCode: '60601'
}
}
]
})
beforeEach(async () => {
setupOrderDetailsPage(ecomMultiShipmentOrder)
})
test('should render order details page', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should display numbered shipping method headings', async () => {
expect(await screen.findByRole('heading', {name: /shipping method 1/i})).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /shipping method 2/i})).toBeInTheDocument()
})
test('should display numbered shipping address headings for ECOM multi-shipment', async () => {
expect(
await screen.findByRole('heading', {name: /shipping address 1/i})
).toBeInTheDocument()
expect(
await screen.findByRole('heading', {name: /shipping address 2/i})
).toBeInTheDocument()
})
test('should display both shipping addresses', async () => {
expect(await screen.findByText(/John Doe/i)).toBeInTheDocument()
// Jane Smith appears in both shipping and billing address
const janeSmithElements = await screen.findAllByText(/Jane Smith/i)
expect(janeSmithElements).toHaveLength(2)
})
test('should display ECOM shipping statuses', async () => {
// Use exact match to avoid "Not shipped" matching "Shipped"
expect(await screen.findByText('Shipped')).toBeInTheDocument()
expect(await screen.findByText('Not shipped')).toBeInTheDocument()
})
})
describe('OMS Single shipment with tracking URL', () => {
// Single OMS shipment should show shipping address and tracking as clickable link
const omsSingleShipmentOrder = createMockOmsOrder({
shipments: [
{
shippingMethod: {name: 'Standard'},
shippingAddress: {
fullName: 'Alex Johnson',
address1: '789 Main St',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98101'
}
}
],
omsData: {
status: 'SHIPPED',
shipments: [
{
status: 'DELIVERED',
trackingNumber: 'TRACK-12345',
trackingUrl: 'https://tracking.fedex.com/TRACK-12345',
provider: 'FedEx Ground'
}
]
}
})
beforeEach(async () => {
setupOrderDetailsPage(omsSingleShipmentOrder)
})
test('should display shipping address for single OMS shipment', async () => {
expect(
await screen.findByRole('heading', {name: /^shipping address$/i})
).toBeInTheDocument()
expect(await screen.findByText(/Alex Johnson/i)).toBeInTheDocument()
})
test('should display OMS provider instead of ECOM method name', async () => {
expect(await screen.findByText(/FedEx Ground/i)).toBeInTheDocument()
})
test('should display tracking number as clickable link', async () => {
const trackingLink = await screen.findByRole('link', {name: /TRACK-12345/i})
expect(trackingLink).toHaveAttribute('href', 'https://tracking.fedex.com/TRACK-12345')
})
test('should display OMS shipment status (fallback to raw value)', async () => {
expect(await screen.findByText(/DELIVERED/i)).toBeInTheDocument()
})
})
describe('OMS Single shipment with partial data (missing provider, trackingUrl)', () => {
// Tests fallback behavior when OMS data is partially available
const omsPartialDataOrder = createMockOmsOrder({
shipments: [
{
shippingMethod: {name: 'Ground Shipping'},
shippingAddress: {
fullName: 'Mike Brown',
address1: '100 Oak St',
city: 'Denver',
stateCode: 'CO',
postalCode: '80201'
}
}
],
omsData: {
status: 'Processing',
shipments: [
{
status: 'ALLOCATED',
trackingNumber: 'OMS-TRACK-999'
// No provider field
// No trackingUrl - tracking number displayed as plain text
}
]
}
})
beforeEach(async () => {
setupOrderDetailsPage(omsPartialDataOrder)
})
test('should render order details page', async () => {
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
})
test('should fallback to ECOM shipping method name when OMS provider is missing', async () => {
expect(await screen.findByText(/Ground Shipping/i)).toBeInTheDocument()
})
test('should display OMS status even when other OMS fields are missing', async () => {
expect(await screen.findByText(/ALLOCATED/i)).toBeInTheDocument()
})
test('should display OMS tracking number (takes priority over ECOM)', async () => {
expect(await screen.findByText(/OMS-TRACK-999/i)).toBeInTheDocument()
// ECOM tracking should NOT be displayed
expect(screen.queryByText(/ECOM-TRACK-999/i)).not.toBeInTheDocument()
})
test('should display tracking number as plain text when trackingUrl is missing', async () => {
// Should NOT be a link
expect(screen.queryByRole('link', {name: /OMS-TRACK-999/i})).not.toBeInTheDocument()
// But should still show the tracking number as text
expect(await screen.findByText(/OMS-TRACK-999/i)).toBeInTheDocument()
})
test('should display shipping address with fullName', async () => {
expect(await screen.findByText(/Mike Brown/i)).toBeInTheDocument()
expect(await screen.findByText(/100 Oak St/i)).toBeInTheDocument()
})
})
describe('BOPIS Order with OMS Single Pickup and Single Delivery', () => {
// Helper to create BOPIS order with OMS data
const createBopisOmsOrder = (overrides = {}) => ({
orderNo: 'BOPIS-OMS-001',
currency: 'USD',
productItems: [{productId: 'product-1', quantity: 1}],
omsData: {
status: 'Processing',
shipments: [
{
status: 'SHIPPED',
provider: 'FedEx',
trackingNumber: 'BOPIS-TRACK-123',
trackingUrl: 'https://tracking.fedex.com/BOPIS-TRACK-123'
}
]
},
shipments: [
{
shipmentId: 'pickup1',
shippingMethod: {
c_storePickupEnabled: true
},
c_fromStoreId: '00001'
},
{
shipmentId: 'delivery1',
shippingMethod: {
name: 'Ground'
},
shippingAddress: {
fullName: 'Sarah Johnson',
address1: '456 Delivery St',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98101'
}
}
],
billingAddress: {
firstName: 'Sarah',
lastName: 'Johnson',
address1: '456 Delivery St',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98101'
},
paymentInstruments: [],
...overrides
})
test('should display OMS status for BOPIS order', async () => {
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText('Processing')).toBeInTheDocument()
})
test('should display pickup address section for BOPIS order', async () => {
global.server.use(
rest.get('*/stores', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockStore))
})
)
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /pickup address/i})).toBeInTheDocument()
expect(await screen.findByText('Pickup Address')).toBeInTheDocument()
})
test('should display pickup address details (store name, address, phone)', async () => {
global.server.use(
rest.get('*/stores', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockStore))
})
)
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText('Pickup Address')).toBeInTheDocument()
expect(await screen.findByText(/Downtown Store/i)).toBeInTheDocument()
expect(await screen.findByText(/100 Market St/i)).toBeInTheDocument()
expect(await screen.findByText(/San Francisco, CA 94105/i)).toBeInTheDocument()
expect(await screen.findByText(/Phone: \(415\) 555-0001/i)).toBeInTheDocument()
})
test('should display OMS provider for delivery shipment in BOPIS order', async () => {
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /^shipping method$/i})).toBeInTheDocument()
expect(await screen.findByText('Shipping Method')).toBeInTheDocument()
expect(await screen.findByText(/FedEx/i)).toBeInTheDocument()
expect(screen.queryByText(/Ground/i)).not.toBeInTheDocument()
const trackingLink = await screen.findByRole('link', {name: /BOPIS-TRACK-123/i})
expect(trackingLink).toHaveAttribute('href', 'https://tracking.fedex.com/BOPIS-TRACK-123')
expect(await screen.findByText(/SHIPPED/i)).toBeInTheDocument()
})
test('should NOT display shipping address for BOPIS OMS order with multiple shipments', async () => {
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
// Shipping address should be hidden for OMS multi-shipment orders
// (can't reliably correlate OMS shipments to ECOM addresses by index)
expect(screen.queryByRole('heading', {name: /^shipping address$/i})).not.toBeInTheDocument()
expect(screen.queryByText(/Sarah Johnson/i)).not.toBeInTheDocument()
})
test('should NOT display payment method for BOPIS OMS order', async () => {
setupOrderDetailsPage(createBopisOmsOrder())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(screen.queryByRole('heading', {name: /payment method/i})).not.toBeInTheDocument()
})
})
describe('BOPIS Order with OMS - Single Pickup Only', () => {
// OMS BOPIS order with only pickup shipment, no delivery
const createOmsBopisPickupOnly = () => ({
orderNo: 'OMS-BOPIS-PICKUP-001',
currency: 'USD',
productItems: [{productId: 'product-1', quantity: 1}],
omsData: {
status: 'Ready for Pickup',
shipments: [
{
status: 'READY_FOR_PICKUP',
provider: 'Store Pickup',
trackingNumber: 'PICKUP-12345',
trackingUrl: 'https://tracking.example.com/PICKUP-12345'
}
]
},
shipments: [
{
shipmentId: 'pickup1',
shippingMethod: {
c_storePickupEnabled: true
},
c_fromStoreId: '00001'
}
],
billingAddress: {
firstName: 'Alex',
lastName: 'Johnson',
address1: '2030 NE 8th st',
city: 'Seattle',
stateCode: 'WA',
postalCode: '98121'
},
paymentInstruments: []
})
test('should display OMS status for pickup-only BOPIS order', async () => {
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText(/Ready for Pickup/i)).toBeInTheDocument()
})
test('should display pickup address section', async () => {
global.server.use(
rest.get('*/stores', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockStore))
})
)
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /pickup address/i})).toBeInTheDocument()
expect(await screen.findByText('Pickup Address')).toBeInTheDocument()
})
test('should display pickup address details for OMS pickup-only order', async () => {
global.server.use(
rest.get('*/stores', (req, res, ctx) => {
return res(ctx.delay(0), ctx.json(mockStore))
})
)
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByText('Pickup Address')).toBeInTheDocument()
expect(await screen.findByText(/Downtown Store/i)).toBeInTheDocument()
expect(await screen.findByText(/100 Market St/i)).toBeInTheDocument()
})
test('should NOT display payment method for OMS pickup-only order', async () => {
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(screen.queryByRole('heading', {name: /payment method/i})).not.toBeInTheDocument()
})
test('should NOT display shipping method section (pickup only)', async () => {
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(screen.queryByRole('heading', {name: /shipping method/i})).not.toBeInTheDocument()
})
test('should NOT display shipping address section (pickup only)', async () => {
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(screen.queryByRole('heading', {name: /shipping address/i})).not.toBeInTheDocument()
})
test('should display billing address', async () => {
setupOrderDetailsPage(createOmsBopisPickupOnly())
expect(await screen.findByTestId('account-order-details-page')).toBeInTheDocument()
expect(await screen.findByRole('heading', {name: /billing address/i})).toBeInTheDocument()
expect(await screen.findByText(/Alex Johnson/i)).toBeInTheDocument()