Skip to content
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

Fix STPThreeDSUICustomization not properly initializing defaults or t… #1303

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions Stripe/Payments/STPThreeDSUICustomization.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,39 @@ + (instancetype)defaultSettings {
- (instancetype)init {
self = [super init];
if (self) {
_uiCustomization = [STDSUICustomization new];
// Initialize defaults for all properties
_footerCustomization = [STPThreeDSFooterCustomization defaultSettings];
_labelCustomization = [STPThreeDSLabelCustomization defaultSettings];
_navigationBarCustomization = [STPThreeDSNavigationBarCustomization defaultSettings];
_selectionCustomization = [STPThreeDSSelectionCustomization defaultSettings];
_textFieldCustomization = [STPThreeDSTextFieldCustomization defaultSettings];

STPThreeDSButtonCustomization *nextButton = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeNext];
STPThreeDSButtonCustomization *cancelButton = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeCancel];
STPThreeDSButtonCustomization *resendButton = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeResend];
STPThreeDSButtonCustomization *submitButton = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeSubmit];
STPThreeDSButtonCustomization *continueButton = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeContinue];
_buttonCustomizationDictionary = [@{
@(STPThreeDSCustomizationButtonTypeNext): [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeNext
],
@(STPThreeDSCustomizationButtonTypeCancel): [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeCancel],
@(STPThreeDSCustomizationButtonTypeResend): [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeResend],
@(STPThreeDSCustomizationButtonTypeSubmit): [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeSubmit],
@(STPThreeDSCustomizationButtonTypeContinue): [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeContinue],
} mutableCopy];
@(STPThreeDSCustomizationButtonTypeNext): nextButton,
@(STPThreeDSCustomizationButtonTypeCancel): cancelButton,
@(STPThreeDSCustomizationButtonTypeResend): resendButton,
@(STPThreeDSCustomizationButtonTypeSubmit): submitButton,
@(STPThreeDSCustomizationButtonTypeContinue): continueButton,
} mutableCopy];

// Initialize the underlying STDS class we are wrapping
_uiCustomization = [STDSUICustomization new];
[_uiCustomization setButtonCustomization:nextButton.buttonCustomization forType:STDSUICustomizationButtonTypeNext];
[_uiCustomization setButtonCustomization:cancelButton.buttonCustomization forType:STDSUICustomizationButtonTypeCancel];
[_uiCustomization setButtonCustomization:resendButton.buttonCustomization forType:STDSUICustomizationButtonTypeResend];
[_uiCustomization setButtonCustomization:submitButton.buttonCustomization forType:STDSUICustomizationButtonTypeSubmit];
[_uiCustomization setButtonCustomization:continueButton.buttonCustomization forType:STDSUICustomizationButtonTypeContinue];

_uiCustomization.footerCustomization = _footerCustomization.footerCustomization;
_uiCustomization.labelCustomization = _labelCustomization.labelCustomization;
_uiCustomization.navigationBarCustomization = _navigationBarCustomization.navigationBarCustomization;
_uiCustomization.selectionCustomization = _selectionCustomization.selectionCustomization;
_uiCustomization.textFieldCustomization = _textFieldCustomization.textFieldCustomization;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the function on line 70 is what was messing me up. Mutating the returned STPThreeDSButotnCustomization wasn't syncing. Do the above _uiCustomization setButtonCustomization calls fix that because now both dictionaries reference the same STDSButtonCustomization instance?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly. _buttonCustomizationDictionary references STPThreeDSUIButtonCustomization instances which forward all their properties to the underlying STDS instance, which we are now properly setting on _uiCustomization like we should have been (like on line 67, which is why calling the setter synced things).

}
return self;
}
Expand Down
54 changes: 43 additions & 11 deletions Tests/Tests/STPThreeDSUICustomizationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,69 @@ @implementation STPThreeDSUICustomizationTest

- (void)testPropertiesPassedThrough {
STPThreeDSUICustomization *customization = [STPThreeDSUICustomization defaultSettings];

// Maintains button customization objects
STPThreeDSButtonCustomization *button = [customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeNext];
button.backgroundColor = UIColor.redColor;
[customization setButtonCustomization:button forType:STPThreeDSCustomizationButtonTypeNext];
XCTAssertEqual([customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeNext], button);
[customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeNext].backgroundColor = UIColor.cyanColor;
[customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeResend].backgroundColor = UIColor.cyanColor;
[customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeSubmit].backgroundColor = UIColor.cyanColor;
[customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeContinue].backgroundColor = UIColor.cyanColor;
[customization buttonCustomizationForButtonType:STPThreeDSCustomizationButtonTypeCancel].backgroundColor = UIColor.cyanColor;
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeNext].backgroundColor, UIColor.cyanColor);
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeResend].backgroundColor, UIColor.cyanColor);
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeSubmit].backgroundColor, UIColor.cyanColor);
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeContinue].backgroundColor, UIColor.cyanColor);
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeCancel].backgroundColor, UIColor.cyanColor);

STPThreeDSButtonCustomization *buttonCustomization = [STPThreeDSButtonCustomization defaultSettingsForButtonType:STPThreeDSCustomizationButtonTypeNext];
[customization setButtonCustomization:buttonCustomization forType:STPThreeDSCustomizationButtonTypeNext];
XCTAssertEqual([customization.uiCustomization buttonCustomizationForButtonType:STDSUICustomizationButtonTypeNext], buttonCustomization.buttonCustomization);

// Footer
customization.footerCustomization.backgroundColor = UIColor.cyanColor;
XCTAssertEqual(customization.uiCustomization.footerCustomization.backgroundColor, UIColor.cyanColor);

STPThreeDSFooterCustomization *footerCustomization = [STPThreeDSFooterCustomization defaultSettings];
customization.footerCustomization = footerCustomization;
XCTAssertEqual(customization.uiCustomization.footerCustomization, footerCustomization.footerCustomization);

// Label
customization.labelCustomization.textColor = UIColor.cyanColor;
XCTAssertEqual(customization.uiCustomization.labelCustomization.textColor, UIColor.cyanColor);

STPThreeDSFooterCustomization *footer = [STPThreeDSFooterCustomization defaultSettings];
customization.footerCustomization = footer;
XCTAssertEqual(customization.uiCustomization.footerCustomization, footer.footerCustomization);
STPThreeDSLabelCustomization *labelCustomization = [STPThreeDSLabelCustomization defaultSettings];
customization.labelCustomization = labelCustomization;
XCTAssertEqual(customization.uiCustomization.labelCustomization, labelCustomization.labelCustomization);

STPThreeDSLabelCustomization *label = [STPThreeDSLabelCustomization defaultSettings];
customization.labelCustomization = label;
XCTAssertEqual(customization.uiCustomization.labelCustomization, label.labelCustomization);
// Navigation Bar
customization.navigationBarCustomization.textColor = UIColor.cyanColor;
XCTAssertEqual(customization.uiCustomization.navigationBarCustomization.textColor, UIColor.cyanColor);

STPThreeDSNavigationBarCustomization *navigationBar = [STPThreeDSNavigationBarCustomization defaultSettings];
customization.navigationBarCustomization = navigationBar;
XCTAssertEqual(customization.uiCustomization.navigationBarCustomization, navigationBar.navigationBarCustomization);

// Selection
customization.selectionCustomization.primarySelectedColor = UIColor.cyanColor;
XCTAssertEqual(customization.uiCustomization.selectionCustomization.primarySelectedColor, UIColor.cyanColor);

STPThreeDSSelectionCustomization *selection = [STPThreeDSSelectionCustomization defaultSettings];
customization.selectionCustomization = selection;
XCTAssertEqual(customization.uiCustomization.selectionCustomization, selection.selectionCustomization);

// Text Field
customization.textFieldCustomization.textColor = UIColor.cyanColor;
XCTAssertEqual(customization.uiCustomization.textFieldCustomization.textColor, UIColor.cyanColor);

STPThreeDSTextFieldCustomization *textField = [STPThreeDSTextFieldCustomization defaultSettings];
customization.textFieldCustomization = textField;
XCTAssertEqual(customization.uiCustomization.textFieldCustomization, textField.textFieldCustomization);

// Other
customization.backgroundColor = UIColor.redColor;
customization.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
customization.blurStyle = UIBlurEffectStyleDark;
customization.preferredStatusBarStyle = UIStatusBarStyleLightContent;

XCTAssertEqual(UIColor.redColor, customization.backgroundColor);
XCTAssertEqual(customization.backgroundColor, customization.uiCustomization.backgroundColor);

Expand Down