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.

78 lines
2.9 KiB

// Copyright © 2015 Abhishek Banthia
import CoreModelKit
3 years ago
import XCTest
@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"]
3 years ago
func testValidStandardMenubarHandler_returnMenubarTitle() {
// Wipe all timezones from UserDefaults
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
3 years ago
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 1
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
3 years ago
let menubarTimezones = DataStore.shared().menubarTimezones()
XCTAssertTrue(menubarTimezones?.count == 1)
3 years ago
// Set standard menubar in Prefs
UserDefaults.standard.set(1, forKey: CLMenubarCompactMode)
3 years ago
let menubarHandler = MenubarHandler()
let menubarString = menubarHandler.titleForMenubar() ?? ""
3 years ago
// Test menubar string is present
XCTAssertTrue(menubarString.count > 0)
XCTAssertTrue(menubarString.contains("Ghar"))
3 years ago
// Set default back to compact menubar
UserDefaults.standard.set(0, forKey: CLMenubarCompactMode)
}
3 years ago
func testUnfavouritedTimezone_returnEmptyMenubarTimezoneCount() {
// Wipe all timezones from UserDefaults
UserDefaults.standard.setValue(nil, forKey: CLDefaultPreferenceKey)
3 years ago
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 0
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
3 years ago
let menubarTimezones = DataStore.shared().menubarTimezones()
XCTAssertTrue(menubarTimezones?.count == 0)
}
3 years ago
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)
3 years ago
// Save a menubar selected timezone
let dataObject = TimezoneData(with: mumbai)
dataObject.isFavourite = 0
let operationsObject = TimezoneDataOperations(with: dataObject)
operationsObject.saveObject()
3 years ago
let menubarString = menubarHandler.titleForMenubar() ?? ""
3 years ago
// Test menubar string is absent
XCTAssertTrue(menubarString.count == 0)
}
}