Browse Source

More tests.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
0ac3ea009f
  1. 57
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  2. 19
      Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

57
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -108,6 +108,17 @@ class ClockerUnitTests: XCTestCase {
XCTAssert(newDefaults?.count == oldCount + 1)
}
func testDecoding() {
let timezone = TimezoneData.customObject(from: nil)
XCTAssertNotNil(timezone)
}
func testDescription() {
let timezoneData = TimezoneData(with: california)
XCTAssertFalse(timezoneData.description.isEmpty)
XCTAssertFalse(timezoneData.debugDescription.isEmpty)
}
func testDeletingATimezone() {
let defaults = UserDefaults.standard
@ -243,17 +254,61 @@ class ClockerUnitTests: XCTestCase {
dataObject.setShouldOverrideGlobalTimeFormat(11) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "hh:mm:ss")
dataObject.setShouldOverrideGlobalTimeFormat(12) // 12-hour with preceding zero and seconds
XCTAssertTrue(dataObject.timezoneFormat(DataStore.shared().timezoneFormat()) == "epoch")
}
func testSecondsDisplayForOverridenTimezone() {
let dataObject = TimezoneData(with: california)
UserDefaults.standard.set(NSNumber(value: 1), forKey: CLSelectedTimeZoneFormatKey) // Set to 24-Hour Format
// Test default behaviour
let timezoneWithSecondsKeys = [4,5,8,11]
for timezoneKey in timezoneWithSecondsKeys {
dataObject.setShouldOverrideGlobalTimeFormat(timezoneKey)
XCTAssertTrue(dataObject.shouldShowSeconds(DataStore.shared().timezoneFormat()))
}
let timezoneWithoutSecondsKeys = [1,2,7,10]
for timezoneKey in timezoneWithoutSecondsKeys {
dataObject.setShouldOverrideGlobalTimeFormat(timezoneKey)
XCTAssertFalse(dataObject.shouldShowSeconds(DataStore.shared().timezoneFormat()))
}
// Test wrong override timezone key
let wrongTimezoneKey = 88
dataObject.setShouldOverrideGlobalTimeFormat(wrongTimezoneKey)
XCTAssertFalse(dataObject.shouldShowSeconds(DataStore.shared().timezoneFormat()))
// Test wrong global preference key
dataObject.setShouldOverrideGlobalTimeFormat(0)
XCTAssertFalse(dataObject.shouldShowSeconds(88))
}
func testTimezone() {
let dataObject = TimezoneData(with: mumbai)
XCTAssertEqual(dataObject.timezone(), "Asia/Calcutta")
dataObject.isSystemTimezone = true
let autoupdatingTimezone = TimeZone.autoupdatingCurrent.identifier
XCTAssertEqual(dataObject.timezone(), autoupdatingTimezone)
}
func testFormattedLabel() {
let dataObject = TimezoneData(with: mumbai)
XCTAssertTrue(dataObject.formattedTimezoneLabel() == "Ghar", "Incorrect custom label returned by model.")
dataObject.customLabel = nil
dataObject.setLabel("")
XCTAssertTrue(dataObject.formattedTimezoneLabel() == "Mumbai", "Incorrect custom label returned by model.")
dataObject.formattedAddress = nil
XCTAssertTrue(dataObject.formattedTimezoneLabel() == "Asia", "Incorrect custom label returned by model.")
dataObject.setLabel("Jogeshwari")
XCTAssertTrue(dataObject.formattedTimezoneLabel() == "Jogeshwari", "Incorrect custom label returned by model.")
}
func testEquality() {

19
Clocker/CoreModelKit/Sources/CoreModelKit/TimezoneData.swift

@ -210,7 +210,7 @@ public class TimezoneData: NSObject, NSCoding {
} else if shouldOverride == 12 {
overrideFormat = .epochTime
} else {
assertionFailure("Chosen a wrong timezone format")
print("Chosen a wrong timezone format")
}
}
@ -225,16 +225,6 @@ public class TimezoneData: NSObject, NSCoding {
return timezone
}
if let name = formattedAddress, let placeIdentifier = placeID, let timezoneIdentifier = timezoneID {
let errorDictionary = [
"Formatted Address": name,
"Place Identifier": placeIdentifier,
"TimezoneID": timezoneIdentifier,
]
Logger.log(object: errorDictionary, for: "Error fetching timezone() in TimezoneData")
}
return TimeZone.autoupdatingCurrent.identifier
}
@ -290,13 +280,6 @@ public class TimezoneData: NSObject, NSCoding {
return lhs.placeID == rhs.placeID
}
public override func isEqual(to object: Any?) -> Bool {
if let other = object as? TimezoneData {
return placeID == other.placeID
}
return false
}
public override func isEqual(_ object: Any?) -> Bool {
guard let compared = object as? TimezoneData else {
return false

Loading…
Cancel
Save