From 4aa633dd7a4d4d8e3e76f125e9b50fac812dcb62 Mon Sep 17 00:00:00 2001 From: Alex Guretzki Date: Tue, 3 Sep 2024 15:28:31 +0200 Subject: [PATCH] Adding CardComponent snapshot tests --- Adyen.xcodeproj/project.pbxproj | 6 + .../Components/CardComponentUITests.swift | 118 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Tests/SnapshotTests/Components/CardComponentUITests.swift diff --git a/Adyen.xcodeproj/project.pbxproj b/Adyen.xcodeproj/project.pbxproj index ee7f8fca3d..dfbd75064b 100644 --- a/Adyen.xcodeproj/project.pbxproj +++ b/Adyen.xcodeproj/project.pbxproj @@ -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 */; }; @@ -1619,6 +1621,7 @@ 814044302B62BDBB00EB7FBA /* SecuredViewControllerUITests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SecuredViewControllerUITests.swift; sourceTree = ""; }; 814276612A7145F50081E896 /* AddressInputFormViewController+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AddressInputFormViewController+ViewModel.swift"; sourceTree = ""; }; 8149CCB52B0B855F007235E2 /* ThreeDS2PlusDACoreActionHandlerTests+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ThreeDS2PlusDACoreActionHandlerTests+Constants.swift"; sourceTree = ""; }; + 814E15492C87407F00D90D4B /* CardComponentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardComponentUITests.swift; sourceTree = ""; }; 817C907F2C3D590C0072A202 /* GiftCardComponentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiftCardComponentUITests.swift; sourceTree = ""; }; 817C908B2C3EB8B70072A202 /* bg-BG */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "bg-BG"; path = "bg-BG.lproj/Localizable.strings"; sourceTree = ""; }; 817C908C2C3EB8C10072A202 /* ca-ES */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "ca-ES"; path = "ca-ES.lproj/Localizable.strings"; sourceTree = ""; }; @@ -2749,6 +2752,7 @@ 00EACBD328855D190082B360 /* OnlineBankingComponentUITests.swift */, 007D790B2812C81400382D31 /* AtomeComponentUITests.swift */, 007D791E2823A84C00382D31 /* AffirmComponentUITests.swift */, + 814E15492C87407F00D90D4B /* CardComponentUITests.swift */, ); path = Components; sourceTree = ""; @@ -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 */, @@ -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 */, diff --git a/Tests/SnapshotTests/Components/CardComponentUITests.swift b/Tests/SnapshotTests/Components/CardComponentUITests.swift new file mode 100644 index 0000000000..988f830d1b --- /dev/null +++ b/Tests/SnapshotTests/Components/CardComponentUITests.swift @@ -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" + } + } +}