Skip to content

Commit

Permalink
Merge branch 'develop' into use-xcode-15
Browse files Browse the repository at this point in the history
  • Loading branch information
goergisn committed Nov 16, 2023
2 parents 01f4d4c + cc522ce commit d89ba29
Show file tree
Hide file tree
Showing 54 changed files with 382 additions and 641 deletions.
3 changes: 2 additions & 1 deletion Adyen/UI/List/ListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public class ListItem: FormItem {

/// Indicate to the ``ListViewController`` to start loading / show the loading indicator for this specific item
///
/// To stop the loading for the whole list either call ListViewController.``ListViewController/stopLoading()`` or ListItem.``ListItem/stopLoading()``
/// To stop the loading for the whole list either call ListViewController.``ListViewController/stopLoading()``
/// or ListItem.``ListItem/stopLoading()``
public func startLoading() {
setLoading(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ internal class ThreeDS2CoreActionHandler: AnyThreeDS2CoreActionHandler {
completionHandler(.success(encodedFingerprint))

case let .failure(error):
let encodedError = try AdyenCoder.encodeBase64(ThreeDS2Component.Fingerprint(threeDS2SDKError: error.base64Representation()))
let encodedError = try AdyenCoder.encodeBase64(ThreeDS2Component.Fingerprint(
threeDS2SDKError: error.base64Representation())
)
completionHandler(.success(encodedError))
}
} catch {
Expand Down
6 changes: 3 additions & 3 deletions Demo/Common/Helpers/APIClientHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import Adyen
import AdyenNetworking

enum ApiClientHelper {
internal enum ApiClientHelper {

static func generateApiClient() -> APIClientProtocol {
internal static func generateApiClient() -> APIClientProtocol {
guard CommandLine.arguments.contains("-UITests"),
let paymentMethodsUrl = Bundle.main.url(forResource: "payment_methods_response", withExtension: "json"),
let sessionsUrl = Bundle.main.url(forResource: "session_response", withExtension: "json"),
Expand All @@ -24,7 +24,7 @@ enum ApiClientHelper {
return apiClient
}

static func generatePalApiClient() -> APIClientProtocol {
internal static func generatePalApiClient() -> APIClientProtocol {
let context = DemoAPIContext(environment: ConfigurationConstants.classicAPIEnvironment)
return DefaultAPIClient(apiContext: context)
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/Common/Networking/PaymentsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal struct PaymentsResponse: Response {
case amount
}

var isAccepted: Bool {
internal var isAccepted: Bool {
switch resultCode {
case .authorised, .received, .pending:
return true
Expand Down
45 changes: 15 additions & 30 deletions Tests/Actions Tests/ActionComponent/AdyenActionComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class AdyenActionComponentTests: XCTestCase {
}
"""

func testRedirectToHttpWebLink() {
func testRedirectToHttpWebLink() throws {
let sut = AdyenActionComponent(context: Dummy.context)
let delegate = ActionComponentDelegateMock()
sut.presentationDelegate = UIViewController.findTopPresenter()
sut.presentationDelegate = try XCTUnwrap(UIViewController.topPresenter() as? PresentationDelegate)
sut.delegate = delegate

delegate.onDidOpenExternalApplication = { _ in
Expand All @@ -72,28 +72,22 @@ class AdyenActionComponentTests: XCTestCase {
let action = Action.redirect(RedirectAction(url: URL(string: "https://www.adyen.com")!, paymentData: "test_data"))
sut.handle(action)

wait(for: .seconds(2))

let topPresentedViewController = UIViewController.findTopPresenter()
XCTAssertNotNil(topPresentedViewController as? SFSafariViewController)
try waitUntilTopPresenter(isOfType: SFSafariViewController.self)
}

func testAwaitAction() {
func testAwaitAction() throws {
let sut = AdyenActionComponent(context: Dummy.context)
sut.presentationDelegate = UIViewController.findTopPresenter()
sut.presentationDelegate = try XCTUnwrap(UIViewController.topPresenter() as? PresentationDelegate)

let action = Action.await(AwaitAction(paymentData: "SOME_DATA", paymentMethodType: .blik))
sut.handle(action)

wait(for: .seconds(2))

let waitExpectation = expectation(description: "Expect AwaitViewController to be presented")

let topPresentedViewController = UIViewController.findTopPresenter()
XCTAssertNotNil(topPresentedViewController as? AdyenActions.AwaitViewController)
try waitUntilTopPresenter(isOfType: AdyenActions.AwaitViewController.self)

(sut.presentationDelegate as! UIViewController).dismiss(animated: true) {
let topPresentedViewController = UIViewController.findTopPresenter()
let topPresentedViewController = try? UIViewController.topPresenter()
XCTAssertNil(topPresentedViewController as? AdyenActions.AwaitViewController)

waitExpectation.fulfill()
Expand Down Expand Up @@ -133,32 +127,23 @@ class AdyenActionComponentTests: XCTestCase {
waitForExpectations(timeout: 10, handler: nil)
}

func testVoucherAction() {
func testVoucherAction() throws {
let sut = AdyenActionComponent(context: Dummy.context)
sut.presentationDelegate = UIViewController.findTopPresenter()
sut.presentationDelegate = try XCTUnwrap(UIViewController.topPresenter() as? PresentationDelegate)

let action = try! JSONDecoder().decode(VoucherAction.self, from: voucherAction.data(using: .utf8)!)
sut.handle(Action.voucher(action))

wait(for: .seconds(2))

let waitExpectation = expectation(description: "Expect VoucherViewController to be presented")
let topPresentedViewController = UIViewController.findTopPresenter()
XCTAssertNotNil(topPresentedViewController?.view as? VoucherView)

(sut.presentationDelegate as! UIViewController).dismiss(animated: true) {
let topPresentedViewController = UIViewController.findTopPresenter()
XCTAssertNil(topPresentedViewController as? VoucherViewController)

let voucherViewController = try waitUntilTopPresenter(isOfType: ADYViewController.self)
XCTAssertNotNil(voucherViewController.view as? VoucherView)

let presentationDelegate = try XCTUnwrap(sut.presentationDelegate as? UIViewController)
presentationDelegate.dismiss(animated: true) {
XCTAssertNotEqual(voucherViewController, try? UIViewController.topPresenter())
waitExpectation.fulfill()
}

waitForExpectations(timeout: 10, handler: nil)
}
}

extension UIViewController: PresentationDelegate {
public func present(component: PresentableComponent) {
self.present(component.viewController, animated: true, completion: nil)
}
}
6 changes: 3 additions & 3 deletions Tests/Actions Tests/Await/AwaitComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class AwaitComponentTests: XCTestCase {
let presentationDelegate = PresentationDelegateMock()
let waitExpectation = expectation(description: "Wait for the presentationDelegate to be called.")
presentationDelegate.doPresent = { [weak self] component in
guard let self = self else { return }

XCTAssertNotNil(component.viewController as? AwaitViewController)
let viewController = component.viewController as! AwaitViewController

UIApplication.shared.keyWindow?.rootViewController = viewController
self.setupRootViewController(viewController)

let view = viewController.awaitView

self?.wait(for: .milliseconds(300))

XCTAssertEqual(view.messageLabel.textColor, UIColor.red)
XCTAssertEqual(view.messageLabel.textAlignment, .center)
Expand Down
55 changes: 19 additions & 36 deletions Tests/Actions Tests/Redirect/RedirectComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import XCTest

class RedirectComponentTests: XCTestCase {

override func tearDown() {
super.tearDown()
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: false)
wait(for: .milliseconds(300))
override func setUp(completion: @escaping (Error?) -> Void) {
UIApplication.shared.adyen.mainKeyWindow?.rootViewController?.dismiss(animated: false) {
super.setUp(completion: completion)
}
}

override func setUp() {
super.setUp()
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: false)
wait(for: .milliseconds(300))
override func tearDown(completion: @escaping (Error?) -> Void) {
UIApplication.shared.adyen.mainKeyWindow?.rootViewController?.dismiss(animated: false) {
super.tearDown(completion: completion)
}
}

func testUIConfiguration() {
Expand Down Expand Up @@ -131,21 +131,20 @@ class RedirectComponentTests: XCTestCase {
waitForExpectations(timeout: 10, handler: nil)
}

func testOpenUniversalLinkFailure() {
func testOpenUniversalLinkFailure() throws {
let sut = RedirectComponent(context: Dummy.context)
let delegate = ActionComponentDelegateMock()
sut.delegate = delegate
let appLauncher = AppLauncherMock()
sut.appLauncher = appLauncher
let presentingViewControllerMock = PresentingViewControllerMock()
sut.presentationDelegate = presentingViewControllerMock
let topViewController: UIViewController! = UIViewController.findTopPresenter()
let topViewController = try UIViewController.topPresenter()
topViewController.present(presentingViewControllerMock, animated: false, completion: nil)

let safariVCExpectation = expectation(description: "Expect SFSafariViewController() to be presented")
presentingViewControllerMock.onPresent = { viewController, animated, completion in
XCTAssertNotNil(viewController as? SFSafariViewController)
XCTAssertEqual(animated, true)
XCTAssertTrue(viewController is SFSafariViewController)
completion?()
safariVCExpectation.fulfill()
}
Expand All @@ -171,9 +170,9 @@ class RedirectComponentTests: XCTestCase {
waitForExpectations(timeout: 10, handler: nil)
}

func testOpenHttpWebLink() {
func testOpenHttpWebLink() throws {
let sut = RedirectComponent(context: Dummy.context)
sut.presentationDelegate = UIViewController.findTopPresenter()
sut.presentationDelegate = try UIViewController.topPresenter()
let delegate = ActionComponentDelegateMock()
sut.delegate = delegate
let appLauncher = AppLauncherMock()
Expand All @@ -194,15 +193,12 @@ class RedirectComponentTests: XCTestCase {
let action = RedirectAction(url: URL(string: "https://www.adyen.com?returnUrlQueryString=anything")!, paymentData: "test_data")
sut.handle(action)

wait(for: .seconds(2))

let topPresentedViewController = UIViewController.findTopPresenter()
XCTAssertNotNil(topPresentedViewController as? SFSafariViewController)
try waitUntilTopPresenter(isOfType: SFSafariViewController.self)
}

func testOpenHttpWebLinkAndDragedDown() {
func testOpenHttpWebLinkAndDragedDown() throws {
let sut = RedirectComponent(context: Dummy.context)
sut.presentationDelegate = UIViewController.findTopPresenter()
sut.presentationDelegate = try UIViewController.topPresenter()
let delegate = ActionComponentDelegateMock()
sut.delegate = delegate

Expand All @@ -215,13 +211,11 @@ class RedirectComponentTests: XCTestCase {
XCTAssertEqual(error as! ComponentError, ComponentError.cancelled)
waitExpectation.fulfill()
}

wait(for: .seconds(2))

let topPresentedViewController = UIViewController.findTopPresenter() as? SFSafariViewController
XCTAssertNotNil(topPresentedViewController)
let topPresentedViewController = try waitUntilTopPresenter(isOfType: SFSafariViewController.self)

topPresentedViewController!.presentationController?.delegate?.presentationControllerDidDismiss?(topPresentedViewController!.presentationController!)
let presentationController = try XCTUnwrap(topPresentedViewController.presentationController)
presentationController.delegate?.presentationControllerDidDismiss?(presentationController)

waitForExpectations(timeout: 10, handler: nil)
}
Expand Down Expand Up @@ -351,14 +345,3 @@ class RedirectComponentTests: XCTestCase {
waitForExpectations(timeout: 2)
}
}

extension UIViewController {
public static func findTopPresenter() -> UIViewController? {
guard let viewController = UIApplication.shared.keyWindow?.rootViewController else {
AdyenAssertion.assertionFailure(message: "Application's keyWindow is not set or have no rootViewController")
return nil
}
return viewController.adyen.topPresenter
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BoletoVoucherShareableVoucherViewProviderTests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment.")
Expand Down
6 changes: 3 additions & 3 deletions Tests/Actions Tests/Voucher/DokuVoucherUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DokuVoucherUITests: XCTestCase {

let sut = viewControllerProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment. -- Test")
Expand Down Expand Up @@ -57,7 +57,7 @@ class DokuVoucherUITests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment.")
Expand Down Expand Up @@ -95,7 +95,7 @@ class DokuVoucherUITests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EContextATMShareableVoucherViewProviderTests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment. -- Test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EContextStoresVoucherViewControllerProviderTests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment. -- Test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MultibancoShareableVoucherViewProviderTests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OXXOShareableVoucherViewProviderTests: XCTestCase {

let sut = viewProvider.provideView(with: action, logo: nil)

UIApplication.shared.keyWindow?.rootViewController?.view = sut
setupRootViewController(ADYViewController(view: sut))

let textLabel: UILabel! = sut.findView(by: "adyen.voucher.textLabel")
XCTAssertEqual(textLabel.text, "Thank you for your purchase, please use the following information to complete your payment.")
Expand Down
29 changes: 13 additions & 16 deletions Tests/Actions Tests/Voucher/VoucherComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class VoucherComponentTests: XCTestCase {
let component = component as! PresentableComponentWrapper
XCTAssert(component.component === sut)

UIApplication.shared.keyWindow?.rootViewController = component.viewController
setupRootViewController(component.viewController)

let view = sut.view

Expand All @@ -113,13 +113,12 @@ class VoucherComponentTests: XCTestCase {

wait(for: .milliseconds(300))

let alertSheet = UIViewController.findTopPresenter() as? UIAlertController
XCTAssertNotNil(alertSheet)
XCTAssertEqual(alertSheet?.actions.count, 4)
XCTAssertEqual(alertSheet?.actions[0].title, "Copy code")
XCTAssertEqual(alertSheet?.actions[1].title, "Download PDF")
XCTAssertEqual(alertSheet?.actions[2].title, "Read instructions")
XCTAssertEqual(alertSheet?.actions[3].title, "Cancel")
let alertSheet = try! XCTUnwrap(UIViewController.topPresenter() as? UIAlertController)
XCTAssertEqual(alertSheet.actions.count, 4)
XCTAssertEqual(alertSheet.actions[0].title, "Copy code")
XCTAssertEqual(alertSheet.actions[1].title, "Download PDF")
XCTAssertEqual(alertSheet.actions[2].title, "Read instructions")
XCTAssertEqual(alertSheet.actions[3].title, "Cancel")

presentationDelegateExpectation.fulfill()
}
Expand All @@ -137,7 +136,7 @@ class VoucherComponentTests: XCTestCase {
let component = component as! PresentableComponentWrapper
XCTAssert(component.component === sut)

UIApplication.shared.keyWindow?.rootViewController = component.viewController
self.setupRootViewController(component.viewController)

let view = sut.view

Expand All @@ -151,14 +150,12 @@ class VoucherComponentTests: XCTestCase {

optionsButton.sendActions(for: .touchUpInside)

wait(for: .milliseconds(300))

let alertSheet = UIViewController.findTopPresenter() as? UIAlertController
let alertSheet = try! waitUntilTopPresenter(isOfType: UIAlertController.self)
XCTAssertNotNil(alertSheet)
XCTAssertEqual(alertSheet?.actions.count, 3)
XCTAssertEqual(alertSheet?.actions[0].title, "Copy code")
XCTAssertEqual(alertSheet?.actions[1].title, "Save as image")
XCTAssertEqual(alertSheet?.actions[2].title, "Cancel")
XCTAssertEqual(alertSheet.actions.count, 3)
XCTAssertEqual(alertSheet.actions[0].title, "Copy code")
XCTAssertEqual(alertSheet.actions[1].title, "Save as image")
XCTAssertEqual(alertSheet.actions[2].title, "Cancel")

presentationDelegateExpectation.fulfill()
}
Expand Down
Loading

0 comments on commit d89ba29

Please sign in to comment.