|
| 1 | +// |
| 2 | +// Copyright (c) 2025 Adyen N.V. |
| 3 | +// |
| 4 | +// This file is open source and available under the MIT license. See the LICENSE file for more info. |
| 5 | +// |
| 6 | + |
| 7 | +@testable import AdyenCardScanner |
| 8 | +import Foundation |
| 9 | +import QuartzCore |
| 10 | + |
| 11 | +class CardScannerViewModelMock: CardScannerViewModelProtocol { |
| 12 | + // MARK: - videoPreviewLayer |
| 13 | + |
| 14 | + var videoPreviewLayer: CALayer = .init() |
| 15 | + |
| 16 | + // MARK: - configureSession |
| 17 | + |
| 18 | + var configureSessionCallsCount = 0 |
| 19 | + var configureSessionCalled: Bool { |
| 20 | + configureSessionCallsCount > 0 |
| 21 | + } |
| 22 | + |
| 23 | + var configureSessionClosure: (() -> Void)? |
| 24 | + |
| 25 | + func configureSession() { |
| 26 | + configureSessionCallsCount += 1 |
| 27 | + configureSessionClosure?() |
| 28 | + } |
| 29 | + |
| 30 | + // MARK: - startCaptureSession |
| 31 | + |
| 32 | + var startCaptureSessionCallsCount = 0 |
| 33 | + var startCaptureSessionCalled: Bool { |
| 34 | + startCaptureSessionCallsCount > 0 |
| 35 | + } |
| 36 | + |
| 37 | + var startCaptureSessionClosure: (() -> Void)? |
| 38 | + |
| 39 | + func startCaptureSession() { |
| 40 | + startCaptureSessionCallsCount += 1 |
| 41 | + startCaptureSessionClosure?() |
| 42 | + } |
| 43 | + |
| 44 | + // MARK: - stopCaptureSession |
| 45 | + |
| 46 | + var stopCaptureSessionCallsCount = 0 |
| 47 | + var stopCaptureSessionCalled: Bool { |
| 48 | + stopCaptureSessionCallsCount > 0 |
| 49 | + } |
| 50 | + |
| 51 | + var stopCaptureSessionClosure: (() -> Void)? |
| 52 | + |
| 53 | + func stopCaptureSession() { |
| 54 | + stopCaptureSessionCallsCount += 1 |
| 55 | + stopCaptureSessionClosure?() |
| 56 | + } |
| 57 | + |
| 58 | + // MARK: - updateVideoOrientation |
| 59 | + |
| 60 | + var updateVideoOrientationCallsCount = 0 |
| 61 | + var updateVideoOrientationCalled: Bool { |
| 62 | + updateVideoOrientationCallsCount > 0 |
| 63 | + } |
| 64 | + |
| 65 | + var updateVideoOrientationClosure: (() -> Void)? |
| 66 | + |
| 67 | + func updateVideoOrientation() { |
| 68 | + updateVideoOrientationCallsCount += 1 |
| 69 | + updateVideoOrientationClosure?() |
| 70 | + } |
| 71 | + |
| 72 | + // MARK: - update |
| 73 | + |
| 74 | + var updateCallsCount = 0 |
| 75 | + var updateCalled: Bool { |
| 76 | + updateCallsCount > 0 |
| 77 | + } |
| 78 | + |
| 79 | + var updateReceivedPreviewLayerFrame: CGRect? |
| 80 | + var updateReceivedROIInPreviewLayer: CGRect? |
| 81 | + var updateReceivedInvocations: [(CGRect, CGRect)] = [] |
| 82 | + var updateClosure: ((CGRect, CGRect) -> Void)? |
| 83 | + |
| 84 | + func update(previewLayerFrame: CGRect, roiInPreviewLayer: CGRect) { |
| 85 | + updateCallsCount += 1 |
| 86 | + updateReceivedPreviewLayerFrame = previewLayerFrame |
| 87 | + updateReceivedROIInPreviewLayer = roiInPreviewLayer |
| 88 | + updateReceivedInvocations.append((previewLayerFrame, roiInPreviewLayer)) |
| 89 | + updateClosure?(previewLayerFrame, roiInPreviewLayer) |
| 90 | + } |
| 91 | +} |
0 commit comments