Skip to content

Commit

Permalink
Fixed snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Sep 13, 2024
1 parent ad77d0d commit b1335c5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 62 deletions.
22 changes: 18 additions & 4 deletions Cryptomator/Snapshots/SnapshotCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#if SNAPSHOTS
import CryptomatorCommonCore
import Dependencies
import FileProvider
import Foundation
import LocalAuthentication
Expand All @@ -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)
Expand All @@ -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<T>(serviceName: NSFileProviderServiceName, domain: NSFileProviderDomain?) -> Promise<XPC<T>> {
return getCastedProxy()
}
Expand Down
7 changes: 3 additions & 4 deletions FileProviderExtension/FileProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#if SNAPSHOTS
import CryptomatorCommonCore
import CryptomatorFileProvider
import Dependencies
import FileProviderUI
import LocalAuthentication
import Promises
Expand All @@ -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)
Expand All @@ -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())
}
}

Expand All @@ -64,7 +65,8 @@ extension UnlockVaultViewController {
}()

@objc func swizzled_unlock() {
let getXPCPromise: Promise<XPC<VaultUnlocking>> = FileProviderXPCConnector.shared.getXPC(serviceName: .vaultUnlocking, domain: nil)
@Dependency(\.fileProviderConnector) var fileProviderConnector
let getXPCPromise: Promise<XPC<VaultUnlocking>> = fileProviderConnector.getXPC(serviceName: .vaultUnlocking, domain: nil)
getXPCPromise.then { xpc in
xpc.proxy.unlockVault(kek: [UInt8](), reply: { [weak self] _ in
self?.coordinator?.done()
Expand Down
51 changes: 6 additions & 45 deletions Snapshots/Snapshots.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import XCTest

@MainActor
class Snapshots: XCTestCase {
var app: XCUIApplication!
var filesApp: XCUIApplication!
Expand Down Expand Up @@ -166,58 +167,14 @@ 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() {
guard XCUIDevice.shared.orientation == .portrait else {
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() {
Expand All @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions fastlane/Snapfile
Original file line number Diff line number Diff line change
@@ -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([
Expand Down

0 comments on commit b1335c5

Please sign in to comment.