Skip to content

Commit

Permalink
Adding CardComponent snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Sep 3, 2024
1 parent f68621c commit 4aa633d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
8140A3762A3327B500896403 /* AdyenComponents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9175E55259393E800D653BE /* AdyenComponents.framework */; };
814276622A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814276612A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift */; };
8149CCB62B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8149CCB52B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift */; };
814E154A2C87407F00D90D4B /* CardComponentUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814E15492C87407F00D90D4B /* CardComponentUITests.swift */; };
814E154B2C87407F00D90D4B /* CardComponentUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 814E15492C87407F00D90D4B /* CardComponentUITests.swift */; };
8152A2982BF7585B00AF957C /* FormItemViewBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9A781AD2403BD1600E12487 /* FormItemViewBuilderTests.swift */; };
8169B9EC2A0506CC00AAC9F8 /* Adyen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2C0E03322097917008616F6 /* Adyen.framework */; };
817C90802C3D590C0072A202 /* GiftCardComponentUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817C907F2C3D590C0072A202 /* GiftCardComponentUITests.swift */; };
Expand Down Expand Up @@ -1619,6 +1621,7 @@
814044302B62BDBB00EB7FBA /* SecuredViewControllerUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecuredViewControllerUITests.swift; sourceTree = "<group>"; };
814276612A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressInputFormViewController+ViewModel.swift"; sourceTree = "<group>"; };
8149CCB52B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ThreeDS2PlusDACoreActionHandlerTests+Constants.swift"; sourceTree = "<group>"; };
814E15492C87407F00D90D4B /* CardComponentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardComponentUITests.swift; sourceTree = "<group>"; };
817C907F2C3D590C0072A202 /* GiftCardComponentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiftCardComponentUITests.swift; sourceTree = "<group>"; };
817C908B2C3EB8B70072A202 /* bg-BG */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "bg-BG"; path = "bg-BG.lproj/Localizable.strings"; sourceTree = "<group>"; };
817C908C2C3EB8C10072A202 /* ca-ES */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ca-ES"; path = "ca-ES.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2749,6 +2752,7 @@
00EACBD328855D190082B360 /* OnlineBankingComponentUITests.swift */,
007D790B2812C81400382D31 /* AtomeComponentUITests.swift */,
007D791E2823A84C00382D31 /* AffirmComponentUITests.swift */,
814E15492C87407F00D90D4B /* CardComponentUITests.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -6629,6 +6633,7 @@
81DF940C2BAAD8EB0001DCBC /* XCTestCase+FirstResponder.swift in Sources */,
81DF940D2BAAD8EB0001DCBC /* OnlineBankingComponentUITests.swift in Sources */,
81DF940E2BAAD8EB0001DCBC /* SecuredViewControllerUITests.swift in Sources */,
814E154B2C87407F00D90D4B /* CardComponentUITests.swift in Sources */,
817C90812C3D590C0072A202 /* GiftCardComponentUITests.swift in Sources */,
81DF940F2BAAD8EB0001DCBC /* (null) in Sources */,
81DF94112BAAD8EB0001DCBC /* AdyenCoder.swift in Sources */,
Expand Down Expand Up @@ -7708,6 +7713,7 @@
0022095C29A4C65E00B2BACD /* BoletoComponentUITests.swift in Sources */,
81088A242BDBC2C5007FCDB9 /* CancellableMock.swift in Sources */,
F9CCA3D2296ECCFA00AD643D /* XCTestCase+FormTextItemView.swift in Sources */,
814E154A2C87407F00D90D4B /* CardComponentUITests.swift in Sources */,
817C90802C3D590C0072A202 /* GiftCardComponentUITests.swift in Sources */,
F9CCA3DE296ED1F400AD643D /* XCTestCase+SnapshotTesting.swift in Sources */,
81825CBC2AC59C4000F91912 /* UIViewController+Search.swift in Sources */,
Expand Down
118 changes: 118 additions & 0 deletions Tests/SnapshotTests/Components/CardComponentUITests.swift
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"
}
}
}

0 comments on commit 4aa633d

Please sign in to comment.