Skip to content

Commit

Permalink
test: Re enabled tests having issue with DI given the project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Aug 20, 2024
1 parent 99ffea9 commit d8d1eb0
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 171 deletions.
5 changes: 2 additions & 3 deletions kDriveAPITests/kDriveCore/DriveFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import kDriveCore
import RealmSwift
import XCTest

/* FIXME: DI issues, check target
final class DriveFileManagerTests: XCTestCase {
static let defaultTimeout = 10.0
static var driveFileManager: DriveFileManager!
Expand Down Expand Up @@ -160,7 +159,8 @@ final class DriveFileManagerTests: XCTestCase {
query: file.name,
categories: [],
belongToAllCategories: true,
sortType: .nameAZ
sortType: .nameAZ,
fileExtensions: []
)
let children = DriveFileManagerTests.driveFileManager.getCachedFile(id: DriveFileManager.searchFilesRootFile.id)?.children
let searchedFile = children?.contains { $0.id == fileProxy.id } ?? false
Expand Down Expand Up @@ -350,4 +350,3 @@ final class DriveFileManagerTests: XCTestCase {
tearDownTest(directory: testDirectory)
}
}
*/
78 changes: 38 additions & 40 deletions kDriveTests/kDrive/Launch/ITAppLaunchTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,50 +100,48 @@ final class ITAppLaunchTest: XCTestCase {
SimpleResolver.register(services)
}

/* FIXME: broken DI
@MainActor func testUnlock() throws {
// GIVEN applock enabled
UserDefaults.shared.isAppLockEnabled = true
let accountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
accountManager.currentDriveFileManager = DriveFileManager(
drive: Drive(),
apiFetcher: DriveApiFetcher(token: self.fakeAccount.token, delegate: accountManager)
)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: accountManagerFactory)
@MainActor func testUnlock() throws {
// GIVEN applock enabled
UserDefaults.shared.isAppLockEnabled = true
let accountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
accountManager.currentDriveFileManager = DriveFileManager(
drive: Drive(),
apiFetcher: DriveApiFetcher(token: self.fakeAccount.token, delegate: accountManager)
)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: accountManagerFactory)

@InjectService var accountManager: AccountManageable
XCTAssertNotNil(accountManager.currentAccount, "expecting a user logged in")
@InjectService var accountManager: AccountManageable
XCTAssertNotNil(accountManager.currentAccount, "expecting a user logged in")

@InjectService var router: AppNavigable
router.showAppLock()
@InjectService var router: AppNavigable
router.showAppLock()

let scene = UIApplication.shared.connectedScenes.first
let sceneDelegate = (scene?.delegate as? SceneDelegate)
let window = sceneDelegate?.window
let rootViewController = window?.rootViewController
XCTAssertNotNil(
rootViewController as? LockedAppViewController,
"Should be a LockedAppViewController, got \(rootViewController)"
)
let scene = UIApplication.shared.connectedScenes.first
let sceneDelegate = (scene?.delegate as? SceneDelegate)
let window = sceneDelegate?.window
let rootViewController = window?.rootViewController
XCTAssertNotNil(
rootViewController as? LockedAppViewController,
"Should be a LockedAppViewController, got \(rootViewController)"
)

// WHEN
let lockedAppViewController = LockedAppViewController.instantiate()
lockedAppViewController.unlockApp()
// WHEN
let lockedAppViewController = LockedAppViewController.instantiate()
lockedAppViewController.unlockApp()

// THEN
guard let rootViewControllerRefresh = window?.rootViewController else {
XCTFail("Expecting a rootViewController")
return
}
// THEN
guard let rootViewControllerRefresh = window?.rootViewController else {
XCTFail("Expecting a rootViewController")
return
}

let lockView = rootViewControllerRefresh as? LockedAppViewController
XCTAssertNil(lockView, "no longer expecting a lock view, got \(lockView)")
}
*/
let lockView = rootViewControllerRefresh as? LockedAppViewController
XCTAssertNil(lockView, "no longer expecting a lock view, got \(lockView)")
}
}
254 changes: 126 additions & 128 deletions kDriveTests/kDrive/Launch/UTRootViewControllerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,134 +91,132 @@ final class UTRootViewControllerState: XCTestCase {
}
}

/* FIXME: broken DI
func testFirstLaunchState() throws {
// GIVEN empty accounts
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = true
let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}
func testOnboardingState() throws {
// GIVEN empty accounts
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false
let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}
func testOnboardingWithAppLockState() throws {
// GIVEN empty accounts BUT AppLock enabled
UserDefaults.shared.isAppLockEnabled = true
UserDefaults.shared.legacyIsFirstLaunch = false
let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}
func testAppLockState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = true
UserDefaults.shared.legacyIsFirstLaunch = false
let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
XCTAssertEqual(currentState, .appLock, "State should be applock, got \(currentState)")
}
func testNoDriveFileManagerState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false
let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}
func testMainViewControllerState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false
let accountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
accountManager.currentDriveFileManager = DriveFileManager(
drive: Drive(),
apiFetcher: DriveApiFetcher(token: self.fakeAccount.token, delegate: accountManager)
)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: accountManagerFactory)
@InjectService var accountManager: AccountManageable
XCTAssertNotNil(accountManager.currentAccount, "expecting a user logged in")
// WHEN
let currentState = RootViewControllerState.getCurrentState()
// THEN
switch currentState {
case .preloading(let account):
XCTAssertEqual(account.id, fakeAccount.userId)
default:
XCTFail("Should be preloading \(fakeAccount), got \(currentState)")
}
}
*/
func testFirstLaunchState() throws {
// GIVEN empty accounts
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = true

let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}

func testOnboardingState() throws {
// GIVEN empty accounts
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false

let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}

func testOnboardingWithAppLockState() throws {
// GIVEN empty accounts BUT AppLock enabled
UserDefaults.shared.isAppLockEnabled = true
UserDefaults.shared.legacyIsFirstLaunch = false

let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}

func testAppLockState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = true
UserDefaults.shared.legacyIsFirstLaunch = false

let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
XCTAssertEqual(currentState, .appLock, "State should be applock, got \(currentState)")
}

func testNoDriveFileManagerState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false

let emptyAccountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: emptyAccountManagerFactory)

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
XCTAssertEqual(currentState, .onboarding, "State should be onboarding")
}

func testMainViewControllerState() throws {
// GIVEN
UserDefaults.shared.isAppLockEnabled = false
UserDefaults.shared.legacyIsFirstLaunch = false

let accountManagerFactory = Factory(type: AccountManageable.self) { _, _ in
let accountManager = MockAccountManager()
accountManager.accounts.append(self.fakeAccount)
accountManager.currentAccount = self.fakeAccount
accountManager.currentUserId = self.fakeAccount.userId
accountManager.currentDriveFileManager = DriveFileManager(
drive: Drive(),
apiFetcher: DriveApiFetcher(token: self.fakeAccount.token, delegate: accountManager)
)
return accountManager
}
SimpleResolver.sharedResolver.store(factory: accountManagerFactory)

@InjectService var accountManager: AccountManageable
XCTAssertNotNil(accountManager.currentAccount, "expecting a user logged in")

// WHEN
let currentState = RootViewControllerState.getCurrentState()

// THEN
switch currentState {
case .preloading(let account):
XCTAssertEqual(account.id, fakeAccount.userId)
default:
XCTFail("Should be preloading \(fakeAccount), got \(currentState)")
}
}
}

extension RootViewControllerState: Equatable {
Expand Down

0 comments on commit d8d1eb0

Please sign in to comment.