|
|
|
@ -107,6 +107,17 @@ class ClockerUnitTests: XCTestCase {
|
|
|
|
|
XCTAssert(newDefaults != nil) |
|
|
|
|
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() { |
|
|
|
|