@@ -988,6 +988,47 @@ final class OrderDetailsDataSourceTests: XCTestCase {
988988 let row = row ( row: . shippingLine, in: shippingSection)
989989 XCTAssertNotNil ( row)
990990 }
991+
992+ func test_purchased_shipping_labels_sections_are_ordered_and_have_correct_titles( ) async throws {
993+ // Given
994+ var order = makeOrder ( )
995+ let shippingLabel1 = ShippingLabel . fake ( ) . copy ( siteID: order. siteID, orderID: order. orderID, shipmentID: " 1 " )
996+ let shippingLabel2 = ShippingLabel . fake ( ) . copy ( siteID: order. siteID, orderID: order. orderID, shipmentID: " 0 " )
997+ order = order. copy ( shippingLabels: [ shippingLabel1, shippingLabel2] )
998+ insert ( shippingLabel: shippingLabel1, order: order)
999+ insert ( shippingLabel: shippingLabel2, order: order)
1000+
1001+ let dataSource = OrderDetailsDataSource ( order: order,
1002+ storageManager: storageManager,
1003+ cardPresentPaymentsConfiguration: Mocks . configuration,
1004+ receiptEligibilityUseCase: MockReceiptEligibilityUseCase ( ) ,
1005+ featureFlags: MockFeatureFlagService ( revampedShippingLabelCreation: false ) )
1006+ dataSource. configureResultsControllers { }
1007+
1008+ // When
1009+ await dataSource. reloadSections ( )
1010+
1011+ // Then
1012+ // Get IndexPaths for all shipping label rows
1013+ var shippingLabelSectionsIndices : [ IndexPath ] = [ ]
1014+ for (sectionIndex, section) in dataSource. sections. enumerated ( ) {
1015+ for (rowIndex, row) in section. rows. enumerated ( ) where row == . shippingLabelDetail {
1016+ shippingLabelSectionsIndices. append ( IndexPath ( row: rowIndex, section: sectionIndex) )
1017+ }
1018+ }
1019+
1020+ XCTAssertEqual ( shippingLabelSectionsIndices. count, 2 )
1021+
1022+ let firstLabelSection = dataSource. sections [ shippingLabelSectionsIndices [ 0 ] . section]
1023+ XCTAssertEqual ( firstLabelSection. title, " Package 1 " )
1024+ let firstLabel = dataSource. shippingLabel ( at: shippingLabelSectionsIndices [ 0 ] )
1025+ XCTAssertEqual ( firstLabel, shippingLabel2)
1026+
1027+ let secondLabelSection = dataSource. sections [ shippingLabelSectionsIndices [ 1 ] . section]
1028+ XCTAssertEqual ( secondLabelSection. title, " Package 2 " )
1029+ let secondLabel = dataSource. shippingLabel ( at: shippingLabelSectionsIndices [ 1 ] )
1030+ XCTAssertEqual ( secondLabel, shippingLabel1)
1031+ }
9911032}
9921033
9931034// MARK: - Test Data
0 commit comments