You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
80 lines
3.0 KiB
4 years ago
|
// Copyright © 2015 Abhishek Banthia
|
||
|
|
||
|
import XCTest
|
||
|
import CoreModelKit
|
||
|
|
||
|
@testable import Clocker
|
||
|
|
||
|
class StandardMenubarHandlerTests: XCTestCase {
|
||
|
|
||
|
private let mumbai = ["customLabel": "Ghar",
|
||
|
"formattedAddress": "Mumbai",
|
||
|
"place_id": "ChIJwe1EZjDG5zsRaYxkjY_tpF0",
|
||
|
"timezoneID": "Asia/Calcutta",
|
||
|
"nextUpdate": "",
|
||
|
"latitude": "19.0759837",
|
||
|
"longitude": "72.8776559"]
|
||
|
|
||
|
func testValidStandardMenubarHandler_returnMenubarTitle() {
|
||
|
// Wipe all timezones from UserDefaults
|
||
|
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
|
||
|
|
||
|
// Save a menubar selected timezone
|
||
|
let dataObject = TimezoneData(with: mumbai)
|
||
|
dataObject.isFavourite = 1
|
||
|
let operationsObject = TimezoneDataOperations(with: dataObject)
|
||
|
operationsObject.saveObject()
|
||
|
|
||
|
let menubarTimezones = DataStore.shared().menubarTimezones()
|
||
|
XCTAssertTrue(menubarTimezones?.count == 1)
|
||
|
|
||
|
// Set standard menubar in Prefs
|
||
|
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode)
|
||
|
|
||
|
let menubarHandler = MenubarHandler()
|
||
|
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() {
|
||
|
// Wipe all timezones from UserDefaults
|
||
|
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
|
||
|
|
||
|
// Save a menubar selected timezone
|
||
|
let dataObject = TimezoneData(with: mumbai)
|
||
|
dataObject.isFavourite = 0
|
||
|
let operationsObject = TimezoneDataOperations(with: dataObject)
|
||
|
operationsObject.saveObject()
|
||
|
|
||
|
let menubarTimezones = DataStore.shared().menubarTimezones()
|
||
|
XCTAssertTrue(menubarTimezones?.count == 0)
|
||
|
}
|
||
|
|
||
|
func testUnfavouritedTimezone_returnNilMenubarString() {
|
||
|
// Wipe all timezones from UserDefaults
|
||
|
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
|
||
|
let menubarHandler = MenubarHandler()
|
||
|
let emptyMenubarString = menubarHandler.titleForMenubar()
|
||
|
// Returns early because DataStore.menubarTimezones is nil
|
||
|
XCTAssertNil(emptyMenubarString)
|
||
|
|
||
|
// Save a menubar selected timezone
|
||
|
let dataObject = TimezoneData(with: mumbai)
|
||
|
dataObject.isFavourite = 0
|
||
|
let operationsObject = TimezoneDataOperations(with: dataObject)
|
||
|
operationsObject.saveObject()
|
||
|
|
||
|
let menubarString = menubarHandler.titleForMenubar() ?? ""
|
||
|
|
||
|
// Test menubar string is absent
|
||
|
XCTAssertTrue(menubarString.count == 0)
|
||
|
}
|
||
|
|
||
|
}
|