diff --git a/Clocker/ClockerUnitTests/ReviewControllerTests.swift b/Clocker/ClockerUnitTests/ReviewControllerTests.swift index fc1755e..ab03218 100644 --- a/Clocker/ClockerUnitTests/ReviewControllerTests.swift +++ b/Clocker/ClockerUnitTests/ReviewControllerTests.swift @@ -53,6 +53,38 @@ class ReviewControllerTests: XCTestCase { XCTAssertTrue(ReviewController.canPrompt()) } + func testPromptDisplayAfterTwoMonths() { + let dateChunk = TimeChunk(seconds: 0, + minutes: 0, + hours: 0, + days: 68, + weeks: 0, + months: 0, + years: 0) + let minInstall = Date().subtract(dateChunk) + + let promptChunk = TimeChunk(seconds: 0, + minutes: 0, + hours: 0, + days: 60, + weeks: 0, + months: 0, + years: 0) + let lastPromptDate = Date().subtract(promptChunk) + + guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker3") else { + return + } + mockDefaults.set(minInstall, forKey: "install") + mockDefaults.set("test-version", forKey: "last-version") + mockDefaults.set(lastPromptDate, forKey: "last-prompt") + ReviewController.applicationDidLaunch(mockDefaults) + + // Explicitly set preview mode to false + ReviewController.setPreviewMode(false) + XCTAssertFalse(ReviewController.canPrompt()) + } + func testPrompDisplayedAfterThreeMonths() { let dateChunk = TimeChunk(seconds: 0, minutes: 0, @@ -72,7 +104,7 @@ class ReviewControllerTests: XCTestCase { years: 0) let lastPromptDate = Date().subtract(promptChunk) - guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker3") else { + guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else { return } mockDefaults.set(minInstall, forKey: "install") @@ -89,7 +121,7 @@ class ReviewControllerTests: XCTestCase { } func testPrompted() { - guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else { + guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker5") else { return } ReviewController.applicationDidLaunch(mockDefaults) diff --git a/Clocker/ClockerUnitTests/ThemerTests.swift b/Clocker/ClockerUnitTests/ThemerTests.swift index b295f4d..25c5574 100644 --- a/Clocker/ClockerUnitTests/ThemerTests.swift +++ b/Clocker/ClockerUnitTests/ThemerTests.swift @@ -122,7 +122,7 @@ class ThemerTests: XCTestCase { func testSystemTheme() throws { let currentSystemTheme = - UserDefaults.standard.string(forKey: "AppleInterfaceStyle")?.lowercased().contains("dark") ?? false ? Themer.Theme.dark : Themer.Theme.light + UserDefaults.standard.string(forKey: CLAppleInterfaceStyleKey)?.lowercased().contains("dark") ?? false ? Themer.Theme.dark : Themer.Theme.light let subject = Themer(index: 2) // 2 is for system theme let expectedSliderKnobColor = currentSystemTheme == .light ? NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9) : NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9) let expectedSliderRightColor = currentSystemTheme == .dark ? NSColor.white : NSColor.gray diff --git a/Clocker/Overall App/Strings.swift b/Clocker/Overall App/Strings.swift index f7edaff..e9fa746 100644 --- a/Clocker/Overall App/Strings.swift +++ b/Clocker/Overall App/Strings.swift @@ -36,3 +36,4 @@ let CLDefaultMenubarMode = "com.abhishek.shouldDefaultToCompactMode" let CLInstallHomeIndicatorObject = "installHomeIndicatorObject" let CLSwitchToCompactModeAlert = "com.abhishek.switchToCompactMode" let CLDisplayDSTTransitionInfo = "com.abhishek.showDSTTransitionInfo" +let CLAppleInterfaceStyleKey = "AppleInterfaceStyle" diff --git a/Clocker/Overall App/Themer.swift b/Clocker/Overall App/Themer.swift index c478d53..acc9221 100644 --- a/Clocker/Overall App/Themer.swift +++ b/Clocker/Overall App/Themer.swift @@ -431,7 +431,7 @@ extension Themer { private func retrieveCurrentSystem() -> Theme { if #available(OSX 10.14, *) { - if let appleInterfaceStyle = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") as? String { + if let appleInterfaceStyle = UserDefaults.standard.object(forKey: CLAppleInterfaceStyleKey) as? String { if appleInterfaceStyle.lowercased().contains("dark") { return .dark }