-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Guretzki
committed
Sep 3, 2024
1 parent
f68621c
commit 4aa633d
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
Tests/SnapshotTests/Components/CardComponentUITests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// Copyright (c) 2024 Adyen N.V. | ||
// | ||
// This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
// | ||
|
||
import XCTest | ||
@_spi(AdyenInternal) @testable import Adyen | ||
@testable import AdyenCard | ||
@testable import AdyenComponents | ||
|
||
class CardComponentUITests: XCTestCase { | ||
|
||
let paymentMethod = CardPaymentMethod( | ||
type: .bcmc, | ||
name: "Test name", | ||
fundingSource: .debit, | ||
brands: [.accel] | ||
) | ||
|
||
func test_all_fields() throws { | ||
|
||
var configuration = CardComponent.Configuration.extendedConfiguration | ||
|
||
let sut = CardComponent( | ||
paymentMethod: paymentMethod, | ||
context: Dummy.context, | ||
configuration: configuration | ||
) | ||
|
||
verifyViewControllerImage(matching: sut.viewController, named: "CardComponentUITests.\(#function)") | ||
} | ||
|
||
func test_hidden_cvc() throws { | ||
|
||
var configuration = CardComponent.Configuration.minimalConfiguration | ||
configuration.showsSecurityCodeField = false | ||
|
||
let sut = CardComponent( | ||
paymentMethod: paymentMethod, | ||
context: Dummy.context, | ||
configuration: configuration | ||
) | ||
|
||
verifyViewControllerImage(matching: sut.viewController, named: "CardComponentUITests.\(#function)") | ||
} | ||
|
||
func test_billing_address_modes() throws { | ||
|
||
var configuration = CardComponent.Configuration.minimalConfiguration | ||
|
||
[CardComponent.AddressFormType.none, .full, .postalCode].forEach { mode in | ||
configuration.billingAddress.mode = mode | ||
|
||
let sut = CardComponent( | ||
paymentMethod: paymentMethod, | ||
context: Dummy.context, | ||
configuration: configuration | ||
) | ||
|
||
verifyViewControllerImage( | ||
matching: sut.viewController, | ||
named: "CardComponentUITests.\(#function).\(mode.description)" | ||
) | ||
} | ||
|
||
} | ||
} | ||
|
||
// MARK: - Convenience | ||
|
||
private extension CardComponent.Configuration { | ||
|
||
static var minimalConfiguration: Self { | ||
var configuration = CardComponent.Configuration() | ||
configuration.showsHolderNameField = false | ||
configuration.koreanAuthenticationMode = .hide | ||
configuration.socialSecurityNumberMode = .hide | ||
configuration.installmentConfiguration = nil | ||
return configuration | ||
} | ||
|
||
static var extendedConfiguration: Self { | ||
var configuration = CardComponent.Configuration() | ||
configuration.showsHolderNameField = true | ||
configuration.billingAddress.mode = .full | ||
configuration.koreanAuthenticationMode = .show | ||
configuration.socialSecurityNumberMode = .show | ||
configuration.installmentConfiguration = .init( | ||
cardBasedOptions: [.bcmc: .init( | ||
monthValues: [2, 3, 4], | ||
includesRevolving: true | ||
)], | ||
defaultOptions: .init( | ||
monthValues: [2, 3, 4], | ||
includesRevolving: true | ||
), | ||
showInstallmentAmount: true | ||
) | ||
return configuration | ||
} | ||
} | ||
|
||
private extension CardComponent.AddressFormType { | ||
|
||
var description: String { | ||
switch self { | ||
case let .lookup(provider): | ||
"lookup" | ||
case .full: | ||
"full" | ||
case .postalCode: | ||
"postalCode" | ||
case .none: | ||
"none" | ||
} | ||
} | ||
} |