From b1335c5e26c8079385b1e7181eec57503f55a070 Mon Sep 17 00:00:00 2001 From: Tobias Hagemann Date: Fri, 13 Sep 2024 10:25:21 +0200 Subject: [PATCH] Fixed snapshots --- .../Snapshots/SnapshotCoordinator.swift | 22 ++++++-- .../FileProviderExtension.swift | 7 ++- .../FileProviderCoordinatorSnapshotMock.swift | 12 +++-- Snapshots/Snapshots.swift | 51 +++---------------- fastlane/Snapfile | 6 +-- 5 files changed, 36 insertions(+), 62 deletions(-) diff --git a/Cryptomator/Snapshots/SnapshotCoordinator.swift b/Cryptomator/Snapshots/SnapshotCoordinator.swift index dae0d3f1c..30a75aa07 100644 --- a/Cryptomator/Snapshots/SnapshotCoordinator.swift +++ b/Cryptomator/Snapshots/SnapshotCoordinator.swift @@ -8,6 +8,7 @@ #if SNAPSHOTS import CryptomatorCommonCore +import Dependencies import FileProvider import Foundation import LocalAuthentication @@ -31,9 +32,7 @@ class SnapshotCoordinator: MainCoordinator { } override func showVaultDetail(for vaultInfo: VaultInfo) { - let snapshotFileProviderConnectorMock = SnapshotFileProviderConnectorMock() - snapshotFileProviderConnectorMock.proxy = SnapshotVaultLockingMock() - let viewModel = VaultDetailViewModel(vaultInfo: vaultInfo, vaultManager: VaultDBManager.shared, fileProviderConnector: snapshotFileProviderConnectorMock, passwordManager: SnapshotVaultPasswordManagerMock(), dbManager: DatabaseManager.shared, vaultKeepUnlockedSettings: SnapshotVaultKeepUnlockedSettings()) + let viewModel = VaultDetailViewModel(vaultInfo: vaultInfo, vaultManager: VaultDBManager.shared, passwordManager: SnapshotVaultPasswordManagerMock(), dbManager: DatabaseManager.shared, vaultKeepUnlockedSettings: SnapshotVaultKeepUnlockedSettings()) let vaultDetailViewController = VaultDetailViewController(viewModel: viewModel) let detailNavigationController = BaseNavigationController(rootViewController: vaultDetailViewController) rootViewController.showDetailViewController(detailNavigationController, sender: nil) @@ -57,8 +56,23 @@ class SnapshotCoordinator: MainCoordinator { } } +private enum FileProviderConnectorKey: DependencyKey { + static var liveValue: FileProviderConnector = SnapshotFileProviderConnectorMock() + #if DEBUG + static var testValue: FileProviderConnector = SnapshotFileProviderConnectorMock() + #endif +} + +public extension DependencyValues { + var fileProviderConnector: FileProviderConnector { + get { self[FileProviderConnectorKey.self] } + set { self[FileProviderConnectorKey.self] = newValue } + } +} + private class SnapshotFileProviderConnectorMock: FileProviderConnector { - var proxy: Any? + let proxy = SnapshotVaultLockingMock() + func getXPC(serviceName: NSFileProviderServiceName, domain: NSFileProviderDomain?) -> Promise> { return getCastedProxy() } diff --git a/FileProviderExtension/FileProviderExtension.swift b/FileProviderExtension/FileProviderExtension.swift index 50ef6008c..def01d6d2 100644 --- a/FileProviderExtension/FileProviderExtension.swift +++ b/FileProviderExtension/FileProviderExtension.swift @@ -250,10 +250,9 @@ class FileProviderExtension: NSFileProviderExtension { #if SNAPSHOTS let snapshotVaultPath = CloudPath(LocalizedString.getValue("snapshots.main.vault1")) let snapshotDomain = NSFileProviderDomain(vaultUID: "12345", displayName: snapshotVaultPath.lastPathComponent) - serviceSources.append(VaultUnlockingServiceSourceSnapshotMock(domain: snapshotDomain, - notificator: notificator, - dbPath: dbPath, - delegate: LocalURLProvider(domain: snapshotDomain))) + if let manager = NSFileProviderManager(for: snapshotDomain) { + serviceSources.append(VaultUnlockingServiceSourceSnapshotMock(domain: snapshotDomain, notificator: notificator, dbPath: dbPath, delegate: LocalURLProvider(domain: snapshotDomain), taskRegistrator: manager)) + } #else if let domain = domain, let localURLProvider = localURLProvider, let dbPath = dbPath, let notificator = notificator, let manager = NSFileProviderManager(for: domain) { serviceSources.append(VaultUnlockingServiceSource(domain: domain, notificator: notificator, dbPath: dbPath, delegate: localURLProvider, taskRegistrator: manager)) diff --git a/FileProviderExtensionUI/Snapshots/FileProviderCoordinatorSnapshotMock.swift b/FileProviderExtensionUI/Snapshots/FileProviderCoordinatorSnapshotMock.swift index eb46c6fd0..8230facda 100644 --- a/FileProviderExtensionUI/Snapshots/FileProviderCoordinatorSnapshotMock.swift +++ b/FileProviderExtensionUI/Snapshots/FileProviderCoordinatorSnapshotMock.swift @@ -8,6 +8,8 @@ #if SNAPSHOTS import CryptomatorCommonCore +import CryptomatorFileProvider +import Dependencies import FileProviderUI import LocalAuthentication import Promises @@ -21,8 +23,8 @@ class FileProviderCoordinatorSnapshotMock: FileProviderCoordinator { super.init(extensionContext: extensionContext, hostViewController: hostViewController) } - override func showManualPasswordScreen(viewModel: UnlockVaultViewModel) { - let viewModel = UnlockVaultViewModelSnapshotMock(domain: NSFileProviderDomain(vaultUID: "123", displayName: "")) + override func showManualLogin(for domain: NSFileProviderDomain, unlockError: UnlockError) { + let viewModel = UnlockVaultViewModelSnapshotMock(domain: domain) let unlockVaultVC = UnlockVaultViewController(viewModel: viewModel) unlockVaultVC.coordinator = self navigationController.pushViewController(unlockVaultVC, animated: false) @@ -33,11 +35,10 @@ class UnlockVaultViewModelSnapshotMock: UnlockVaultViewModel { init(domain: NSFileProviderDomain) { super.init(domain: domain, wrongBiometricalPassword: false, - fileProviderConnector: FileProviderXPCConnector.shared, passwordManager: VaultPasswordManagerSnapshotMock(), vaultAccountManager: VaultAccountDBManager.shared, providerManager: CloudProviderDBManager.shared, - vaultCache: VaultDBCache(dbWriter: CryptomatorDatabase.shared.dbPool)) + vaultCache: VaultDBCache()) } } @@ -64,7 +65,8 @@ extension UnlockVaultViewController { }() @objc func swizzled_unlock() { - let getXPCPromise: Promise> = FileProviderXPCConnector.shared.getXPC(serviceName: .vaultUnlocking, domain: nil) + @Dependency(\.fileProviderConnector) var fileProviderConnector + let getXPCPromise: Promise> = fileProviderConnector.getXPC(serviceName: .vaultUnlocking, domain: nil) getXPCPromise.then { xpc in xpc.proxy.unlockVault(kek: [UInt8](), reply: { [weak self] _ in self?.coordinator?.done() diff --git a/Snapshots/Snapshots.swift b/Snapshots/Snapshots.swift index 87cb7ef6a..44cf29439 100644 --- a/Snapshots/Snapshots.swift +++ b/Snapshots/Snapshots.swift @@ -8,6 +8,7 @@ import XCTest +@MainActor class Snapshots: XCTestCase { var app: XCUIApplication! var filesApp: XCUIApplication! @@ -166,19 +167,6 @@ class Snapshots: XCTestCase { XCTAssert(filesApp.wait(for: .runningForeground, timeout: 5.0)) navigateFromRecentsToFilesAppOverview() - - // Tap on More Locations - tapMoreLocationsInFilesAppOverview() - - // Enable Cryptomator as FileProvider - let browseCollectionView = filesApp.collectionViews["Browse View"] - let cryptomatorCell = browseCollectionView.cells["DOC.sidebar.item.Cryptomator"] - let cryptomatorCellSwitch = cryptomatorCell.switches.firstMatch - XCTAssert(cryptomatorCellSwitch.waitForIsHittable(timeout: 3.0)) - cryptomatorCellSwitch.tap() - - // Press Done - tapDoneButtonInFilesAppOverview() } private func navigateFromRecentsToFilesAppOverview() { @@ -186,38 +174,7 @@ class Snapshots: XCTestCase { return } // Tap on Browse - filesApp.tabBars["DOC.browsingModeTabBar"].buttons.element(boundBy: 1).tap(withNumberOfTaps: 2, numberOfTouches: 1) - } - - private func tapDoneButtonInFilesAppOverview() { - let doneButton: XCUIElement - switch UIDevice.current.userInterfaceIdiom { - case .phone: - doneButton = filesApp.navigationBars["FullDocumentManagerViewControllerNavigationBar"].buttons.firstMatch - case .pad: - doneButton = filesApp.navigationBars.firstMatch.buttons.element(boundBy: 1) - default: - XCTFail("Tap Done button in Files app overview is not supported for device: \(UIDevice.current.userInterfaceIdiom)") - return - } - XCTAssert(doneButton.waitForIsHittable(timeout: 3.0)) - doneButton.tap() - } - - private func tapMoreLocationsInFilesAppOverview() { - let index: Int - switch UIDevice.current.userInterfaceIdiom { - case .phone: - index = 2 - case .pad: - index = 3 - default: - XCTFail("Tap Done button in Files app overview is not supported for device: \(UIDevice.current.userInterfaceIdiom)") - return - } - let moreLocationsCell = filesApp.cells.element(boundBy: index) - XCTAssert(moreLocationsCell.waitForIsHittable(timeout: 3.0)) - moreLocationsCell.tap() + filesApp.tabBars["DOC.browsingModeTabBar"].buttons.element(boundBy: 2).tap(withNumberOfTaps: 2, numberOfTouches: 1) } private func snapshotFilesOverview() { @@ -233,6 +190,10 @@ class Snapshots: XCTestCase { // Start Cryptomator FileProvider cryptomatorCell.tap() + // Enable Cryptomator as FileProvider + let activateButton = filesApp.alerts.element(boundBy: 0).buttons.element(boundBy: 1) + activateButton.tap() + // Unlock Screen let vaultUnlockTableView = filesApp.tables["Snapshot_UnlockVaultViewController"] XCTAssert(vaultUnlockTableView.waitForExistence(timeout: 20.0)) diff --git a/fastlane/Snapfile b/fastlane/Snapfile index dc2ac8ece..113c13a2f 100644 --- a/fastlane/Snapfile +++ b/fastlane/Snapfile @@ -1,9 +1,7 @@ # A list of devices you want to take the screenshots from devices([ - "iPhone 13 Pro Max", - "iPhone 8 Plus", - "iPad Pro (12.9-inch) (5th generation)", - "iPad Pro (12.9-inch) (2nd generation)", + "iPhone 15 Pro Max", + "iPad Pro 13-inch (M4)", ]) languages([