Browse Source

Fix theming tests.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
958562ee4c
  1. 12
      Clocker/ClockerUnitTests/ThemerTests.swift
  2. 14
      Clocker/Overall App/Themer.swift
  3. 5
      Clocker/Panel/Rate Controller/ReviewController.swift

12
Clocker/ClockerUnitTests/ThemerTests.swift

@ -101,7 +101,7 @@ class ThemerTests: XCTestCase {
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "ExtraWhite"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedMenubarOnboardingImage = "Dark Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraWhiteHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
@ -153,13 +153,13 @@ class ThemerTests: XCTestCase {
func testSystemTheme() throws {
let currentSystemTheme =
UserDefaults.standard.string(forKey: "AppleUserInterfaceStyle")?.lowercased().contains("dark") ?? false ? Themer.Theme.dark : Themer.Theme.light
UserDefaults.standard.string(forKey: "AppleInterfaceStyle")?.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
let expectedBackgroundColor = currentSystemTheme == .dark ? NSColor(deviceRed: 42.0 / 255.0, green: 42.0 / 255.0, blue: 42.0 / 255.0, alpha: 1.0) : NSColor.white
let expectedBackgroundColor = currentSystemTheme == .dark ? NSColor.windowBackgroundColor : NSColor.white
let expectedTextColor = NSColor.textColor
let expectedTextBackgroundColor = currentSystemTheme == .dark ? NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0) : NSColor(deviceRed: 241.0 / 255.0, green: 241.0 / 255.0, blue: 241.0 / 255.0, alpha: 1.0)
let expectedTextBackgroundColor = currentSystemTheme == .light ? NSColor(deviceRed: 42.0 / 255.0, green: 55.0 / 255.0, blue: 62.0 / 255.0, alpha: 1.0) : NSColor.controlBackgroundColor
let expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
@ -220,7 +220,7 @@ class ThemerTests: XCTestCase {
func testSolarizedLightTheme() throws {
let subject = Themer(index: 3) // 3 is for solarized light theme
let expectedSliderKnobColor = NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
let expectedSliderKnobColor = NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9)
let expectedSliderRightColor = NSColor.gray
let expectedBackgroundColor = NSColor(deviceRed: 253.0 / 255.0, green: 246.0 / 255.0, blue: 227.0 / 255.0, alpha: 1.0)
let expectedTextColor = NSColor.black
@ -299,7 +299,7 @@ class ThemerTests: XCTestCase {
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "ExtraWhite"
let expectedMenubarOnboardingImage = "Light Menubar"
let expectedMenubarOnboardingImage = "Dark Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraWhiteHighlighted"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"

14
Clocker/Overall App/Themer.swift

@ -95,12 +95,12 @@ extension Themer {
func sliderKnobColor() -> NSColor {
switch themeIndex {
case .light:
case .light, .solarizedLight:
return NSColor(deviceRed: 255.0, green: 255.0, blue: 255, alpha: 0.9)
case .dark, .solarizedDark:
return NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
case .system:
return retrieveCurrentSystem() == .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)
default:
return NSColor(deviceRed: 0.0, green: 0.0, blue: 0, alpha: 0.9)
}
}
@ -108,6 +108,8 @@ extension Themer {
switch themeIndex {
case .dark:
return NSColor.white
case .system:
return retrieveCurrentSystem() == .dark ? NSColor.white : NSColor.gray
default:
return NSColor.gray
}
@ -258,8 +260,10 @@ extension Themer {
switch themeIndex {
case .system:
return NSImage(named: NSImage.Name("Dynamic Menubar"))!
default:
return retrieveCurrentSystem() == .dark ? NSImage(named: NSImage.Name("Dark Menubar"))! : NSImage(named: NSImage.Name("Light Menubar"))!
case .light, .solarizedLight:
return NSImage(named: NSImage.Name("Light Menubar"))!
case .dark, .solarizedDark:
return NSImage(named: NSImage.Name("Dark Menubar"))!
}
}

5
Clocker/Panel/Rate Controller/ReviewController.swift

@ -5,7 +5,6 @@ import StoreKit
final class ReviewController {
private static var storage = UserDefaults.standard
private static let version: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "N/A"
private static var debugging = false
private enum Keys {
@ -32,7 +31,7 @@ final class ReviewController {
class func prompted() {
storage.set(Date(), forKey: Keys.lastPrompt)
storage.set(version, forKey: Keys.lastVersion)
storage.set(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String, forKey: Keys.lastVersion)
}
class func canPrompt() -> Bool {
@ -57,7 +56,7 @@ final class ReviewController {
let minInterval: TimeInterval = day * 90
// never prompt w/in the same version
return lastVersion != version
return lastVersion != (Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String)
// limit all types of prompts to at least 1mo intervals
&& lastPrompt.timeIntervalSinceNow < minInterval
}

Loading…
Cancel
Save