Browse Source

Add timezones when offline + tests.

pull/92/head
Abhishek 6 years ago
parent
commit
10935808d6
  1. 19
      Clocker/ClockerUITests/NetworkDisconnectionTests.swift
  2. 39
      Clocker/Preferences/General/PreferencesViewController.swift

19
Clocker/ClockerUITests/NetworkDisconnectionTests.swift

@ -20,6 +20,25 @@ class NetworkDisconnectionTests: XCTestCase {
} }
} }
// User should be still be able to add a timezone
func testAddingATimezone() {
app.launchArguments.append("mockNetworkDown")
precondition()
app.buttons["FloatingPreferences"].click()
if app.sheets.count == 0 {
app.windows["Clocker"].checkBoxes["AddTimezone"].click()
}
XCTAssertFalse(app.sheets.staticTexts["ErrorPlaceholder"].exists)
let searchField = app.searchFields["AvailableSearchField"]
searchField.reset(text: "Kolkata")
addAPlace(place: "Kolkata", to: app)
app.sheets.buttons["Close"].click()
}
func testAddingACity() { func testAddingACity() {
app.launchArguments.append("mockNetworkDown") app.launchArguments.append("mockNetworkDown")
precondition() precondition()

39
Clocker/Preferences/General/PreferencesViewController.swift

@ -42,6 +42,7 @@ class PreferencesViewController: ParentViewController {
return DataStore.shared().timezones() return DataStore.shared().timezones()
} }
private var timezoneMetadataDictionary: [String: [String]] = [:]
private lazy var startupManager = StartupManager() private lazy var startupManager = StartupManager()
private var filteredArray: [Any] = [] private var filteredArray: [Any] = []
private var timezoneArray: [TimezoneMetadata] = [] private var timezoneArray: [TimezoneMetadata] = []
@ -548,10 +549,11 @@ extension PreferencesViewController {
self.placeholderLabel.isHidden = false self.placeholderLabel.isHidden = false
/*
if NetworkManager.isConnected() == false { if NetworkManager.isConnected() == false {
self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
return return
} }*/
self.isActivityInProgress = true self.isActivityInProgress = true
@ -564,9 +566,14 @@ extension PreferencesViewController {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
if let errorPresent = error { if let errorPresent = error {
self.findLocalSearchResultsForTimezones()
if self.timezoneFilteredArray.isEmpty {
self.presentError(errorPresent.localizedDescription) self.presentError(errorPresent.localizedDescription)
return return
} }
self.prepareUIForPresentingResults()
return
}
guard let data = response else { guard let data = response else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
@ -698,10 +705,10 @@ extension PreferencesViewController {
placeholderLabel.isHidden = false placeholderLabel.isHidden = false
} }
if NetworkManager.isConnected() == false || ProcessInfo.processInfo.arguments.contains("mockTimezoneDown") { // if NetworkManager.isConnected() == false || ProcessInfo.processInfo.arguments.contains("mockTimezoneDown") {
resetStateAndShowDisconnectedMessage() // resetStateAndShowDisconnectedMessage()
return // return
} // }
searchField.placeholderString = "Fetching data might take some time!" searchField.placeholderString = "Fetching data might take some time!"
placeholderLabel.placeholderString = "Retrieving timezone data" placeholderLabel.placeholderString = "Retrieving timezone data"
@ -813,6 +820,12 @@ extension PreferencesViewController {
searchField.placeholderString = "Enter a city, state or country name" searchField.placeholderString = "Enter a city, state or country name"
availableTimezoneTableView.isHidden = false availableTimezoneTableView.isHidden = false
isActivityInProgress = false isActivityInProgress = false
timezoneMetadataDictionary =
["IST": ["india", "indian", "kolkata", "calcutta", "mumbai", "delhi", "hyderabad", "noida"],
"PST": ["los", "los angeles", "california", "san francisco", "bay area", "pacific standard time"],
"UTC": ["utc", "universal"],
"EST": ["florida", "new york"]]
} }
private func setupTimezoneDatasource() { private func setupTimezoneDatasource() {
@ -826,20 +839,8 @@ extension PreferencesViewController {
for (abbreviation, timezone) in TimeZone.abbreviationDictionary { for (abbreviation, timezone) in TimeZone.abbreviationDictionary {
var tags: Set<String> = [abbreviation.lowercased(), timezone.lowercased()] var tags: Set<String> = [abbreviation.lowercased(), timezone.lowercased()]
var extraTags: [String] = [] var extraTags: [String] = []
if abbreviation == "IST" { if let tagsPresent = timezoneMetadataDictionary[abbreviation] {
extraTags = ["india", "indian", "kolkata", "calcutta", "mumbai", "delhi", "hyderabad", "noida"] extraTags = tagsPresent
}
if abbreviation == "PST" {
extraTags = ["los", "los angeles", "california", "san francisco", "bay area", "pacific standard time"]
}
if abbreviation == "UTC" {
extraTags = ["utc", "universal"]
}
if abbreviation == "EST" {
extraTags = ["florida", "new york"]
} }
extraTags.forEach { tag in extraTags.forEach { tag in

Loading…
Cancel
Save