From b49c4002ec555937767e0faedcdb5c2869979b0a Mon Sep 17 00:00:00 2001 From: Alex Guretzki Date: Fri, 26 Jan 2024 14:19:23 +0100 Subject: [PATCH] Adding QRCodeAction + DocumentAction tests --- .../AdyenActionComponentTests.swift | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/Tests/Actions Tests/ActionComponent/AdyenActionComponentTests.swift b/Tests/Actions Tests/ActionComponent/AdyenActionComponentTests.swift index bb7a4aeba7..97aced2eec 100644 --- a/Tests/Actions Tests/ActionComponent/AdyenActionComponentTests.swift +++ b/Tests/Actions Tests/ActionComponent/AdyenActionComponentTests.swift @@ -58,6 +58,21 @@ class AdyenActionComponentTests: XCTestCase { "type" : "voucher" } """ + + let qrAction = """ + { + "paymentMethodType": "upi_qr", + "qrCodeData": "QR_CODE_DATA", + "paymentData": "" + } + """ + + let documentAction = """ + { + "paymentMethodType": "directdebit_GB", + "url": "https://adyen.com" + } + """ func testRedirectToHttpWebLink() throws { let sut = AdyenActionComponent(context: Dummy.context) @@ -118,13 +133,7 @@ class AdyenActionComponentTests: XCTestCase { let action = try! JSONDecoder().decode(ThreeDS2Action.self, from: threeDSFingerprintAction.data(using: .utf8)!) sut.handle(Action.threeDS2(action)) - let waitExpectation = expectation(description: "Expect in app browser to be presented and then dismissed") - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(2)) { - XCTAssertNotNil(sut.currentActionComponent as? ThreeDS2Component) - waitExpectation.fulfill() - } - - waitForExpectations(timeout: 10, handler: nil) + wait { sut.currentActionComponent is ThreeDS2Component } } func testVoucherAction() throws { @@ -146,4 +155,27 @@ class AdyenActionComponentTests: XCTestCase { waitForExpectations(timeout: 100, handler: nil) } + + func testQRCodeAction() throws { + + let sut = AdyenActionComponent(context: Dummy.context) + sut.presentationDelegate = try UIViewController.topPresenter() + + let action = try! JSONDecoder().decode(QRCodeAction.self, from: qrAction.data(using: .utf8)!) + sut.handle(Action.qrCode(action)) + + try waitUntilTopPresenter(isOfType: QRCodeViewController.self) + } + + func testDocumentAction() throws { + // DocumentAction + let sut = AdyenActionComponent(context: Dummy.context) + sut.presentationDelegate = try UIViewController.topPresenter() + + let action = try! JSONDecoder().decode(DocumentAction.self, from: documentAction.data(using: .utf8)!) + sut.handle(Action.document(action)) + + let documentViewController = try waitUntilTopPresenter(isOfType: ADYViewController.self) + XCTAssertNotNil(documentViewController.view as? DocumentActionView) + } }