-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Modules/Legacy/Core/Sources/Document Scanning/DocumentCameraViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Created by Geoff Pado on 5/16/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import VisionKit | ||
|
||
protocol DocumentCameraViewController: UIViewController { | ||
var delegate: VNDocumentCameraViewControllerDelegate? { get set } | ||
} | ||
|
||
extension VNDocumentCameraViewController: DocumentCameraViewController {} | ||
|
||
class StubDocumentCameraViewController: UIViewController, DocumentCameraViewController { | ||
weak var delegate: VNDocumentCameraViewControllerDelegate? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Modules/Legacy/Core/Tests/Document Scanning/DocumentScanningControllerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Created by Geoff Pado on 5/16/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import PurchasingDoubles | ||
import VisionKit | ||
import XCTest | ||
|
||
@testable import Core | ||
|
||
class DocumentScanningControllerTests: XCTestCase { | ||
func testCameraViewControllerIsReturnedIfPurchased() { | ||
let repository = SpyRepository(withCheese: .purchased) | ||
let scanningController = DocumentScanningController(delegate: nil, purchaseRepository: repository) | ||
let cameraViewController = scanningController.cameraViewController() | ||
|
||
XCTAssert(cameraViewController is DocumentCameraViewController) | ||
} | ||
|
||
func testCameraViewControllerReturnsAlertIfNotPurchased() { | ||
let repository = SpyRepository(withCheese: .unavailable) | ||
let scanningController = DocumentScanningController(delegate: nil, purchaseRepository: repository) | ||
let cameraViewController = scanningController.cameraViewController() | ||
|
||
XCTAssert(cameraViewController is UIAlertController) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...o Selection/Photo Library/Data Source/PhotoLibraryDataSourceExtraItemsProviderTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Created by Geoff Pado on 5/16/24. | ||
// Copyright © 2024 Cocoatype, LLC. All rights reserved. | ||
|
||
import PurchasingDoubles | ||
import XCTest | ||
|
||
@testable import Core | ||
@testable import Defaults | ||
|
||
class PhotoLibraryDataSourceExtraItemsProviderTests: XCTestCase { | ||
@Defaults.Value(key: .hideDocumentScanner) var hideDocumentScanner: Bool | ||
override func tearDown() { | ||
hideDocumentScanner = false | ||
super.tearDown() | ||
} | ||
|
||
func testDocumentScannerIsIncludedIfPurchasedAndSupportedAndNotHidden() { | ||
let repository = SpyRepository(withCheese: .purchased) | ||
let provider = PhotoLibraryDataSourceExtraItemsProvider(isDocumentScannerSupported: true, purchaseRepository: repository) | ||
hideDocumentScanner = false | ||
XCTAssertTrue(provider.extraItems.contains(where: \.isDocumentScan)) | ||
} | ||
|
||
func testDocumentScannerIsIncludedIfNotPurchasedAndNotHidden() { | ||
let repository = SpyRepository(withCheese: .unavailable) | ||
let provider = PhotoLibraryDataSourceExtraItemsProvider(isDocumentScannerSupported: true, purchaseRepository: repository) | ||
hideDocumentScanner = false | ||
XCTAssertTrue(provider.extraItems.contains(where: \.isDocumentScan)) | ||
} | ||
|
||
func testDocumentScannerIsIncludedIfPurchasedAndHidden() { | ||
let repository = SpyRepository(withCheese: .purchased) | ||
let provider = PhotoLibraryDataSourceExtraItemsProvider(isDocumentScannerSupported: true, purchaseRepository: repository) | ||
hideDocumentScanner = true | ||
XCTAssertTrue(provider.extraItems.contains(where: \.isDocumentScan)) | ||
} | ||
|
||
func testDocumentScannerIsNotIncludedIfNotPurchasedAndHidden() { | ||
let repository = SpyRepository(withCheese: .unavailable) | ||
let provider = PhotoLibraryDataSourceExtraItemsProvider(isDocumentScannerSupported: true, purchaseRepository: repository) | ||
hideDocumentScanner = true | ||
XCTAssertFalse(provider.extraItems.contains(where: \.isDocumentScan)) | ||
} | ||
|
||
func testDocumentScannerIsNotIncludedIfNotSupported() { | ||
let repository = SpyRepository(withCheese: .purchased) | ||
let provider = PhotoLibraryDataSourceExtraItemsProvider(isDocumentScannerSupported: false, purchaseRepository: repository) | ||
hideDocumentScanner = false | ||
XCTAssertFalse(provider.extraItems.contains(where: \.isDocumentScan)) | ||
} | ||
} | ||
|
||
private extension PhotoLibraryItem { | ||
var isDocumentScan: Bool { | ||
switch self { | ||
case .documentScan: return true | ||
case .asset, .limitedLibrary: return false | ||
} | ||
} | ||
} | ||
|
||
private extension PhotoLibraryDataSourceExtraItemsProvider { | ||
var extraItems: [PhotoLibraryItem] { | ||
(0..<itemsCount).map { item(atIndex: $0) } | ||
} | ||
} |