Skip to content

Commit

Permalink
Added identifiers ui elements
Browse files Browse the repository at this point in the history
  • Loading branch information
neelSharma12 committed Feb 17, 2025
1 parent 1b006f1 commit 00ef0ce
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
51 changes: 51 additions & 0 deletions AdyenComponents/PayTo/PayToComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public final class PayToComponent: PaymentComponent,
static let identifierPickerItem = "identifierPicker"
static let firstNameInputItem = "firstNameTextfield"
static let lastNameInputItem = "lastNameTextfield"
static let emailInputItem = "emailTextfield"
static let abnInputItem = "abnTextfield"
static let organizationIDInputItem = "organizationIDTextfield"
}

private enum AccountIdentifiers: String, CustomStringConvertible, CaseIterable {
Expand Down Expand Up @@ -131,6 +134,7 @@ public final class PayToComponent: PaymentComponent,
scopeInstance: self,
postfix: ViewIdentifier.phoneNumberItem
)
// TODO: Add translation
item.title = localizedString(LocalizationKey(key: "Phone"), configuration.localizationParameters)
item.placeholder = localizedString(LocalizationKey(key: "Mobile number"), configuration.localizationParameters)
return item
Expand Down Expand Up @@ -198,6 +202,45 @@ public final class PayToComponent: PaymentComponent,
return item
}()

/// The account holder email text input item.
internal lazy var emailInputItem: FormTextInputItem = {
let item = FormTextInputItem(style: configuration.style.textField)
// TODO: Add translation
item.title = localizedString(LocalizationKey(key: "Email"), configuration.localizationParameters)
item.placeholder = localizedString(LocalizationKey(key: "Email"), configuration.localizationParameters)
item.identifier = ViewIdentifierBuilder.build(
scopeInstance: self,
postfix: ViewIdentifier.emailInputItem
)
return item
}()

/// The account holder abn text input item.
internal lazy var abnInputItem: FormTextInputItem = {
let item = FormTextInputItem(style: configuration.style.textField)
// TODO: Add translation
item.title = localizedString(LocalizationKey(key: "ABN"), configuration.localizationParameters)
item.placeholder = localizedString(LocalizationKey(key: "ABN"), configuration.localizationParameters)
item.identifier = ViewIdentifierBuilder.build(
scopeInstance: self,
postfix: ViewIdentifier.abnInputItem
)
return item
}()

/// The account holder organization ID text input item.
internal lazy var organizationIDInputItem: FormTextInputItem = {
let item = FormTextInputItem(style: configuration.style.textField)
// TODO: Add translation
item.title = localizedString(LocalizationKey(key: "Organization ID"), configuration.localizationParameters)
item.placeholder = localizedString(LocalizationKey(key: "Organization ID"), configuration.localizationParameters)
item.identifier = ViewIdentifierBuilder.build(
scopeInstance: self,
postfix: ViewIdentifier.organizationIDInputItem
)
return item
}()

private lazy var formViewController: FormViewController = {
let formViewController = FormViewController(
scrollEnabled: configuration.showsSubmitButton,
Expand Down Expand Up @@ -233,13 +276,21 @@ public final class PayToComponent: PaymentComponent,
// MARK: - Private

private func appendItemsTo(formVC: FormViewController) {
dynamicContent(formVC)
staticContent(formVC)
}

private func staticContent(_ formVC: FormViewController) {
formVC.append(firstNameInputItem)
formVC.append(lastNameInputItem)
}

private func dynamicContent(_ formVC: FormViewController) {
// TODO: Add bussiness logic to show/hide these
formVC.append(emailInputItem)
formVC.append(abnInputItem)
formVC.append(organizationIDInputItem)
}
}

@_spi(AdyenInternal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,52 @@ class PayToComponentTests: XCTestCase {
XCTAssertNotNil(lastNameInputItem, "last name input field should exist")
}

func test_email_textfield_exists() throws {
// Given
let sut = try PayToComponent(
paymentMethod: AdyenCoder.decode(payto),
context: Dummy.context
)

sut.viewController.loadViewIfNeeded()

// Check by accessibility identifier
let emailInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.emailTextfield"))

// Then
XCTAssertNotNil(emailInputItem, "email input field should exist")
}

func test_abn_textfield_exists() throws {
// Given
let sut = try PayToComponent(
paymentMethod: AdyenCoder.decode(payto),
context: Dummy.context
)

sut.viewController.loadViewIfNeeded()

// Check by accessibility identifier
let abnInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.abnTextfield"))

// Then
XCTAssertNotNil(abnInputItem, "abn input field should exist")
}

func test_organizationID_textfield_exists() throws {
// Given
let sut = try PayToComponent(
paymentMethod: AdyenCoder.decode(payto),
context: Dummy.context
)

sut.viewController.loadViewIfNeeded()

// Check by accessibility identifier
let organizationIDInputItem: FormTextInputItemView = try XCTUnwrap(sut.viewController.view.findView(with: "AdyenComponents.PayToComponent.organizationIDTextfield"))

// Then
XCTAssertNotNil(organizationIDInputItem, "organizationID input field should exist")
}

}

0 comments on commit 00ef0ce

Please sign in to comment.