Browse Source

Make AppleInterfaceStyle key a constant.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
77c4d95546
  1. 36
      Clocker/ClockerUnitTests/ReviewControllerTests.swift
  2. 2
      Clocker/ClockerUnitTests/ThemerTests.swift
  3. 1
      Clocker/Overall App/Strings.swift
  4. 2
      Clocker/Overall App/Themer.swift

36
Clocker/ClockerUnitTests/ReviewControllerTests.swift

@ -53,6 +53,38 @@ class ReviewControllerTests: XCTestCase {
XCTAssertTrue(ReviewController.canPrompt()) 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() { func testPrompDisplayedAfterThreeMonths() {
let dateChunk = TimeChunk(seconds: 0, let dateChunk = TimeChunk(seconds: 0,
minutes: 0, minutes: 0,
@ -72,7 +104,7 @@ class ReviewControllerTests: XCTestCase {
years: 0) years: 0)
let lastPromptDate = Date().subtract(promptChunk) let lastPromptDate = Date().subtract(promptChunk)
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker3") else { guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else {
return return
} }
mockDefaults.set(minInstall, forKey: "install") mockDefaults.set(minInstall, forKey: "install")
@ -89,7 +121,7 @@ class ReviewControllerTests: XCTestCase {
} }
func testPrompted() { func testPrompted() {
guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker4") else { guard let mockDefaults = UserDefaults(suiteName: "com.test.Clocker5") else {
return return
} }
ReviewController.applicationDidLaunch(mockDefaults) ReviewController.applicationDidLaunch(mockDefaults)

2
Clocker/ClockerUnitTests/ThemerTests.swift

@ -122,7 +122,7 @@ class ThemerTests: XCTestCase {
func testSystemTheme() throws { func testSystemTheme() throws {
let currentSystemTheme = 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 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 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 let expectedSliderRightColor = currentSystemTheme == .dark ? NSColor.white : NSColor.gray

1
Clocker/Overall App/Strings.swift

@ -36,3 +36,4 @@ let CLDefaultMenubarMode = "com.abhishek.shouldDefaultToCompactMode"
let CLInstallHomeIndicatorObject = "installHomeIndicatorObject" let CLInstallHomeIndicatorObject = "installHomeIndicatorObject"
let CLSwitchToCompactModeAlert = "com.abhishek.switchToCompactMode" let CLSwitchToCompactModeAlert = "com.abhishek.switchToCompactMode"
let CLDisplayDSTTransitionInfo = "com.abhishek.showDSTTransitionInfo" let CLDisplayDSTTransitionInfo = "com.abhishek.showDSTTransitionInfo"
let CLAppleInterfaceStyleKey = "AppleInterfaceStyle"

2
Clocker/Overall App/Themer.swift

@ -431,7 +431,7 @@ extension Themer {
private func retrieveCurrentSystem() -> Theme { private func retrieveCurrentSystem() -> Theme {
if #available(OSX 10.14, *) { 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") { if appleInterfaceStyle.lowercased().contains("dark") {
return .dark return .dark
} }

Loading…
Cancel
Save