|
|
@ -14,51 +14,59 @@ class StandardMenubarHandlerTests: XCTestCase { |
|
|
|
"latitude": "19.0759837", |
|
|
|
"latitude": "19.0759837", |
|
|
|
"longitude": "72.8776559"] |
|
|
|
"longitude": "72.8776559"] |
|
|
|
|
|
|
|
|
|
|
|
func testValidStandardMenubarHandler_returnMenubarTitle() { |
|
|
|
private func makeMockStore(with menubarMode: Int = 1) -> DataStore { |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
DataStore.shared().setTimezones(nil) |
|
|
|
guard let defaults = UserDefaults(suiteName: "com.abhishek.Clocker.StandardMenubarHandlerTests") else { |
|
|
|
|
|
|
|
XCTFail("User defaults couldn't be initialized") |
|
|
|
|
|
|
|
return DataStore.shared() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
defaults.set(menubarMode, forKey: CLMenubarCompactMode) |
|
|
|
|
|
|
|
defaults.set(0, forKey: CLShowMeetingInMenubar) |
|
|
|
|
|
|
|
XCTAssertNotEqual(defaults, UserDefaults.standard) |
|
|
|
|
|
|
|
return DataStore(with: defaults) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func saveObject(object: TimezoneData, |
|
|
|
|
|
|
|
in store: DataStore, |
|
|
|
|
|
|
|
at index: Int = -1) { |
|
|
|
|
|
|
|
var defaults = store.timezones() |
|
|
|
|
|
|
|
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object as Any) |
|
|
|
|
|
|
|
index == -1 ? defaults.append(encodedObject) : defaults.insert(encodedObject, at: index) |
|
|
|
|
|
|
|
store.setTimezones(defaults) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testValidStandardMenubarHandler_returnMenubarTitle() { |
|
|
|
|
|
|
|
let store = makeMockStore() |
|
|
|
|
|
|
|
store.setTimezones(nil) |
|
|
|
|
|
|
|
|
|
|
|
// Save a menubar selected timezone |
|
|
|
// Save a menubar selected timezone |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
dataObject.isFavourite = 1 |
|
|
|
dataObject.isFavourite = 1 |
|
|
|
let operationsObject = TimezoneDataOperations(with: dataObject) |
|
|
|
saveObject(object: dataObject, in: store) |
|
|
|
operationsObject.saveObject() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarTimezones = DataStore.shared().menubarTimezones() |
|
|
|
|
|
|
|
XCTAssertTrue(menubarTimezones?.count == 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set standard menubar in Prefs |
|
|
|
let menubarTimezones = store.menubarTimezones() |
|
|
|
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode) |
|
|
|
XCTAssertTrue(menubarTimezones?.count == 1, "Count is \(String(describing: menubarTimezones?.count))") |
|
|
|
|
|
|
|
|
|
|
|
let menubarHandler = MenubarTitleProvider() |
|
|
|
|
|
|
|
let menubarString = menubarHandler.titleForMenubar() ?? "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test menubar string is present |
|
|
|
|
|
|
|
XCTAssertTrue(menubarString.count > 0) |
|
|
|
|
|
|
|
XCTAssertTrue(menubarString.contains("Ghar")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set default back to compact menubar |
|
|
|
|
|
|
|
UserDefaults.standard.set(0, forKey: CLMenubarCompactMode) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testUnfavouritedTimezone_returnEmptyMenubarTimezoneCount() { |
|
|
|
func testUnfavouritedTimezone_returnEmptyMenubarTimezoneCount() { |
|
|
|
|
|
|
|
let store = makeMockStore() |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
DataStore.shared().setTimezones(nil) |
|
|
|
store.setTimezones(nil) |
|
|
|
|
|
|
|
|
|
|
|
// Save a menubar selected timezone |
|
|
|
// Save a menubar selected timezone |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
dataObject.isFavourite = 0 |
|
|
|
dataObject.isFavourite = 0 |
|
|
|
let operationsObject = TimezoneDataOperations(with: dataObject) |
|
|
|
saveObject(object: dataObject, in: store) |
|
|
|
operationsObject.saveObject() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarTimezones = DataStore.shared().menubarTimezones() |
|
|
|
let menubarTimezones = store.menubarTimezones() |
|
|
|
XCTAssertTrue(menubarTimezones?.count == 0) |
|
|
|
XCTAssertTrue(menubarTimezones?.count == 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testUnfavouritedTimezone_returnNilMenubarString() { |
|
|
|
func testUnfavouritedTimezone_returnNilMenubarString() { |
|
|
|
|
|
|
|
let store = makeMockStore() |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
// Wipe all timezones from UserDefaults |
|
|
|
DataStore.shared().setTimezones(nil) |
|
|
|
store.setTimezones(nil) |
|
|
|
let menubarHandler = MenubarTitleProvider() |
|
|
|
let menubarHandler = MenubarTitleProvider(with: store) |
|
|
|
let emptyMenubarString = menubarHandler.titleForMenubar() |
|
|
|
let emptyMenubarString = menubarHandler.titleForMenubar() |
|
|
|
// Returns early because DataStore.menubarTimezones is nil |
|
|
|
// Returns early because DataStore.menubarTimezones is nil |
|
|
|
XCTAssertNil(emptyMenubarString) |
|
|
|
XCTAssertNil(emptyMenubarString) |
|
|
@ -66,12 +74,42 @@ class StandardMenubarHandlerTests: XCTestCase { |
|
|
|
// Save a menubar selected timezone |
|
|
|
// Save a menubar selected timezone |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
dataObject.isFavourite = 0 |
|
|
|
dataObject.isFavourite = 0 |
|
|
|
let operationsObject = TimezoneDataOperations(with: dataObject) |
|
|
|
saveObject(object: dataObject, in: store) |
|
|
|
operationsObject.saveObject() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarString = menubarHandler.titleForMenubar() ?? "" |
|
|
|
let menubarString = menubarHandler.titleForMenubar() ?? "" |
|
|
|
|
|
|
|
|
|
|
|
// Test menubar string is absent |
|
|
|
// Test menubar string is absent |
|
|
|
XCTAssertTrue(menubarString.count == 0) |
|
|
|
XCTAssertTrue(menubarString.count == 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testWithEmptyMenubarTimezones() { |
|
|
|
|
|
|
|
let store = makeMockStore() |
|
|
|
|
|
|
|
store.setTimezones(nil) |
|
|
|
|
|
|
|
let menubarHandler = MenubarTitleProvider(with: store) |
|
|
|
|
|
|
|
XCTAssertNil(menubarHandler.titleForMenubar()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testWithStandardMenubarMode() { |
|
|
|
|
|
|
|
// Set mode to standard mode |
|
|
|
|
|
|
|
let store = makeMockStore(with: 0) |
|
|
|
|
|
|
|
// Save a menubar selected timezone |
|
|
|
|
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
|
|
|
|
dataObject.isFavourite = 1 |
|
|
|
|
|
|
|
saveObject(object: dataObject, in: store) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarHandler = MenubarTitleProvider(with: store) |
|
|
|
|
|
|
|
XCTAssertNil(menubarHandler.titleForMenubar()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func testProviderPassingAllConditions() { |
|
|
|
|
|
|
|
// Set mode to standard mode |
|
|
|
|
|
|
|
let store = makeMockStore() |
|
|
|
|
|
|
|
// Save a menubar selected timezone |
|
|
|
|
|
|
|
let dataObject = TimezoneData(with: mumbai) |
|
|
|
|
|
|
|
dataObject.isFavourite = 1 |
|
|
|
|
|
|
|
saveObject(object: dataObject, in: store) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let menubarHandler = MenubarTitleProvider(with: store) |
|
|
|
|
|
|
|
XCTAssertNotNil(menubarHandler.titleForMenubar()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|