Browse Source

Fix unit tests + change key name.

pull/92/head
Abhishek 4 years ago
parent
commit
4329460635
  1. 109
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  2. 2
      Clocker/Overall App/AppDefaults.swift
  3. 4
      Clocker/Overall App/DataStore.swift
  4. 2
      Clocker/Overall App/Strings.swift
  5. 2
      Clocker/Preferences/Appearance/AppearanceViewController.swift

109
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -72,8 +72,7 @@ class ClockerUnitTests: XCTestCase {
func testOverridingSecondsComponent_shouldHideSeconds() { func testOverridingSecondsComponent_shouldHideSeconds() {
let dummyDefaults = UserDefaults.standard let dummyDefaults = UserDefaults.standard
dummyDefaults.set(NSNumber(value: 0), forKey: CLShowSecondsInMenubar) dummyDefaults.set(NSNumber(value: 4), forKey: CLSelectedTimeZoneFormatKey) // 4 is 12 hour with seconds
dummyDefaults.set(NSNumber(value: 1), forKey: CL24hourFormatSelectedKey)
let timezoneObjects = [TimezoneData(with: mumbai), let timezoneObjects = [TimezoneData(with: mumbai),
TimezoneData(with: auckland), TimezoneData(with: auckland),
@ -84,37 +83,11 @@ class ClockerUnitTests: XCTestCase {
let currentTime = operationsObject.time(with: 0) let currentTime = operationsObject.time(with: 0)
XCTAssert(currentTime.count == 8) // 8 includes 2 colons XCTAssert(currentTime.count == 8) // 8 includes 2 colons
$0.setShouldOverrideSecondsFormat(1) $0.setShouldOverrideGlobalTimeFormat(1)
let newTime = operationsObject.time(with: 0)
XCTAssert(newTime.count == 5) // 5 includes colon
}
// Reset
dummyDefaults.set(NSNumber(value: 1), forKey: CLShowSecondsInMenubar)
}
func testOverridingSecondsComponentFor12HourFormat_shouldHideSeconds() {
let dummyDefaults = UserDefaults.standard
dummyDefaults.set(NSNumber(value: 0), forKey: CLShowSecondsInMenubar)
dummyDefaults.set(NSNumber(value: 0), forKey: CL24hourFormatSelectedKey)
let timezoneObjects = [TimezoneData(with: mumbai),
TimezoneData(with: auckland),
TimezoneData(with: california)]
timezoneObjects.forEach {
let operationsObject = TimezoneDataOperations(with: $0)
let currentTime = operationsObject.time(with: 0)
XCTAssert(currentTime.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).count >= 10) // 8 includes 2 colons
$0.setShouldOverrideSecondsFormat(1)
let newTime = operationsObject.time(with: 0) let newTime = operationsObject.time(with: 0)
XCTAssert(newTime.count == 7) // 5 includes colon
XCTAssert(newTime.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).count >= 7) // 5 includes colon
} }
// Reset
dummyDefaults.set(NSNumber(value: 1), forKey: CLShowSecondsInMenubar)
dummyDefaults.set(NSNumber(value: 1), forKey: CL24hourFormatSelectedKey)
} }
func testAddingATimezoneToDefaults() { func testAddingATimezoneToDefaults() {
@ -155,11 +128,11 @@ class ClockerUnitTests: XCTestCase {
// The below test might fail outside California or if DST is active! // The below test might fail outside California or if DST is active!
// CI is calibrated to be on LA timezone! // CI is calibrated to be on LA timezone!
func testTimeDifference() { func testTimeDifference() {
XCTAssertTrue(operations.timeDifference() == ", 13 hours 30 mins ahead", "Difference was unexpectedly: \(operations.timeDifference())") XCTAssertTrue(operations.timeDifference() == ", 11 hours 30 mins ahead", "Difference was unexpectedly: \(operations.timeDifference())")
XCTAssertTrue(californiaOperations.timeDifference() == "", "Difference was unexpectedly: \(californiaOperations.timeDifference())") XCTAssertTrue(californiaOperations.timeDifference() == ", 2 hours behind", "Difference was unexpectedly: \(californiaOperations.timeDifference())")
XCTAssertTrue(floridaOperations.timeDifference() == ", 3 hours ahead", "Difference was unexpectedly: \(floridaOperations.timeDifference())") XCTAssertTrue(floridaOperations.timeDifference() == ", an hour ahead", "Difference was unexpectedly: \(floridaOperations.timeDifference())")
XCTAssertTrue(aucklandOperations.timeDifference() == ", 21 hours ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())") XCTAssertTrue(aucklandOperations.timeDifference() == ", 19 hours ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())")
XCTAssertTrue(omahaOperations.timeDifference() == ", 2 hours ahead", "Difference was unexpectedly: \(omahaOperations.timeDifference())") XCTAssertTrue(omahaOperations.timeDifference() == "", "Difference was unexpectedly: \(omahaOperations.timeDifference())")
} }
func testSunriseSunset() { func testSunriseSunset() {
@ -188,34 +161,72 @@ class ClockerUnitTests: XCTestCase {
func testTimezoneFormat() { func testTimezoneFormat() {
let dataObject = TimezoneData(with: mumbai) let dataObject = TimezoneData(with: mumbai)
UserDefaults.standard.set(NSNumber(value: 0), forKey: CLShowSecondsInMenubar) // Set to show seconds UserDefaults.standard.set(NSNumber(value: 0), forKey: CLSelectedTimeZoneFormatKey) // Set to 12 hour format
UserDefaults.standard.set(NSNumber(value: 0), forKey: CL24hourFormatSelectedKey) // Set to 12 hour format
dataObject.setShouldOverrideGlobalTimeFormat(0) dataObject.setShouldOverrideGlobalTimeFormat(0) // Respect Global Preference
XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a") XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a")
dataObject.setShouldOverrideGlobalTimeFormat(1) dataObject.setShouldOverrideGlobalTimeFormat(1) // 12-Hour Format
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss") XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a")
dataObject.setShouldOverrideGlobalTimeFormat(2) // 24-Hour format
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm")
dataObject.setShouldOverrideGlobalTimeFormat(2) // Skip 3 since it's a placeholder
dataObject.setShouldOverrideGlobalTimeFormat(4) // 12-Hour with seconds
XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a") XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a")
UserDefaults.standard.set(NSNumber(value: 1), forKey: CL24hourFormatSelectedKey) // Set to 24-Hour Format dataObject.setShouldOverrideGlobalTimeFormat(5) // 24-Hour format with seconds
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss") XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss")
UserDefaults.standard.set(NSNumber(value: 1), forKey: CLShowSecondsInMenubar) // Skip 6 since it's a placeholder
dataObject.setShouldOverrideGlobalTimeFormat(7) // 12-hour with preceding zero and no seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm a")
dataObject.setShouldOverrideGlobalTimeFormat(8) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss a")
// Skip 9 since it's a placeholder
dataObject.setShouldOverrideGlobalTimeFormat(10) // 12-hour without am/pm and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm")
dataObject.setShouldOverrideGlobalTimeFormat(11) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss")
}
func testTimezoneFormatWithDefaultSetAs24HourFormat() {
let dataObject = TimezoneData(with: california)
UserDefaults.standard.set(NSNumber(value: 1), forKey: CLSelectedTimeZoneFormatKey) // Set to 24-Hour Format
dataObject.setShouldOverrideGlobalTimeFormat(0) dataObject.setShouldOverrideGlobalTimeFormat(0)
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm")
dataObject.setShouldOverrideGlobalTimeFormat(1) // 12-Hour Format
XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a") XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a")
dataObject.setShouldOverrideGlobalTimeFormat(1) dataObject.setShouldOverrideGlobalTimeFormat(2) // 24-Hour format
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm") XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm")
dataObject.setShouldOverrideGlobalTimeFormat(2) // Skip 3 since it's a placeholder
XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm") dataObject.setShouldOverrideGlobalTimeFormat(4) // 12-Hour with seconds
XCTAssertTrue(dataObject.timezoneFormat() == "h:mm:ss a")
UserDefaults.standard.set(NSNumber(value: 0), forKey: CL24hourFormatSelectedKey) dataObject.setShouldOverrideGlobalTimeFormat(5) // 24-Hour format with seconds
XCTAssertTrue(dataObject.timezoneFormat() == "h:mm a") XCTAssertTrue(dataObject.timezoneFormat() == "HH:mm:ss")
// Skip 6 since it's a placeholder
dataObject.setShouldOverrideGlobalTimeFormat(7) // 12-hour with preceding zero and no seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm a")
dataObject.setShouldOverrideGlobalTimeFormat(8) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss a")
// Skip 9 since it's a placeholder
dataObject.setShouldOverrideGlobalTimeFormat(10) // 12-hour without am/pm and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm")
dataObject.setShouldOverrideGlobalTimeFormat(11) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat() == "hh:mm:ss")
} }
func testFormattedLabel() { func testFormattedLabel() {

2
Clocker/Overall App/AppDefaults.swift

@ -99,7 +99,7 @@ class AppDefaults {
private class func defaultsDictionary() -> [String: Any] { private class func defaultsDictionary() -> [String: Any] {
return [CLThemeKey: 0, return [CLThemeKey: 0,
CLDisplayFutureSliderKey: 0, CLDisplayFutureSliderKey: 0,
CL24hourFormatSelectedKey: 0, // 12-hour format CLSelectedTimeZoneFormatKey: 0, // 12-hour format
CLRelativeDateKey: 0, CLRelativeDateKey: 0,
CLShowDayInMenu: 0, CLShowDayInMenu: 0,
CLShowDateInMenu: 1, CLShowDateInMenu: 1,

4
Clocker/Overall App/DataStore.swift

@ -107,7 +107,7 @@ class DataStore: NSObject {
} }
func timezoneFormat() -> NSNumber { func timezoneFormat() -> NSNumber {
return userDefaults.object(forKey: CL24hourFormatSelectedKey) as? NSNumber ?? NSNumber(integerLiteral: 0) return userDefaults.object(forKey: CLSelectedTimeZoneFormatKey) as? NSNumber ?? NSNumber(integerLiteral: 0)
} }
func shouldDisplay(_ type: ViewType) -> Bool { func shouldDisplay(_ type: ViewType) -> Bool {
@ -120,7 +120,7 @@ class DataStore: NSObject {
} }
return value == "YES" return value == "YES"
case .twelveHour: case .twelveHour:
return shouldDisplayHelper(CL24hourFormatSelectedKey) return shouldDisplayHelper(CLSelectedTimeZoneFormatKey)
case .showAllDayEventsInMenubar: case .showAllDayEventsInMenubar:
return shouldDisplayHelper(CLShowAllDayEventsInUpcomingView) return shouldDisplayHelper(CLShowAllDayEventsInUpcomingView)
case .sunrise: case .sunrise:

2
Clocker/Overall App/Strings.swift

@ -6,7 +6,7 @@ let CLEmptyString = ""
let CLDefaultPreferenceKey = "defaultPreferences" let CLDefaultPreferenceKey = "defaultPreferences"
let CLTimezoneName = "formattedAddress" let CLTimezoneName = "formattedAddress"
let CLCustomLabel = "customLabel" let CLCustomLabel = "customLabel"
let CL24hourFormatSelectedKey = "is24HourFormatSelected" let CLSelectedTimeZoneFormatKey = "is24HourFormatSelected"
let CLDragSessionKey = "public.text" let CLDragSessionKey = "public.text"
let CLTimezoneID = "timezoneID" let CLTimezoneID = "timezoneID"
let CLPlaceIdentifier = "place_id" let CLPlaceIdentifier = "place_id"

2
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -175,7 +175,7 @@ class AppearanceViewController: ParentViewController {
@IBAction func timeFormatSelectionChanged(_ sender: NSPopUpButton) { @IBAction func timeFormatSelectionChanged(_ sender: NSPopUpButton) {
let selection = NSNumber(value: sender.indexOfSelectedItem) let selection = NSNumber(value: sender.indexOfSelectedItem)
UserDefaults.standard.set(selection, forKey: CL24hourFormatSelectedKey) UserDefaults.standard.set(selection, forKey: CLSelectedTimeZoneFormatKey)
Logger.log(object: ["Time Format": sender.indexOfSelectedItem == 0 ? "12 Hour Format" : "24 Hour Format"], for: "Time Format Selected") Logger.log(object: ["Time Format": sender.indexOfSelectedItem == 0 ? "12 Hour Format" : "24 Hour Format"], for: "Time Format Selected")

Loading…
Cancel
Save