@@ -11,6 +11,55 @@ import XCTest
1111
1212@MainActor
1313final class ShippingAddressElementConfigurationTests : XCTestCase {
14+ func testCheckoutInitializesShippingAddressElement( ) async throws {
15+ // Given
16+ var sessionJSON = CheckoutTestHelpers . openSessionJSON
17+ sessionJSON [ " shipping_address_collection " ] = [ " allowed_countries " : [ " US " , " CA " ] ]
18+ var elementsSessionJSON = CheckoutTestHelpers . minimalElementsSessionJSON
19+ elementsSessionJSON [ " flags " ] = [ " ocs_mobile_should_use_autocomplete_proxy_endpoints " : true ]
20+ sessionJSON [ " elements_session " ] = elementsSessionJSON
21+ let apiResponse = try XCTUnwrap ( PaymentPagesAPIResponse . decodedObject ( fromAPIResponse: sessionJSON) )
22+
23+ var configuration = Checkout . Configuration (
24+ clientSecret: " cs_test_123_secret_abc " ,
25+ returnURL: " stripe-ios-test://checkout-return "
26+ )
27+ configuration. shippingAddressElement. title = " Delivery address "
28+ configuration. shippingAddressElement. buttonTitle = " Save delivery address "
29+ configuration. shippingAddressElement. appearance. colors. primary = . purple
30+ var shippingDetails = Checkout . Configuration. Defaults. ShippingDetails ( )
31+ shippingDetails. name = " Jenny Rosen "
32+ shippingDetails. address = . init(
33+ country: " US " ,
34+ line1: " 510 Townsend St. " ,
35+ city: " San Francisco " ,
36+ state: " CA " ,
37+ postalCode: " 94103 "
38+ )
39+ configuration. defaults. shippingDetails = shippingDetails
40+ configuration = CheckoutTestHelpers . makeConfiguration (
41+ apiResponse: apiResponse,
42+ configuration: configuration
43+ )
44+
45+ // When
46+ let checkout = try await Checkout ( configuration: configuration)
47+ let shippingAddressElement = checkout. getShippingAddressElement ( )
48+ let addressConfiguration = shippingAddressElement. addressViewController. configuration
49+
50+ // Then
51+ XCTAssertTrue ( shippingAddressElement === checkout. getShippingAddressElement ( ) )
52+ XCTAssertEqual ( addressConfiguration. title, " Delivery address " )
53+ XCTAssertEqual ( addressConfiguration. buttonTitle, " Save delivery address " )
54+ XCTAssertEqual ( addressConfiguration. appearance. colors. primary, . purple)
55+ XCTAssertEqual ( addressConfiguration. allowedCountries, [ " US " , " CA " ] )
56+ XCTAssertEqual ( addressConfiguration. defaultValues. name, " Jenny Rosen " )
57+ XCTAssertEqual ( addressConfiguration. defaultValues. address. country, " US " )
58+ XCTAssertEqual ( addressConfiguration. defaultValues. address. line1, " 510 Townsend St. " )
59+ XCTAssertTrue ( addressConfiguration. apiClient === configuration. apiClient)
60+ XCTAssertTrue ( addressConfiguration. useAutocompleteEndpoints)
61+ }
62+
1463 func testMakeAddressViewControllerConfiguration( ) {
1564 // Given
1665 let apiClient = STPAPIClient ( publishableKey: " pk_test_123 " )
0 commit comments