From 121be86ad9e60d1da2229d6d15f154db512cee4d Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Wed, 20 Dec 2023 13:37:43 +0100 Subject: [PATCH 1/4] fix: Provide restorationIdentifier for MainTabViewController children Signed-off-by: Philippe Weidmann --- .../UI/Controller/Files/File List/FileListViewController.swift | 1 + kDrive/UI/Controller/MainTabViewController.swift | 3 +++ 2 files changed, 4 insertions(+) diff --git a/kDrive/UI/Controller/Files/File List/FileListViewController.swift b/kDrive/UI/Controller/Files/File List/FileListViewController.swift index eab5b9943..aeaf3bceb 100644 --- a/kDrive/UI/Controller/Files/File List/FileListViewController.swift +++ b/kDrive/UI/Controller/Files/File List/FileListViewController.swift @@ -229,6 +229,7 @@ class FileListViewController: UIViewController, UICollectionViewDataSource, Swip navigationController?.setInfomaniakAppearanceNavigationBar() + guard viewModel != nil else { return } #if !ISEXTENSION let plusButtonDirectory: File if viewModel.currentDirectory.id >= DriveFileManager.constants.rootID { diff --git a/kDrive/UI/Controller/MainTabViewController.swift b/kDrive/UI/Controller/MainTabViewController.swift index 949f44f18..e74857a7b 100644 --- a/kDrive/UI/Controller/MainTabViewController.swift +++ b/kDrive/UI/Controller/MainTabViewController.swift @@ -101,6 +101,7 @@ class MainTabViewController: UITabBarController, Restorable { let homeViewController = HomeViewController(driveFileManager: driveFileManager) let navigationViewController = TitleSizeAdjustingNavigationController(rootViewController: homeViewController) navigationViewController.navigationBar.prefersLargeTitles = true + navigationViewController.restorationIdentifier = String(describing: HomeViewController.self) navigationViewController.tabBarItem.accessibilityLabel = KDriveResourcesStrings.Localizable.homeTitle navigationViewController.tabBarItem.image = KDriveResourcesAsset.house.image navigationViewController.tabBarItem.selectedImage = KDriveResourcesAsset.houseFill.image @@ -111,6 +112,7 @@ class MainTabViewController: UITabBarController, Restorable { let menuViewController = MenuViewController(driveFileManager: driveFileManager) let navigationViewController = TitleSizeAdjustingNavigationController(rootViewController: menuViewController) let (placeholder, placeholderSelected) = generateProfileTabImages(image: KDriveResourcesAsset.placeholderAvatar.image) + navigationViewController.restorationIdentifier = String(describing: MenuViewController.self) navigationViewController.tabBarItem.accessibilityLabel = KDriveResourcesStrings.Localizable.menuTitle navigationViewController.tabBarItem.image = placeholder navigationViewController.tabBarItem.selectedImage = placeholderSelected @@ -120,6 +122,7 @@ class MainTabViewController: UITabBarController, Restorable { private static func initRootViewController(with viewModel: FileListViewModel) -> UIViewController { let fileListViewController = FileListViewController.instantiate(viewModel: viewModel) let navigationViewController = TitleSizeAdjustingNavigationController(rootViewController: fileListViewController) + navigationViewController.restorationIdentifier = String(describing: type(of: viewModel)) navigationViewController.navigationBar.prefersLargeTitles = true navigationViewController.tabBarItem.accessibilityLabel = viewModel.title navigationViewController.tabBarItem.image = viewModel.configuration.tabBarIcon.image From 7b7c77e2abc32d5c39f5399bd4034c273c9a9dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Thu, 21 Dec 2023 17:14:18 +0100 Subject: [PATCH 2/4] test: Added TEST flag to test targets --- Project.swift | 7 ++++--- Tuist/ProjectDescriptionHelpers/Constants.swift | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Project.swift b/Project.swift index 9ef375f3f..ace4d926c 100644 --- a/Project.swift +++ b/Project.swift @@ -102,7 +102,7 @@ let project = Project(name: "kDrive", dependencies: [ .target(name: "kDrive") ], - settings: .settings(base: Constants.baseSettings)), + settings: .settings(base: Constants.testSettings)), Target(name: "kDriveAPITests", platform: .iOS, product: .unitTests, @@ -116,7 +116,7 @@ let project = Project(name: "kDrive", dependencies: [ .target(name: "kDrive") ], - settings: .settings(base: Constants.baseSettings)), + settings: .settings(base: Constants.testSettings)), Target(name: "kDriveUITests", platform: .iOS, product: .uiTests, @@ -127,7 +127,8 @@ let project = Project(name: "kDrive", dependencies: [ .target(name: "kDrive"), .target(name: "kDriveCore") - ]), + ], + settings: .settings(base: Constants.testSettings)), Target(name: "kDriveResources", platform: .iOS, product: .staticLibrary, diff --git a/Tuist/ProjectDescriptionHelpers/Constants.swift b/Tuist/ProjectDescriptionHelpers/Constants.swift index 4f6287338..03fa9ef76 100644 --- a/Tuist/ProjectDescriptionHelpers/Constants.swift +++ b/Tuist/ProjectDescriptionHelpers/Constants.swift @@ -19,6 +19,10 @@ import ProjectDescription public enum Constants { + public static let testSettings: [String: SettingValue] = [ + "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "TEST DEBUG" + ] + public static let baseSettings = SettingsDictionary() .automaticCodeSigning(devTeam: "864VDCS2QY") .currentProjectVersion("1") From 893ade696c5d9ad9b85844c310cb5bc801bc2655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Thu, 21 Dec 2023 17:26:56 +0100 Subject: [PATCH 3/4] feat: Making use of the TEST flag --- .../UI/Controller/Files/File List/FileListViewModel.swift | 2 +- kDrive/Utils/MatomoUtils.swift | 2 +- kDriveCore/Utils/Logging.swift | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kDrive/UI/Controller/Files/File List/FileListViewModel.swift b/kDrive/UI/Controller/Files/File List/FileListViewModel.swift index 2fc9a987a..87493bc21 100644 --- a/kDrive/UI/Controller/Files/File List/FileListViewModel.swift +++ b/kDrive/UI/Controller/Files/File List/FileListViewModel.swift @@ -107,7 +107,7 @@ class FileListViewModel: SelectDelegate { /// Internal realm collection of Files observed /// /// They should be frozen by convention. - #if DEBUG + #if DEBUG || TEST var _frozenFiles = AnyRealmCollection(List()) { willSet { for item in newValue { diff --git a/kDrive/Utils/MatomoUtils.swift b/kDrive/Utils/MatomoUtils.swift index 1738649f0..2e938f792 100644 --- a/kDrive/Utils/MatomoUtils.swift +++ b/kDrive/Utils/MatomoUtils.swift @@ -24,7 +24,7 @@ import MatomoTracker class MatomoUtils { static let shared: MatomoTracker = { let tracker = MatomoTracker(siteId: "8", baseURL: URLConstants.matomo.url) - #if DEBUG + #if DEBUG || TEST tracker.isOptedOut = true #endif @InjectService var accountManager: AccountManageable diff --git a/kDriveCore/Utils/Logging.swift b/kDriveCore/Utils/Logging.swift index 22182f4cd..154723450 100644 --- a/kDriveCore/Utils/Logging.swift +++ b/kDriveCore/Utils/Logging.swift @@ -50,7 +50,7 @@ public enum Logging { ] SentryDebug.capture(error: error, context: context, contextKey: "Realm") - #if DEBUG + #if DEBUG && !TEST copyDebugInformations() DDLogError( "Realm files \(realmConfiguration.fileURL?.lastPathComponent ?? "") will be deleted to prevent migration error for next launch" @@ -79,7 +79,7 @@ public enum Logging { } private static func initNetworkLogging() { - #if DEBUG + #if DEBUG && !TEST if !Bundle.main.isExtension { // Atlantis.start(hostName: ProcessInfo.processInfo.environment["hostname"]) } @@ -95,7 +95,7 @@ public enum Logging { "AppLock enabled": UserDefaults.shared.isAppLockEnabled, "Wifi only enabled": UserDefaults.shared.isWifiOnly ] - #if DEBUG + #if DEBUG || TEST return nil #else return event @@ -105,7 +105,7 @@ public enum Logging { } private static func copyDebugInformations() { - #if DEBUG + #if DEBUG && !TEST guard !Bundle.main.isExtension else { return } let fileManager = FileManager.default let debugDirectory = (fileManager.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent( From 86ab8ea12d310963f688005a274513361d10246c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Thu, 21 Dec 2023 17:27:26 +0100 Subject: [PATCH 4/4] feat: Testing that TEST flag is set in test targets --- kDriveCore/Utils/Logging.swift | 2 +- kDriveTestShared/TestsPreconditions.swift | 36 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 kDriveTestShared/TestsPreconditions.swift diff --git a/kDriveCore/Utils/Logging.swift b/kDriveCore/Utils/Logging.swift index 154723450..27fc422dc 100644 --- a/kDriveCore/Utils/Logging.swift +++ b/kDriveCore/Utils/Logging.swift @@ -81,7 +81,7 @@ public enum Logging { private static func initNetworkLogging() { #if DEBUG && !TEST if !Bundle.main.isExtension { -// Atlantis.start(hostName: ProcessInfo.processInfo.environment["hostname"]) + Atlantis.start(hostName: ProcessInfo.processInfo.environment["hostname"]) } #endif } diff --git a/kDriveTestShared/TestsPreconditions.swift b/kDriveTestShared/TestsPreconditions.swift new file mode 100644 index 000000000..be3dd9567 --- /dev/null +++ b/kDriveTestShared/TestsPreconditions.swift @@ -0,0 +1,36 @@ +/* + Infomaniak Mail - iOS App + Copyright (C) 2022 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import XCTest + +/// Sanity checks of SWIFT_ACTIVE_COMPILATION_CONDITIONS +final class TestsPreconditions: XCTestCase { + func testTestFlagIsSet() { + // WHEN + #if !TEST + XCTFail("the TEST flag is expected to be set in test target") + #endif + } + + func testDebugFlagIsSet() { + // WHEN + #if !DEBUG + XCTFail("the DEBUG flag is expected to be set in test target") + #endif + } +}