Skip to content

Commit

Permalink
Merge branch 'develop' into fix-version-increment
Browse files Browse the repository at this point in the history
  • Loading branch information
erenbesel authored Aug 30, 2023
2 parents 3014c3d + 7d1d449 commit 682922c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public extension FormAddressItem {
internal let localizationParameters: LocalizationParameters?
/// Supported country codes. If `nil`, all country codes are listed.
internal let supportedCountryCodes: [String]?
/// Whether to show a title header.
internal let showsHeader: Bool

/// Initializes the form address item configuration.
/// - Parameters:
Expand All @@ -28,11 +30,13 @@ public extension FormAddressItem {
public init(
style: AddressStyle = AddressStyle(),
localizationParameters: LocalizationParameters? = nil,
supportedCountryCodes: [String]? = nil
supportedCountryCodes: [String]? = nil,
showsHeader: Bool = true
) {
self.style = style
self.localizationParameters = localizationParameters
self.supportedCountryCodes = supportedCountryCodes
self.showsHeader = showsHeader
}
}
}
7 changes: 5 additions & 2 deletions Adyen/UI/Form/Items/Address/FormAddressItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ public final class FormAddressItem: FormValueItem<PostalAddress, AddressStyle>,
let subRegions = RegionRepository.subRegions(for: context.countryCode)
addressViewModel = addressViewModelBuilder.build(context: context)

var formItems: [FormItem] = [
let header: FormItem? = configuration.showsHeader ? headerItem.addingDefaultMargins() : nil

var formItems: [FormItem?] = [
FormSpacerItem(),
header,
countryPickerItem
]

Expand All @@ -164,7 +167,7 @@ public final class FormAddressItem: FormValueItem<PostalAddress, AddressStyle>,
}
}

self.items = formItems
self.items = formItems.compactMap { $0 }
}

private func create(for field: AddressField, from viewModel: AddressViewModel, subRegions: [Region]?) -> FormItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public class AddressInputFormViewController: FormViewController {
configuration: .init(
style: viewModel.style.addressStyle,
localizationParameters: viewModel.localizationParameters,
supportedCountryCodes: viewModel.supportedCountryCodes
supportedCountryCodes: viewModel.supportedCountryCodes,
showsHeader: false
),
identifier: identifier,
presenter: self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ class FormAddressItemTests: XCTestCase {
AdyenAssertion.listener = nil
}

func testHeader() throws {

let formAddressItem = FormAddressItem(
initialCountry: "NL",
configuration: .init(
supportedCountryCodes: ["NL", "US"],
showsHeader: true
),
presenter: nil,
addressViewModelBuilder: DefaultAddressViewModelBuilder()
)

XCTAssertTrue(formAddressItem.flatSubitems.contains { $0.identifier == "Adyen.FormAddressItem.title" })

let formAddressItemWithoutHeader = FormAddressItem(
initialCountry: "NL",
configuration: .init(
supportedCountryCodes: ["NL", "US"],
showsHeader: false
),
presenter: nil,
addressViewModelBuilder: DefaultAddressViewModelBuilder()
)

XCTAssertFalse(formAddressItemWithoutHeader.flatSubitems.contains { $0.identifier == "Adyen.FormAddressItem.title" })
}

func testCountryPickerItemUpdate() throws {

let formAddressItem = FormAddressItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class AddressInputFormViewControllerTests: XCTestCase {
let provinceOrTerritoryItemView: FormTextInputItemView = try XCTUnwrap(view.findView(with: "AddressInputFormViewController.billingAddress.stateOrProvince"))
let postalCodeItemView: FormTextInputItemView = try XCTUnwrap(view.findView(with: "AddressInputFormViewController.billingAddress.postalCode"))

XCTAssertNil(view.findView(by: "AddressInputFormViewController.billingAddressItem.title"))

XCTAssertEqual(countryItemView.titleLabel.text, "Country")
XCTAssertEqual(countryItemView.item.value!.title, "Netherlands")
XCTAssertEqual(houseNumberItemView.titleLabel.text, "House number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FormItemViewBuilderTests: XCTestCase {
let view = item.build(with: FormItemViewBuilder())

XCTAssertNotNil(view as? FormVerticalStackItemView<FormAddressItem>)
XCTAssertEqual(view.childItemViews.count, 6)
XCTAssertEqual(view.childItemViews.count, 7)
}

func testFormSAddressItemViewNL() {
Expand All @@ -67,7 +67,7 @@ class FormItemViewBuilderTests: XCTestCase {
let view = item.build(with: FormItemViewBuilder())

XCTAssertNotNil(view as? FormVerticalStackItemView<FormAddressItem>)
XCTAssertEqual(view.childItemViews.count, 8)
XCTAssertEqual(view.childItemViews.count, 9)
}

func testFormSAddressItemViewGB() {
Expand All @@ -78,7 +78,7 @@ class FormItemViewBuilderTests: XCTestCase {
let view = item.build(with: FormItemViewBuilder())

XCTAssertNotNil(view as? FormVerticalStackItemView<FormAddressItem>)
XCTAssertEqual(view.childItemViews.count, 6)
XCTAssertEqual(view.childItemViews.count, 7)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class ACHDirectDebitComponentTests: XCTestCase {
let payButtonItemViewButton: UIControl? = sut.viewController.view.findView(with: "AdyenComponents.ACHDirectDebitComponent.payButtonItem.button")
let payButtonItemViewButtonTitle: UILabel? = sut.viewController.view.findView(with: "AdyenComponents.ACHDirectDebitComponent.payButtonItem.button.titleLabel")

XCTAssertNotNil(sut.viewController.view.findView(by: "AdyenComponents.ACHDirectDebitComponent.billingAddressItem"))
XCTAssertNotNil(sut.viewController.view.findView(by: "AdyenComponents.ACHDirectDebitComponent.billingAddressItem.title"))

/// holder name
XCTAssertEqual(nameItemView?.backgroundColor, .red)
XCTAssertEqual(nameItemViewTitleLabel?.backgroundColor, .blue)
Expand Down
2 changes: 2 additions & 0 deletions Tests/Components Tests/Boleto/BoletoComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class BoletoComponentTests: XCTestCase {
let cityField = viewController.view.findView(by: "addressItem.city.textField") as? UITextField
let postalCodeField = viewController.view.findView(by: "addressItem.postalCode.textField") as? UITextField

XCTAssertNotNil(viewController.view.findView(by: "addressItem.title"))

XCTAssertNotNil(firstNameField)
XCTAssertEqual(firstNameField?.text, prefilledInformation.shopperName?.firstName)

Expand Down
5 changes: 4 additions & 1 deletion UITests/Components/Affirm/AffirmComponentUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ class AffirmComponentUITests: XCTestCase {
wait(for: .milliseconds(300))

assertViewControllerImage(matching: sut.viewController, named: "shopper-info-prefilled")

let view: UIView = sut.viewController.view
let submitButton: UIControl = try XCTUnwrap(view.findView(by: AffirmViewIdentifier.payButton))
submitButton.sendActions(for: .touchUpInside)

XCTAssertNotNil(view.findView(by: "AdyenComponents.AffirmComponent.addressItem"))
XCTAssertNotNil(view.findView(by: "AdyenComponents.AffirmComponent.addressItem.title"))

waitForExpectations(timeout: 10, handler: nil)
}
Expand Down
3 changes: 3 additions & 0 deletions UITests/Components/Atome/AtomeComponentUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class AtomeComponentUITests: XCTestCase {
let sut = AtomeComponent(paymentMethod: paymentMethod,
context: context,
configuration: config)

XCTAssertNotNil(sut.viewController.view.findView(by: "AdyenComponents.AtomeComponent.addressItem.title"))

assertViewControllerImage(matching: sut.viewController, named: "UI_configuration")
}

Expand Down

0 comments on commit 682922c

Please sign in to comment.