From 00ef0ceba250e853c6759cab56481b20a92dd880 Mon Sep 17 00:00:00 2001 From: Neelam Sharma Date: Mon, 17 Feb 2025 14:20:25 +0100 Subject: [PATCH] Added identifiers ui elements --- AdyenComponents/PayTo/PayToComponent.swift | 51 +++++++++++++++++++ .../PayTo/PayToComponentTests.swift | 48 +++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/AdyenComponents/PayTo/PayToComponent.swift b/AdyenComponents/PayTo/PayToComponent.swift index 79d48d0926..111253f860 100644 --- a/AdyenComponents/PayTo/PayToComponent.swift +++ b/AdyenComponents/PayTo/PayToComponent.swift @@ -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 { @@ -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 @@ -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, @@ -233,6 +276,7 @@ public final class PayToComponent: PaymentComponent, // MARK: - Private private func appendItemsTo(formVC: FormViewController) { + dynamicContent(formVC) staticContent(formVC) } @@ -240,6 +284,13 @@ public final class PayToComponent: PaymentComponent, 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) diff --git a/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift b/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift index a25bd6a09b..5e68be122f 100644 --- a/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift +++ b/Tests/IntegrationTests/Components Tests/PayTo/PayToComponentTests.swift @@ -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") + } + }