Browse Source

More themer tests.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
b18baa62d3
  1. 74
      Clocker/ClockerUnitTests/ThemerTests.swift
  2. 25
      Clocker/Overall App/Themer.swift

74
Clocker/ClockerUnitTests/ThemerTests.swift

@ -8,7 +8,8 @@ class ThemerTests: XCTestCase {
@available(macOS 10.14, *)
func testSettingTheme() {
let subject = Themer(index: 0)
// Set to some random number should set to 0
let subject = Themer(index: 124)
XCTAssertEqual(NSAppearance(named: .aqua), NSAppearance(named: .aqua))
// Set the same theme; this should return early
@ -152,7 +153,76 @@ class ThemerTests: XCTestCase {
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
XCTAssertEqual(subject.description, "Current Theme is \(Theme.dark)")
XCTAssertEqual(subject.description, "Current Theme is \(Themer.Theme.dark)")
}
func testSystemTheme() throws {
let currentSystemTheme =
UserDefaults.standard.string(forKey: "AppleUserInterfaceStyle")?.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 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 expectedShutdownImageName = "ellipsis.circle"
let expectedPreferenceImageName = "plus"
let expectedPinImageName = "macwindow.on.rectangle"
let expectedSunriseImageName = "sunrise.fill"
let expectedSunsetImageName = "sunset.fill"
let expectedRemoveImageName = "xmark"
let expectedExtraOptionsImage = "Extra Dynamic"
let expectedMenubarOnboardingImage = "Dynamic Menubar"
let expectedExtraOptionsHighlightedImage = "ExtraHighlighted Dynamic"
let expectedSharingImage = "square.and.arrow.up.on.square.fill"
let expectedCurrentLocationImage = "location.fill"
let expectedPopoverApperarance = NSAppearance.current
let expectedAddImage = "plus"
let expectedAddImageHighlighted = "Add White"
let expectedPrivacyTabImage = "lock"
let expectedAppearanceTabImage = "eye"
let expectedCalendarTabImage = "calendar"
let expectedGeneralTabImage = "gearshape"
let expectedAboutTabImage = "info.circle"
let expectedVideoCallImage = "video.circle.fill"
let expectedFilledTrashImage = "trash.fill"
let expectedBackwardsImage = "gobackward.15"
let expectedForwardsImage = "goforward.15"
let expectedResetSliderImage = "xmark.circle.fill"
XCTAssertEqual(subject.sliderKnobColor(), expectedSliderKnobColor)
XCTAssertEqual(subject.sliderRightColor(), expectedSliderRightColor)
XCTAssertEqual(subject.mainBackgroundColor(), expectedBackgroundColor)
XCTAssertEqual(subject.mainTextColor(), expectedTextColor)
XCTAssertEqual(subject.textBackgroundColor(), expectedTextBackgroundColor)
XCTAssertEqual(subject.shutdownImage().accessibilityDescription, expectedShutdownImageName)
XCTAssertEqual(subject.preferenceImage().accessibilityDescription, expectedPreferenceImageName)
XCTAssertEqual(subject.pinImage().accessibilityDescription, expectedPinImageName)
XCTAssertEqual(subject.sunriseImage().accessibilityDescription, expectedSunriseImageName)
XCTAssertEqual(subject.sunsetImage().accessibilityDescription, expectedSunsetImageName)
XCTAssertEqual(subject.removeImage().accessibilityDescription, expectedRemoveImageName)
XCTAssertEqual(subject.extraOptionsImage().name(), expectedExtraOptionsImage)
XCTAssertEqual(subject.menubarOnboardingImage().name(), expectedMenubarOnboardingImage)
XCTAssertEqual(subject.extraOptionsHighlightedImage().name(), expectedExtraOptionsHighlightedImage)
XCTAssertEqual(subject.sharingImage().accessibilityDescription, expectedSharingImage)
XCTAssertEqual(subject.currentLocationImage().accessibilityDescription, expectedCurrentLocationImage)
XCTAssertEqual(subject.popoverAppearance(), expectedPopoverApperarance)
XCTAssertEqual(subject.addImage().accessibilityDescription, expectedAddImage)
XCTAssertEqual(subject.addImageHighlighted().name(), expectedAddImageHighlighted)
XCTAssertEqual(subject.privacyTabImage().accessibilityDescription, expectedPrivacyTabImage)
XCTAssertEqual(subject.appearanceTabImage().accessibilityDescription, expectedAppearanceTabImage)
XCTAssertEqual(subject.calendarTabImage().accessibilityDescription, expectedCalendarTabImage)
XCTAssertEqual(subject.generalTabImage()?.accessibilityDescription, expectedGeneralTabImage)
XCTAssertEqual(subject.aboutTabImage()?.accessibilityDescription, expectedAboutTabImage)
XCTAssertEqual(subject.videoCallImage()?.accessibilityDescription, expectedVideoCallImage)
XCTAssertEqual(subject.filledTrashImage()?.accessibilityDescription, expectedFilledTrashImage)
XCTAssertEqual(subject.goBackwardsImage()?.accessibilityDescription, expectedBackwardsImage)
XCTAssertEqual(subject.goForwardsImage()?.accessibilityDescription, expectedForwardsImage)
XCTAssertEqual(subject.resetModernSliderImage()?.accessibilityDescription, expectedResetSliderImage)
XCTAssertEqual(subject.description, "System Theme is \(currentSystemTheme == .dark ? Themer.Theme.dark : Themer.Theme.light)")
}
func testSolarizedLightTheme() throws {

25
Clocker/Overall App/Themer.swift

@ -6,18 +6,17 @@ extension Notification.Name {
static let themeDidChangeNotification = Notification.Name(rawValue: "ThemeDidChangeNotification")
}
enum Theme: Int {
class Themer: NSObject {
// Adding a new theme should automatically cause the compiler to complain asking to make the switches in this class to be more exhaustive
enum Theme: Int {
case light = 0
case dark
case system
case solarizedLight
case solarizedDark
}
class Themer: NSObject {
}
private static var sharedInstance = Themer(index: UserDefaults.standard.integer(forKey: CLThemeKey))
private var effectiveApperanceObserver: NSKeyValueObservation?
private var themeIndex: Theme {
didSet {
NotificationCenter.default.post(name: .themeDidChangeNotification, object: nil)
@ -96,11 +95,23 @@ extension Themer {
//MARK: Color
func sliderKnobColor() -> NSColor {
return themeIndex == .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)
switch themeIndex {
case .light:
return NSColor(deviceRed: 255.0, green: 255.0, blue: 255, 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)
}
}
func sliderRightColor() -> NSColor {
return themeIndex == .dark ? NSColor.white : NSColor.gray
switch themeIndex {
case .dark:
return NSColor.white
default:
return NSColor.gray
}
}
func mainBackgroundColor() -> NSColor {

Loading…
Cancel
Save