diff --git a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift index ef54efa8ddc..9281e8b8972 100644 --- a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift +++ b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift @@ -28,14 +28,11 @@ class CWAHibernationProvider: RequiresAppDependencies { if isUITesting { return LaunchArguments.endOfLife.isHibernationStateEnabled.boolValue } - return secureStore.hibernationComparisonDate >= hibernationStartDate - #else - return Date() >= hibernationStartDate #endif + return Date() >= hibernationStartDateForBuild } - /// CWA hibernation threshold date. - private let hibernationStartDate: Date = { + let hibernationStartDateDefault: Date = { var hibernationStartDateComponents = DateComponents() hibernationStartDateComponents.year = 2023 hibernationStartDateComponents.month = 5 @@ -44,13 +41,24 @@ class CWAHibernationProvider: RequiresAppDependencies { hibernationStartDateComponents.minute = 0 hibernationStartDateComponents.second = 0 - guard let hibernationStartDate = Calendar.current.date(from: hibernationStartDateComponents) else { + guard let hibernationStartDateDefault = Calendar.current.date(from: hibernationStartDateComponents) else { fatalError("The hibernation start date couldn't be created.") } - return hibernationStartDate + return hibernationStartDateDefault }() + /// CWA hibernation threshold date. + var hibernationStartDateForBuild: Date { + #if !RELEASE + Log.debug("current hibernationStartDate \(String(describing: secureStore.hibernationStartDate))") + return secureStore.hibernationStartDate ?? hibernationStartDateDefault + + #else + return hibernationStartDateDefault + #endif + } + private var secureStore: Store { #if RELEASE return store diff --git a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/__tests__/CWAHibernationProviderTests.swift b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/__tests__/CWAHibernationProviderTests.swift index 42ed3174a9e..7657078d246 100644 --- a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/__tests__/CWAHibernationProviderTests.swift +++ b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/__tests__/CWAHibernationProviderTests.swift @@ -7,49 +7,31 @@ import XCTest final class CWAHibernationProviderTests: CWATestCase { - func testIsHibernationState_Store_HibernationComparisonDate_before_false() throws { + func testIsHibernationState_HibernationStartDate_beforeSystemDate_true() throws { // GIVEN let mockTestStore = MockTestStore() let sut = CWAHibernationProvider(customStore: mockTestStore) + let today = Date() + let yesterday = today.addingTimeInterval(-86400) // 1 day in seconds // WHEN - var beforeHibernationStartDateComponents = DateComponents() - beforeHibernationStartDateComponents.year = 2023 - beforeHibernationStartDateComponents.month = 4 - beforeHibernationStartDateComponents.day = 30 - beforeHibernationStartDateComponents.hour = 23 - beforeHibernationStartDateComponents.minute = 59 - beforeHibernationStartDateComponents.second = 59 - - guard let hibernationComparisonDate = Calendar.current.date(from: beforeHibernationStartDateComponents) else { - return XCTFail("Expect the hibernation comparison date from the corresponding date components.") - } - mockTestStore.hibernationComparisonDate = hibernationComparisonDate + mockTestStore.hibernationStartDate = yesterday // THEN - XCTAssertFalse(sut.isHibernationState) + XCTAssertTrue(sut.isHibernationState) } - - func testIsHibernationState_Store_HibernationComparisonDate_after_true() throws { + + func testIsHibernationState_HibernationStartDate_afterSystemDate_false() throws { // GIVEN let mockTestStore = MockTestStore() let sut = CWAHibernationProvider(customStore: mockTestStore) + let today = Date() + let tomorrow = today.addingTimeInterval(86400) // 1 day in seconds // WHEN - var afterHibernationStartDateComponents = DateComponents() - afterHibernationStartDateComponents.year = 2023 - afterHibernationStartDateComponents.month = 5 - afterHibernationStartDateComponents.day = 1 - afterHibernationStartDateComponents.hour = 0 - afterHibernationStartDateComponents.minute = 0 - afterHibernationStartDateComponents.second = 0 - - guard let hibernationComparisonDate = Calendar.current.date(from: afterHibernationStartDateComponents) else { - return XCTFail("Expect the hibernation comparison date from the corresponding date components.") - } - mockTestStore.hibernationComparisonDate = hibernationComparisonDate + mockTestStore.hibernationStartDate = tomorrow // THEN - XCTAssertTrue(sut.isHibernationState) - } + XCTAssertFalse(sut.isHibernationState) + } } diff --git a/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewController.swift b/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewController.swift index 3b11933d956..e53676087be 100644 --- a/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewController.swift +++ b/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewController.swift @@ -83,8 +83,8 @@ class DMHibernationOptionsViewController: UITableViewController { let cell = tableView.dequeueReusableCell(cellType: DMDatePickerTableViewCell.self, for: indexPath) cell.configure(cellViewModel: cellViewModel) - cell.didSelectDate = { [weak self] hibernationComparisonDateSelected in - self?.viewModel.hibernationComparisonDateSelected = hibernationComparisonDateSelected + cell.didSelectDate = { [weak self] customHibernationStartDateSelected in + self?.viewModel.customHibernationStartDateSelected = customHibernationStartDateSelected } return cell diff --git a/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewModel.swift b/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewModel.swift index 3ac1498dbce..f4362e09c32 100644 --- a/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewModel.swift +++ b/src/xcode/ENA/ENA/Source/Developer Menu/Features/DMHibernation/DMHibernationOptionsViewModel.swift @@ -12,12 +12,12 @@ class DMHibernationOptionsViewModel { init(store: Store) { self.store = store - self.hibernationComparisonDateSelected = store.hibernationComparisonDate + self.customHibernationStartDateSelected = CWAHibernationProvider.shared.hibernationStartDateForBuild } // MARK: - Internal - var hibernationComparisonDateSelected: Date + var customHibernationStartDateSelected: Date var numberOfSections: Int { Sections.allCases.count } @@ -29,14 +29,12 @@ class DMHibernationOptionsViewModel { } switch section { - case .hibernationComparisonDate: - var title = "App will shutdown after selecting a new date value in the date picker. Currently the hibernation threshold compares against the set date: \(dateFormatter.string(from: store.hibernationComparisonDate))" - - return title + case .hibernationStartDate: + return "You can select a custom start here for testing. At the moment, the hibernation starts on \(dateFormatter.string(from: customHibernationStartDateSelected))." case .storeButton: - return nil + return "App will exit after saving." case .reset: - return "App will shutdown after reseting to today's date." + return "App will exit after reset." } } @@ -46,29 +44,29 @@ class DMHibernationOptionsViewModel { } switch section { - case .hibernationComparisonDate: + case .hibernationStartDate: return DMDatePickerCellViewModel( - title: "Hibernation Comparison Date", + title: "Hibernation Start Date", accessibilityIdentifier: AccessibilityIdentifiers.DeveloperMenu.Hibernation.datePicker, datePickerMode: .dateAndTime, - date: store.hibernationComparisonDate + date: CWAHibernationProvider.shared.hibernationStartDateForBuild ) case .storeButton: return DMButtonCellViewModel( - text: "Save Comparison Date", + text: "Save Custom Start Date", textColor: .white, backgroundColor: .enaColor(for: .buttonPrimary) ) { [weak self] in guard let self = self else { return } - self.store(hibernationComparisonDate: self.hibernationComparisonDateSelected) + self.store(hibernationStartDate: self.customHibernationStartDateSelected) } case .reset: return DMButtonCellViewModel( - text: "Reset Comparison Date", + text: "Reset", textColor: .white, backgroundColor: .enaColor(for: .buttonDestructive) ) { [weak self] in - self?.store(hibernationComparisonDate: Date()) + self?.store(hibernationStartDate: CWAHibernationProvider.shared.hibernationStartDateDefault) } } } @@ -79,13 +77,14 @@ class DMHibernationOptionsViewModel { private let dateFormatter: DateFormatter = { let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd, HH:mm" + dateFormatter.dateFormat = "dd.MM.yyyy, HH:mm" return dateFormatter }() - private func store(hibernationComparisonDate: Date) { - Log.debug("[Debug-Menu] Set hibernation comparison date to: \(dateFormatter.string(from: hibernationComparisonDate)).") - store.hibernationComparisonDate = hibernationComparisonDate + private func store(hibernationStartDate: Date) { + Log.debug("[Debug-Menu] Set hibernation start date to: \(dateFormatter.string(from: hibernationStartDate)).") + store.hibernationStartDate = hibernationStartDate + Log.debug("[Debug-Menu] Set hibernation start done.") exitApp() } @@ -100,7 +99,7 @@ class DMHibernationOptionsViewModel { extension DMHibernationOptionsViewModel { enum Sections: Int, CaseIterable { /// The date, that will be used to compare it against the hibernation start date. - case hibernationComparisonDate + case hibernationStartDate /// Store the set hibernation comparison date case storeButton /// Reset the stored fake date, the hibernation threshold compares to. diff --git a/src/xcode/ENA/ENA/Source/Services/__tests__/Mocks/MockTestStore.swift b/src/xcode/ENA/ENA/Source/Services/__tests__/Mocks/MockTestStore.swift index 8b7dcea598b..9b178d68fd9 100644 --- a/src/xcode/ENA/ENA/Source/Services/__tests__/Mocks/MockTestStore.swift +++ b/src/xcode/ENA/ENA/Source/Services/__tests__/Mocks/MockTestStore.swift @@ -63,7 +63,7 @@ final class MockTestStore: Store, PPAnalyticsData { var forceAPITokenAuthorization = false var recentTraceLocationCheckedInto: DMRecentTraceLocationCheckedInto? var isSrsPrechecksEnabled = false - var hibernationComparisonDate = Date() + var hibernationStartDate: Date? #endif // MARK: - AppConfigCaching diff --git a/src/xcode/ENA/ENA/Source/Workers/Store/SecureStore.swift b/src/xcode/ENA/ENA/Source/Workers/Store/SecureStore.swift index efdb0073791..14e6bd1a778 100644 --- a/src/xcode/ENA/ENA/Source/Workers/Store/SecureStore.swift +++ b/src/xcode/ENA/ENA/Source/Workers/Store/SecureStore.swift @@ -378,9 +378,9 @@ final class SecureStore: SecureKeyValueStoring, Store { set { kvStore["recentTraceLocationCheckedInto"] = newValue } } - var hibernationComparisonDate: Date { - get { kvStore["hibernationComparisonDate"] as Date? ?? Date() } - set { kvStore["hibernationComparisonDate"] = newValue } + var hibernationStartDate: Date? { + get { kvStore["hibernationStartDate"] as Date? } + set { kvStore["hibernationStartDate"] = newValue } } #endif diff --git a/src/xcode/ENA/ENA/Source/Workers/Store/Store.swift b/src/xcode/ENA/ENA/Source/Workers/Store/Store.swift index 275c0376d81..3eab2f2fc38 100644 --- a/src/xcode/ENA/ENA/Source/Workers/Store/Store.swift +++ b/src/xcode/ENA/ENA/Source/Workers/Store/Store.swift @@ -87,7 +87,7 @@ protocol StoreProtocol: AnyObject { var recentTraceLocationCheckedInto: DMRecentTraceLocationCheckedInto? { get set } - var hibernationComparisonDate: Date { get set } + var hibernationStartDate: Date? { get set } #endif diff --git a/src/xcode/ENA/ENAUITests/Home/ENAUITests_01a_Home.swift b/src/xcode/ENA/ENAUITests/Home/ENAUITests_01a_Home.swift index b059422ec17..9d1f8761f4d 100644 --- a/src/xcode/ENA/ENAUITests/Home/ENAUITests_01a_Home.swift +++ b/src/xcode/ENA/ENAUITests/Home/ENAUITests_01a_Home.swift @@ -276,7 +276,7 @@ class ENAUITests_01a_Home: CWATestCase { app.setLaunchArgument(LaunchArguments.endOfLife.isHibernationStateEnabled, to: true) app.launch() - XCTAssertTrue(app.staticTexts[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.descriptionLabel].waitForExistence(timeout: .medium)) + XCTAssertTrue(app.textViews[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.descriptionLabel].waitForExistence(timeout: .medium)) XCTAssertTrue(app.images[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.image].waitForExistence(timeout: .medium)) XCTAssertTrue(app.staticTexts[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.titleLabel].waitForExistence(timeout: .medium)) } diff --git a/src/xcode/ENA/ENAUITests/Onboarding/ENAUITests_00_Onboarding.swift b/src/xcode/ENA/ENAUITests/Onboarding/ENAUITests_00_Onboarding.swift index 063dc2a79ff..40dcb4c3ed6 100644 --- a/src/xcode/ENA/ENAUITests/Onboarding/ENAUITests_00_Onboarding.swift +++ b/src/xcode/ENA/ENAUITests/Onboarding/ENAUITests_00_Onboarding.swift @@ -33,7 +33,7 @@ class ENAUITests_00_Onboarding: CWATestCase { app.buttons["AppStrings.Onboarding.onboardingContinue"].waitAndTap() // check that the homescreen element AppStrings.home.activateTitle is visible onscreen - XCTAssertTrue(app.staticTexts[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.descriptionLabel].waitForExistence(timeout: .medium)) + XCTAssertTrue(app.textViews[AccessibilityIdentifiers.Home.EndOfLifeThankYouCell.descriptionLabel].waitForExistence(timeout: .medium)) } func test_0000_OnboardingFlow_DisablePermissions_normal_XXXL() throws {