Skip to content

Commit

Permalink
Adding snapshot tests for SecuredViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
goergisn committed Jan 25, 2024
1 parent 3a33db9 commit fdab715
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
81616BE52B271CF900D341FF /* FormVerticalStackItemView+IsValid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81616BE32B271C8D00D341FF /* FormVerticalStackItemView+IsValid.swift */; };
81616BE62B271CFB00D341FF /* FormVerticalStackItemView+IsValid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81616BE32B271C8D00D341FF /* FormVerticalStackItemView+IsValid.swift */; };
8169B9EC2A0506CC00AAC9F8 /* Adyen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2C0E03322097917008616F6 /* Adyen.framework */; };
817F6D8C2B62A6110010D248 /* SecuredViewControllerUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817F6D8B2B62A6110010D248 /* SecuredViewControllerUITests.swift */; };
81825CB82AC59C3300F91912 /* UIView+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81825CB72AC59C3300F91912 /* UIView+Search.swift */; };
81825CB92AC59C3300F91912 /* UIView+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81825CB72AC59C3300F91912 /* UIView+Search.swift */; };
81825CBB2AC59C4000F91912 /* UIViewController+Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81825CBA2AC59C4000F91912 /* UIViewController+Search.swift */; };
Expand Down Expand Up @@ -1416,6 +1417,7 @@
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>"; };
81616BE32B271C8D00D341FF /* FormVerticalStackItemView+IsValid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FormVerticalStackItemView+IsValid.swift"; sourceTree = "<group>"; };
817F6D8B2B62A6110010D248 /* SecuredViewControllerUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecuredViewControllerUITests.swift; sourceTree = "<group>"; };
81825CB72AC59C3300F91912 /* UIView+Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Search.swift"; sourceTree = "<group>"; };
81825CBA2AC59C4000F91912 /* UIViewController+Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Search.swift"; sourceTree = "<group>"; };
81825CC02AC59C6400F91912 /* XCTestCase+RootViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "XCTestCase+RootViewController.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2494,6 +2496,7 @@
00EACBD228855CF70082B360 /* Online Banking */,
E7975F97288040BF00A12C40 /* Atome */,
007D791D2823A83100382D31 /* Affirm */,
817F6D8B2B62A6110010D248 /* SecuredViewControllerUITests.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -7278,6 +7281,7 @@
F9CCA3C4296ECB9900AD643D /* AtomeComponentUITests.swift in Sources */,
813BF1132B2365400096940E /* XCTestCase+FirstResponder.swift in Sources */,
F9CCA3C9296ECB9900AD643D /* OnlineBankingComponentUITests.swift in Sources */,
817F6D8C2B62A6110010D248 /* SecuredViewControllerUITests.swift in Sources */,
0022095D29A4C67700B2BACD /* AnalyticsProviderMock.swift in Sources */,
F9CCA3D5296ECD3000AD643D /* AdyenCoder.swift in Sources */,
F9CCA3D6296ECD3C00AD643D /* PresentationDelegateMock.swift in Sources */,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions UITests/Components/SecuredViewControllerUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// 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 Foundation

import XCTest
@_spi(AdyenInternal) @testable import Adyen
@testable import AdyenComponents
@testable import AdyenCard

class SecuredViewControllerUITests: XCTestCase {

func testBlur() throws {
struct DummyStyle: ViewStyle {
var backgroundColor: UIColor
}

let cardComponent = CardComponent(
paymentMethod: CardPaymentMethod(
type: .scheme,
name: "scheme",
fundingSource: .credit,
brands: [.bcmc]
),
context: Dummy.context
)

let sut = try XCTUnwrap(cardComponent.viewController as? SecuredViewController<CardViewController>)
setupRootViewController(sut)

try withoutAnimation {
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
wait { sut.view.subviews.contains(where: { $0 is UIVisualEffectView }) }
verifyViewControllerImage(matching: sut, named: "secured-view-controller-blurred")

NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
wait { !sut.view.subviews.contains(where: { $0 is UIVisualEffectView }) }
verifyViewControllerImage(matching: sut, named: "secured-view-controller-unblurred")
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 26 additions & 11 deletions UITests/Helpers/XCTestCase+SnapshotTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,53 @@ extension XCTestCase {

func assertViewControllerImage(matching viewController: @autoclosure () throws -> UIViewController,
named name: String,
devices: [ViewImageConfig] = [.iPhone12],
record: Bool = false,
device: ViewImageConfig = .iPhone12,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line) {

for device in devices {
try SnapshotTesting.assertSnapshot(matching: viewController(),
as: .image(on: device, perceptualPrecision: 0.98),
named: name,
record: false,
file: file,
testName: "\(testName)-\(device.description)",
line: line)
}
try SnapshotTesting.assertSnapshot(
matching: viewController(),
as: .image(drawHierarchyInKeyWindow: true, perceptualPrecision: 0.98),
named: name,
record: record,
file: file,
testName: "\(testName)-\(device.description)",
line: line
)
}

/// Verifies whether or not the snapshot of the view controller matches the previously recorded snapshot
///
/// Multiple verification snapshots are taken within the timeout and compared with the reference snapshot
func verifyViewControllerImage(matching viewController: @autoclosure () throws -> UIViewController,
named name: String,
record: Bool = false,
timeout: TimeInterval = 120,
device: ViewImageConfig = .iPhone12,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line) {

if record {
try assertViewControllerImage(
matching: viewController(),
named: name,
record: true,
device: device,
file: file,
testName: testName,
line: line
)
return
}

wait(
until: {
let failure = try! verifySnapshot(
of: viewController(),
as: .image(on: device, perceptualPrecision: 0.98),
as: .image(drawHierarchyInKeyWindow: true, perceptualPrecision: 0.98),
named: name,
record: false,
file: file,
Expand Down

0 comments on commit fdab715

Please sign in to comment.