|
6 | 6 |
|
7 | 7 | @_spi(AdyenInternal) @testable import Adyen
|
8 | 8 | @_spi(AdyenInternal) @testable import AdyenActions
|
9 |
| -import AdyenDropIn |
| 9 | +@testable import AdyenDropIn |
10 | 10 | import SafariServices
|
11 | 11 | import XCTest
|
12 | 12 |
|
@@ -130,6 +130,42 @@ class DropInTests: XCTestCase {
|
130 | 130 | }
|
131 | 131 | }
|
132 | 132 |
|
| 133 | + func testDropInStyle() throws { |
| 134 | + var style = DropInComponent.Style(tintColor: .brown) |
| 135 | + |
| 136 | + XCTAssertEqual(style.formComponent.textField.tintColor, .brown) |
| 137 | + XCTAssertEqual(style.navigation.tintColor, .brown) |
| 138 | + |
| 139 | + // MARK: Update separatorColor |
| 140 | + |
| 141 | + style.separatorColor = .yellow |
| 142 | + |
| 143 | + XCTAssertEqual(style.formComponent.separatorColor, .yellow) |
| 144 | + XCTAssertEqual(style.navigation.separatorColor, .yellow) |
| 145 | + |
| 146 | + style.separatorColor = .green |
| 147 | + |
| 148 | + /* |
| 149 | + In its current implementation calling `separatorColor` with multiple times with different colors |
| 150 | + won't have any effect. This might be unexpected but this tests confirms the current implementation detail. |
| 151 | + */ |
| 152 | + XCTAssertEqual(style.formComponent.separatorColor, .yellow) |
| 153 | + XCTAssertEqual(style.navigation.separatorColor, .yellow) |
| 154 | + |
| 155 | + /* |
| 156 | + To be able to restore the initial behavior |
| 157 | + the `formComponent.separatorColor` and/or `navigation.separatorColor` |
| 158 | + have to be nilled out |
| 159 | + */ |
| 160 | + style.formComponent.separatorColor = nil |
| 161 | + style.navigation.separatorColor = nil |
| 162 | + |
| 163 | + style.separatorColor = .green |
| 164 | + |
| 165 | + XCTAssertEqual(style.formComponent.separatorColor, .green) |
| 166 | + XCTAssertEqual(style.navigation.separatorColor, .green) |
| 167 | + } |
| 168 | + |
133 | 169 | func testOpenDropInAsList() throws {
|
134 | 170 | let config = DropInComponent.Configuration()
|
135 | 171 |
|
@@ -307,6 +343,96 @@ class DropInTests: XCTestCase {
|
307 | 343 |
|
308 | 344 | wait(for: [waitExpectation], timeout: 30)
|
309 | 345 | }
|
| 346 | + |
| 347 | + func testReload() throws { |
| 348 | + |
| 349 | + let config = DropInComponent.Configuration() |
| 350 | + |
| 351 | + let paymentMethods = try JSONDecoder().decode( |
| 352 | + PaymentMethods.self, |
| 353 | + from: XCTUnwrap(DropInTests.paymentMethods.data(using: .utf8)) |
| 354 | + ) |
| 355 | + |
| 356 | + let updatedPaymentMethods = try JSONDecoder().decode( |
| 357 | + PaymentMethods.self, |
| 358 | + from: XCTUnwrap(DropInTests.paymentMethodsWithSingleInstant.data(using: .utf8)) |
| 359 | + ) |
| 360 | + |
| 361 | + let expectation = expectation(description: "Api Client Called") |
| 362 | + |
| 363 | + let apiClient = APIClientMock() |
| 364 | + apiClient.mockedResults = [ |
| 365 | + .success(OrderStatusResponse( |
| 366 | + remainingAmount: .init(value: 100, currencyCode: "EUR"), |
| 367 | + paymentMethods: nil |
| 368 | + )) |
| 369 | + ] |
| 370 | + apiClient.onExecute = { |
| 371 | + XCTAssertTrue($0 is OrderStatusRequest) |
| 372 | + expectation.fulfill() |
| 373 | + } |
| 374 | + |
| 375 | + let sut = DropInComponent( |
| 376 | + paymentMethods: paymentMethods, |
| 377 | + context: Dummy.context, |
| 378 | + configuration: config, |
| 379 | + apiClient: apiClient |
| 380 | + ) |
| 381 | + |
| 382 | + try sut.reload(with: .init(pspReference: "", orderData: ""), updatedPaymentMethods) |
| 383 | + |
| 384 | + wait(for: [expectation], timeout: 10) |
| 385 | + |
| 386 | + XCTAssertEqual(sut.paymentMethods, updatedPaymentMethods) |
| 387 | + } |
| 388 | + |
| 389 | + func testReloadFailure() throws { |
| 390 | + |
| 391 | + let config = DropInComponent.Configuration() |
| 392 | + |
| 393 | + let paymentMethods = try JSONDecoder().decode( |
| 394 | + PaymentMethods.self, |
| 395 | + from: XCTUnwrap(DropInTests.paymentMethods.data(using: .utf8)) |
| 396 | + ) |
| 397 | + |
| 398 | + let updatedPaymentMethods = try JSONDecoder().decode( |
| 399 | + PaymentMethods.self, |
| 400 | + from: XCTUnwrap(DropInTests.paymentMethodsWithSingleInstant.data(using: .utf8)) |
| 401 | + ) |
| 402 | + |
| 403 | + let apiClientExpectation = expectation(description: "Api Client Called") |
| 404 | + let failExpectation = expectation(description: "Delegate didFail Called") |
| 405 | + |
| 406 | + let apiClient = APIClientMock() |
| 407 | + apiClient.mockedResults = [ |
| 408 | + // Returning a random error so the reload fails |
| 409 | + .failure(APIError(status: nil, errorCode: "", errorMessage: "", type: .internal)) |
| 410 | + ] |
| 411 | + apiClient.onExecute = { |
| 412 | + XCTAssertTrue($0 is OrderStatusRequest) |
| 413 | + apiClientExpectation.fulfill() |
| 414 | + } |
| 415 | + |
| 416 | + let sut = DropInComponent( |
| 417 | + paymentMethods: paymentMethods, |
| 418 | + context: Dummy.context, |
| 419 | + configuration: config, |
| 420 | + apiClient: apiClient |
| 421 | + ) |
| 422 | + |
| 423 | + let delegateMock = DropInDelegateMock( |
| 424 | + didFailHandler: { _, _ in |
| 425 | + failExpectation.fulfill() |
| 426 | + }) |
| 427 | + |
| 428 | + sut.delegate = delegateMock |
| 429 | + |
| 430 | + try sut.reload(with: .init(pspReference: "", orderData: ""), updatedPaymentMethods) |
| 431 | + |
| 432 | + wait(for: [apiClientExpectation, failExpectation], timeout: 10) |
| 433 | + |
| 434 | + XCTAssertEqual(sut.paymentMethods, paymentMethods) // Should still be the old paymentMethods |
| 435 | + } |
310 | 436 | }
|
311 | 437 |
|
312 | 438 | extension UIViewController {
|
|
0 commit comments