Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@
C930FB6E269D79E0006A26D2 /* AffirmDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = C930FB6D269D79E0006A26D2 /* AffirmDetails.swift */; };
C933801E276A06E1005B66CD /* BACSDirectDebitComponentTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C933801D276A06E1005B66CD /* BACSDirectDebitComponentTracker.swift */; };
C9338020276A09E7005B66CD /* BACSDirectDebitComponentTrackerProtocolMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C933801F276A09E7005B66CD /* BACSDirectDebitComponentTrackerProtocolMock.swift */; };
C93844732D79DF3B00B1E747 /* CardScannerViewModelMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93844722D79DF3B00B1E747 /* CardScannerViewModelMock.swift */; };
C93844752D7B1C4100B1E747 /* CardScannerViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93844742D7B1C4100B1E747 /* CardScannerViewControllerTests.swift */; };
C93B01B72760B03400D311A1 /* BACSConfirmationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93B01B62760B03400D311A1 /* BACSConfirmationViewController.swift */; };
C93B01B92760B06300D311A1 /* BACSConfirmationPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93B01B82760B06300D311A1 /* BACSConfirmationPresenter.swift */; };
C9454C37276A340B0086C218 /* BACSDirectDebitPresentationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9454C35276A33A00086C218 /* BACSDirectDebitPresentationDelegate.swift */; };
Expand Down Expand Up @@ -1904,6 +1906,8 @@
C930FB6D269D79E0006A26D2 /* AffirmDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AffirmDetails.swift; sourceTree = "<group>"; };
C933801D276A06E1005B66CD /* BACSDirectDebitComponentTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSDirectDebitComponentTracker.swift; sourceTree = "<group>"; };
C933801F276A09E7005B66CD /* BACSDirectDebitComponentTrackerProtocolMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSDirectDebitComponentTrackerProtocolMock.swift; sourceTree = "<group>"; };
C93844722D79DF3B00B1E747 /* CardScannerViewModelMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardScannerViewModelMock.swift; sourceTree = "<group>"; };
C93844742D7B1C4100B1E747 /* CardScannerViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardScannerViewControllerTests.swift; sourceTree = "<group>"; };
C93B01B62760B03400D311A1 /* BACSConfirmationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSConfirmationViewController.swift; sourceTree = "<group>"; };
C93B01B82760B06300D311A1 /* BACSConfirmationPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSConfirmationPresenter.swift; sourceTree = "<group>"; };
C9454C35276A33A00086C218 /* BACSDirectDebitPresentationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSDirectDebitPresentationDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3493,6 +3497,7 @@
children = (
C91BF2572D771667001F19DE /* CardImageParsingMock.swift */,
C91BF2592D7716D4001F19DE /* CaptureSessionManagingMock.swift */,
C93844722D79DF3B00B1E747 /* CardScannerViewModelMock.swift */,
);
path = Mocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -3600,6 +3605,7 @@
C91BF2562D7715D8001F19DE /* Mocks */,
C96844922D771328001DB7F1 /* CardScannerViewModelTests.swift */,
C91BF25B2D772233001F19DE /* Assets.xcassets */,
C93844742D7B1C4100B1E747 /* CardScannerViewControllerTests.swift */,
);
path = AdyenCardScannerTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -7082,6 +7088,8 @@
buildActionMask = 2147483647;
files = (
C91BF2582D771667001F19DE /* CardImageParsingMock.swift in Sources */,
C93844752D7B1C4100B1E747 /* CardScannerViewControllerTests.swift in Sources */,
C93844732D79DF3B00B1E747 /* CardScannerViewModelMock.swift in Sources */,
C91BF25A2D7716D4001F19DE /* CaptureSessionManagingMock.swift in Sources */,
C96844932D771328001DB7F1 /* CardScannerViewModelTests.swift in Sources */,
);
Expand Down
83 changes: 83 additions & 0 deletions AdyenCardScannerTests/CardScannerViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

@testable import AdyenCardScanner
import XCTest

final class CardScannerViewControllerTests: XCTestCase {

var viewModel: CardScannerViewModelMock!
var sut: CardScannerViewController!

override func tearDownWithError() throws {
viewModel = nil
sut = nil
try super.tearDownWithError()
}

func testViewDidLoadShouldCallViewModelConfigureSession() throws {
// Given
viewModel = CardScannerViewModelMock()
sut = CardScannerViewController(viewModel: viewModel)

// When
sut.loadViewIfNeeded()

// Then
XCTAssertEqual(viewModel.configureSessionCallsCount, 1)
}

func testViewWillAppearShouldStartCaptureSession() throws {
// Given
viewModel = CardScannerViewModelMock()
sut = CardScannerViewController(viewModel: viewModel)

// When
sut.viewWillAppear(true)

// Then
XCTAssertEqual(viewModel.startCaptureSessionCallsCount, 1)
}

func testViewWillAppearShouldStopCaptureSession() throws {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disappear

// Given
viewModel = CardScannerViewModelMock()
sut = CardScannerViewController(viewModel: viewModel)

// When
sut.viewWillDisappear(true)

// Then
XCTAssertEqual(viewModel.stopCaptureSessionCallsCount, 1)
}

func testViewDidLayoutSubviewsShouldUpdateVideoOrientation() throws {
// Given
viewModel = CardScannerViewModelMock()
sut = CardScannerViewController(viewModel: viewModel)

// When
sut.viewDidLayoutSubviews()

// Then
XCTAssertEqual(viewModel.updateVideoOrientationCallsCount, 1)
}

func testVideoPreviewLayetIsSetOnInit() throws {
Comment thread
nauaros marked this conversation as resolved.
// Given
let expectedVideoPreviewLayer = CALayer()
viewModel = CardScannerViewModelMock()
viewModel.videoPreviewLayer = expectedVideoPreviewLayer
sut = CardScannerViewController(viewModel: viewModel)

// When
sut.loadViewIfNeeded()

// Then
let layer = try XCTUnwrap(sut.view.layer.sublayers?.first)
XCTAssertTrue(layer === expectedVideoPreviewLayer)
}
}
91 changes: 91 additions & 0 deletions AdyenCardScannerTests/Mocks/CardScannerViewModelMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Copyright (c) 2025 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

@testable import AdyenCardScanner
import Foundation
import QuartzCore

class CardScannerViewModelMock: CardScannerViewModelProtocol {
// MARK: - videoPreviewLayer

var videoPreviewLayer: CALayer = .init()

// MARK: - configureSession

var configureSessionCallsCount = 0
var configureSessionCalled: Bool {
configureSessionCallsCount > 0
}

var configureSessionClosure: (() -> Void)?

func configureSession() {
configureSessionCallsCount += 1
configureSessionClosure?()
}

// MARK: - startCaptureSession

var startCaptureSessionCallsCount = 0
var startCaptureSessionCalled: Bool {
startCaptureSessionCallsCount > 0
}

var startCaptureSessionClosure: (() -> Void)?

func startCaptureSession() {
startCaptureSessionCallsCount += 1
startCaptureSessionClosure?()
}

// MARK: - stopCaptureSession

var stopCaptureSessionCallsCount = 0
var stopCaptureSessionCalled: Bool {
stopCaptureSessionCallsCount > 0
}

var stopCaptureSessionClosure: (() -> Void)?

func stopCaptureSession() {
stopCaptureSessionCallsCount += 1
stopCaptureSessionClosure?()
}

// MARK: - updateVideoOrientation

var updateVideoOrientationCallsCount = 0
var updateVideoOrientationCalled: Bool {
updateVideoOrientationCallsCount > 0
}

var updateVideoOrientationClosure: (() -> Void)?

func updateVideoOrientation() {
updateVideoOrientationCallsCount += 1
updateVideoOrientationClosure?()
}

// MARK: - update

var updateCallsCount = 0
var updateCalled: Bool {
updateCallsCount > 0
}

var updateReceivedPreviewLayerFrame: CGRect?
var updateReceivedROIInPreviewLayer: CGRect?
var updateReceivedInvocations: [(CGRect, CGRect)] = []
var updateClosure: ((CGRect, CGRect) -> Void)?

func update(previewLayerFrame: CGRect, roiInPreviewLayer: CGRect) {
updateCallsCount += 1
updateReceivedPreviewLayerFrame = previewLayerFrame
updateReceivedROIInPreviewLayer = roiInPreviewLayer
updateReceivedInvocations.append((previewLayerFrame, roiInPreviewLayer))
updateClosure?(previewLayerFrame, roiInPreviewLayer)
}
}
Loading