@@ -431,6 +431,78 @@ describe('ApplePayButtonStrategy', () => {
431
431
}
432
432
} ) ;
433
433
434
+ it ( 'gets shipping options sorted correctly with recommended option first' , async ( ) => {
435
+ const CheckoutButtonInitializeOptions = getApplePayButtonInitializationOptions ( ) ;
436
+ const newCheckout = {
437
+ ...getCheckout ( ) ,
438
+ consignments : [
439
+ {
440
+ ...getConsignment ( ) ,
441
+ availableShippingOptions : [
442
+ {
443
+ ...getShippingOption ( ) ,
444
+ description : 'Free Shipping' ,
445
+ additionalDescription : 'Free shipping to your order' ,
446
+ isRecommended : false ,
447
+ id : '0:11111111' ,
448
+ } ,
449
+ {
450
+ ...getShippingOption ( ) ,
451
+ id : '0:22222222' ,
452
+ } ,
453
+ ] ,
454
+ } ,
455
+ ] ,
456
+ } ;
457
+
458
+ const freeShippingOption = newCheckout . consignments [ 0 ] . availableShippingOptions [ 0 ] ;
459
+ const flatFeeShippingOption = newCheckout . consignments [ 0 ] . availableShippingOptions [ 1 ] ;
460
+
461
+ const expectedShippingMethods = [
462
+ {
463
+ label : flatFeeShippingOption . description ,
464
+ amount : flatFeeShippingOption . cost . toFixed ( 2 ) ,
465
+ detail : flatFeeShippingOption . additionalDescription ,
466
+ identifier : flatFeeShippingOption . id ,
467
+ } ,
468
+ {
469
+ label : freeShippingOption . description ,
470
+ amount : freeShippingOption . cost . toFixed ( 2 ) ,
471
+ detail : freeShippingOption . additionalDescription ,
472
+ identifier : freeShippingOption . id ,
473
+ } ,
474
+ ] ;
475
+
476
+ jest . spyOn ( checkoutActionCreator , 'loadDefaultCheckout' ) . mockReturnValue ( ( ) =>
477
+ from ( [
478
+ createAction ( CheckoutActionType . LoadCheckoutRequested ) ,
479
+ createAction ( CheckoutActionType . LoadCheckoutSucceeded , newCheckout ) ,
480
+ ] ) ,
481
+ ) ;
482
+
483
+ await strategy . initialize ( CheckoutButtonInitializeOptions ) ;
484
+
485
+ if ( CheckoutButtonInitializeOptions . applepay ) {
486
+ const button = container . firstChild as HTMLElement ;
487
+
488
+ if ( button ) {
489
+ button . click ( ) ;
490
+
491
+ const event = {
492
+ shippingContact : getContactAddress ( ) ,
493
+ } as ApplePayJS . ApplePayShippingContactSelectedEvent ;
494
+
495
+ await applePaySession . onshippingcontactselected ( event ) ;
496
+
497
+ const actualShippingMethods =
498
+ applePaySession . completeShippingContactSelection . mock . calls [ 0 ] [ 0 ]
499
+ . newShippingMethods ;
500
+
501
+ expect ( actualShippingMethods ) . toEqual ( expectedShippingMethods ) ;
502
+ }
503
+ }
504
+ } ) ;
505
+
434
506
it ( 'gets call to update shipping option in consignment fails' , async ( ) => {
435
507
jest . spyOn ( consignmentActionCreator , 'selectShippingOption' ) . mockRejectedValue ( false ) ;
436
508
0 commit comments