Skip to content

Commit

Permalink
Fix STPThreeDSUICustomization not properly initializing defaults or t…
Browse files Browse the repository at this point in the history
…he STDS object it's wrapping. (#1303)
  • Loading branch information
yuki-stripe authored Aug 19, 2019
1 parent ef6ef04 commit 4d8dcb2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 19 deletions.
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;
}
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

0 comments on commit 4d8dcb2

Please sign in to comment.