From b57129c4f3725d401caa728ae97e80a0abc030af Mon Sep 17 00:00:00 2001 From: Felix Schmidt Date: Sun, 12 Mar 2023 09:29:43 +0100 Subject: [PATCH 1/4] 14909: Hibernation Start Date can be set freely. --- .../CWAHibernationProvider.swift | 26 ++++++++---- .../CWAHibernationProviderTests.swift | 42 ++++++------------- .../DMHibernationOptionsViewController.swift | 4 +- .../DMHibernationOptionsViewModel.swift | 37 ++++++++-------- .../__tests__/Mocks/MockTestStore.swift | 2 +- .../Source/Workers/Store/SecureStore.swift | 6 +-- .../ENA/ENA/Source/Workers/Store/Store.swift | 2 +- 7 files changed, 58 insertions(+), 61 deletions(-) diff --git a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift index ef54efa8ddc..17db49a9910 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,28 @@ 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 DEBUG + Log.debug("current hibernationStartDate \(String(describing: secureStore.hibernationStartDate))") + return secureStore.hibernationStartDate ?? hibernationStartDateDefault + + #elseif !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..7e72fb9a272 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,16 @@ 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: + if let customHibernationStartDate = store.hibernationStartDate { + return "App will shutdown after selecting a new date.\nCurrently the (custom) hibernation starts on: \(dateFormatter.string(from: customHibernationStartDate))" + } else { + return "App will shutdown after selecting a new date.\nCurrently the (default) hibernation starts on: \(dateFormatter.string(from: CWAHibernationProvider.shared.hibernationStartDateForBuild))" + } case .storeButton: return nil case .reset: - return "App will shutdown after reseting to today's date." + return "App will shutdown after reset." } } @@ -46,29 +48,29 @@ class DMHibernationOptionsViewModel { } switch section { - case .hibernationComparisonDate: + case .hibernationStartDate: return DMDatePickerCellViewModel( title: "Hibernation Comparison 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) } } } @@ -83,9 +85,10 @@ class DMHibernationOptionsViewModel { 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 saved.") exitApp() } @@ -100,7 +103,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 From 0bbbe5f81d44dcd78b237df35fb84882905abe92 Mon Sep 17 00:00:00 2001 From: Felix Schmidt Date: Sun, 12 Mar 2023 09:49:06 +0100 Subject: [PATCH 2/4] 14909: Choose some better understandable texts. --- .../DMHibernationOptionsViewModel.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 7e72fb9a272..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 @@ -30,15 +30,11 @@ class DMHibernationOptionsViewModel { switch section { case .hibernationStartDate: - if let customHibernationStartDate = store.hibernationStartDate { - return "App will shutdown after selecting a new date.\nCurrently the (custom) hibernation starts on: \(dateFormatter.string(from: customHibernationStartDate))" - } else { - return "App will shutdown after selecting a new date.\nCurrently the (default) hibernation starts on: \(dateFormatter.string(from: CWAHibernationProvider.shared.hibernationStartDateForBuild))" - } + 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 reset." + return "App will exit after reset." } } @@ -50,7 +46,7 @@ class DMHibernationOptionsViewModel { switch section { case .hibernationStartDate: return DMDatePickerCellViewModel( - title: "Hibernation Comparison Date", + title: "Hibernation Start Date", accessibilityIdentifier: AccessibilityIdentifiers.DeveloperMenu.Hibernation.datePicker, datePickerMode: .dateAndTime, date: CWAHibernationProvider.shared.hibernationStartDateForBuild @@ -81,14 +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(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 saved.") + Log.debug("[Debug-Menu] Set hibernation start done.") exitApp() } From a4e72682cc5f6a3441530576fc7703dd24c649df Mon Sep 17 00:00:00 2001 From: Felix Schmidt Date: Mon, 13 Mar 2023 10:03:56 +0100 Subject: [PATCH 3/4] Update src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift Co-authored-by: Omar Ahmed --- .../AppDelegate & Globals/CWAHibernationProvider.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift index 17db49a9910..9281e8b8972 100644 --- a/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift +++ b/src/xcode/ENA/ENA/Source/AppDelegate & Globals/CWAHibernationProvider.swift @@ -50,11 +50,7 @@ class CWAHibernationProvider: RequiresAppDependencies { /// CWA hibernation threshold date. var hibernationStartDateForBuild: Date { - #if DEBUG - Log.debug("current hibernationStartDate \(String(describing: secureStore.hibernationStartDate))") - return secureStore.hibernationStartDate ?? hibernationStartDateDefault - - #elseif !RELEASE + #if !RELEASE Log.debug("current hibernationStartDate \(String(describing: secureStore.hibernationStartDate))") return secureStore.hibernationStartDate ?? hibernationStartDateDefault From 687210a49517b979bbe3c1e64d2b6d58605f70a0 Mon Sep 17 00:00:00 2001 From: Omar Ahmed Date: Mon, 13 Mar 2023 11:56:40 +0100 Subject: [PATCH 4/4] fix accessability --- src/xcode/ENA/ENAUITests/Home/ENAUITests_01a_Home.swift | 2 +- .../ENA/ENAUITests/Onboarding/ENAUITests_00_Onboarding.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 {