-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] feat: Address Element 🏘 #1169
Merged
charliecruzan-stripe
merged 17 commits into
address-element-private-beta
from
charliecruzan/shippingaddresselement
Oct 14, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0cc64d7
set up ios private branch tracking
charliecruzan-stripe 4250035
private feature branch tracking
charliecruzan-stripe eb22939
types and JS
charliecruzan-stripe f504d10
js updates
charliecruzan-stripe 19c0f74
android addresssheetview and fragment
charliecruzan-stripe fa2d018
rewrite payment sheet appearance builders a bit
charliecruzan-stripe 9181b4b
ios implementation
charliecruzan-stripe 45d3278
change onCancel to onError
charliecruzan-stripe 7fb98e1
add defaultShippingDetails to initPaymentSheet
charliecruzan-stripe 44242fe
organize
charliecruzan-stripe 2c0a6b9
move away from singleton
charliecruzan-stripe 9bb2884
handle errors gracefully
charliecruzan-stripe 8a12a56
fix private feature branch tracking on android
charliecruzan-stripe f7398fa
[skip actions] changelog
charliecruzan-stripe 9b5c69e
ios tests
charliecruzan-stripe f99d27e
android tests
charliecruzan-stripe 84ec306
add beta release script [skip actions]
charliecruzan-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
// | ||
// AddressSheetUtilsTests.swift | ||
// stripe-react-native-Unit-Tests | ||
// | ||
// Created by Charles Cruzan on 10/13/22. | ||
// | ||
|
||
import XCTest | ||
@testable import stripe_react_native | ||
import Stripe | ||
|
||
class AddressSheetUtilsTests: XCTestCase { | ||
let testCity = "testCity" | ||
let testCountry = "testCountry" | ||
let testLine1 = "testLine1" | ||
let testLine2 = "testLine2" | ||
let testPostalCode = "testPostalCode" | ||
let testState = "testState" | ||
let testName = "testName" | ||
let testPhone = "testPhone" | ||
|
||
func test_buildDefaultValues_whenPassedNil() throws { | ||
let result = AddressSheetUtils.buildDefaultValues(params: nil) | ||
XCTAssertEqual( | ||
result.address, PaymentSheet.Address() | ||
) | ||
XCTAssertEqual( | ||
result.name, nil | ||
) | ||
XCTAssertEqual( | ||
result.phone, nil | ||
) | ||
XCTAssertEqual( | ||
result.isCheckboxSelected, nil | ||
) | ||
} | ||
|
||
func test_buildDefaultValues_whenPassedValues() throws { | ||
let result = AddressSheetUtils.buildDefaultValues( | ||
params: ["name": testName, | ||
"phone": testPhone, | ||
"address": ["city": testCity], | ||
"isCheckboxSelected": true] | ||
) | ||
XCTAssertEqual( | ||
result.address.city, testCity | ||
) | ||
XCTAssertEqual( | ||
result.name, testName | ||
) | ||
XCTAssertEqual( | ||
result.phone, testPhone | ||
) | ||
XCTAssertEqual( | ||
result.isCheckboxSelected, true | ||
) | ||
} | ||
|
||
func test_buildAddressDetails_whenPassedNil() throws { | ||
let result = AddressSheetUtils.buildAddressDetails(params: nil) | ||
XCTAssertEqual( | ||
result.address.country, "" | ||
) | ||
XCTAssertEqual( | ||
result.address.line1, "" | ||
) | ||
XCTAssertEqual( | ||
result.name, nil | ||
) | ||
XCTAssertEqual( | ||
result.phone, nil | ||
) | ||
XCTAssertEqual( | ||
result.isCheckboxSelected, nil | ||
) | ||
} | ||
|
||
func test_buildAddressDetails_whenPassedValues() throws { | ||
let result = AddressSheetUtils.buildAddressDetails( | ||
params: ["name": testName, | ||
"phone": testPhone, | ||
"address": ["city": testCity], | ||
"isCheckboxSelected": true] | ||
) | ||
|
||
XCTAssertEqual( | ||
result.address.city, testCity | ||
) | ||
XCTAssertEqual( | ||
result.address.line1, "" | ||
) | ||
XCTAssertEqual( | ||
result.name, testName | ||
) | ||
XCTAssertEqual( | ||
result.phone, testPhone | ||
) | ||
XCTAssertEqual( | ||
result.isCheckboxSelected, true | ||
) | ||
} | ||
|
||
func test_buildAddress_forPaymentSheet_whenPassedNil() throws { | ||
let result: PaymentSheet.Address = AddressSheetUtils.buildAddress(params: nil) | ||
|
||
XCTAssertEqual( | ||
result.city, nil | ||
) | ||
XCTAssertEqual( | ||
result.line1, nil | ||
) | ||
XCTAssertEqual( | ||
result.line2, nil | ||
) | ||
XCTAssertEqual( | ||
result.country, nil | ||
) | ||
XCTAssertEqual( | ||
result.postalCode, nil | ||
) | ||
XCTAssertEqual( | ||
result.state, nil | ||
) | ||
} | ||
|
||
func test_buildAddress_forPaymentSheet_whenPassedValues() throws { | ||
let result: PaymentSheet.Address = AddressSheetUtils.buildAddress( | ||
params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState] | ||
) | ||
|
||
XCTAssertEqual( | ||
result.city, testCity | ||
) | ||
XCTAssertEqual( | ||
result.line1, testLine1 | ||
) | ||
XCTAssertEqual( | ||
result.line2, testLine2 | ||
) | ||
XCTAssertEqual( | ||
result.country, testCountry | ||
) | ||
XCTAssertEqual( | ||
result.postalCode, testPostalCode | ||
) | ||
XCTAssertEqual( | ||
result.state, testState | ||
) | ||
} | ||
|
||
func test_buildAddress_forAddressViewController_whenPassedNil() throws { | ||
let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress(params: nil) | ||
|
||
XCTAssertEqual( | ||
result.city, nil | ||
) | ||
XCTAssertEqual( | ||
result.line1, "" | ||
) | ||
XCTAssertEqual( | ||
result.line2, nil | ||
) | ||
XCTAssertEqual( | ||
result.country, "" | ||
) | ||
XCTAssertEqual( | ||
result.postalCode, nil | ||
) | ||
XCTAssertEqual( | ||
result.state, nil | ||
) | ||
} | ||
|
||
func test_buildAddress_forAddressViewController_whenPassedValues() throws { | ||
let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress( | ||
params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState] | ||
) | ||
|
||
XCTAssertEqual( | ||
result.city, testCity | ||
) | ||
XCTAssertEqual( | ||
result.line1, testLine1 | ||
) | ||
XCTAssertEqual( | ||
result.line2, testLine2 | ||
) | ||
XCTAssertEqual( | ||
result.country, testCountry | ||
) | ||
XCTAssertEqual( | ||
result.postalCode, testPostalCode | ||
) | ||
XCTAssertEqual( | ||
result.state, testState | ||
) | ||
} | ||
|
||
func test_buildAdditionalFieldsConfiguration_whenPassedNil() throws { | ||
let result = AddressSheetUtils.buildAdditionalFieldsConfiguration(params: nil) | ||
|
||
XCTAssertEqual( | ||
result.phone, .hidden | ||
) | ||
XCTAssertEqual( | ||
result.name, .required | ||
) | ||
XCTAssertEqual( | ||
result.checkboxLabel, nil | ||
) | ||
} | ||
|
||
func test_buildAdditionalFieldsConfiguration_whenPassedValues() throws { | ||
let testCheckboxLabel = "testCheckboxLabel" | ||
let result = AddressSheetUtils.buildAdditionalFieldsConfiguration( | ||
params: ["name": "hidden", "phoneNumber": "optional", "checkboxLabel": testCheckboxLabel] | ||
) | ||
|
||
XCTAssertEqual( | ||
result.phone, .optional | ||
) | ||
XCTAssertEqual( | ||
result.name, .hidden | ||
) | ||
XCTAssertEqual( | ||
result.checkboxLabel, testCheckboxLabel | ||
) | ||
} | ||
|
||
func test_getFieldConfiguration() throws { | ||
XCTAssertEqual( | ||
AddressSheetUtils.getFieldConfiguration(input: nil, default: .hidden), .hidden | ||
) | ||
|
||
XCTAssertEqual( | ||
AddressSheetUtils.getFieldConfiguration(input: "optional", default: .hidden), .optional | ||
) | ||
|
||
XCTAssertEqual( | ||
AddressSheetUtils.getFieldConfiguration(input: "required", default: .hidden), .required | ||
) | ||
|
||
XCTAssertEqual( | ||
AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .hidden), .hidden | ||
) | ||
|
||
XCTAssertEqual( | ||
AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .optional), .hidden | ||
) | ||
} | ||
|
||
func test_buildResult() throws { | ||
let input = AddressViewController.AddressDetails( | ||
address: AddressViewController.AddressDetails.Address( | ||
city: testCity, country: testCountry, line1: testLine1, line2: testLine2, postalCode: testPostalCode, state: testState | ||
), | ||
name: testName, | ||
phone: testPhone, | ||
isCheckboxSelected: true | ||
) | ||
|
||
XCTAssertEqual( | ||
AddressSheetUtils.buildResult(address: input) as NSDictionary, | ||
[ | ||
"name": testName, | ||
"phone": testPhone, | ||
"isCheckboxSelected": true, | ||
"address": [ | ||
"city": testCity, | ||
"country": testCountry, | ||
"line1": testLine1, | ||
"line2": testLine2, | ||
"postalCode": testPostalCode, | ||
"state": testState | ||
] | ||
] as NSDictionary | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: revert