From 10935808d6f46f32f4764b8a7f6122491eca7822 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sun, 21 Jul 2019 17:27:52 -0700 Subject: [PATCH] Add timezones when offline + tests. --- .../NetworkDisconnectionTests.swift | 19 ++++++++ Clocker/Panel/Data Layer/TimezoneData.swift | 4 +- .../General/PreferencesViewController.swift | 47 ++++++++++--------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Clocker/ClockerUITests/NetworkDisconnectionTests.swift b/Clocker/ClockerUITests/NetworkDisconnectionTests.swift index 8276c62..78340f0 100644 --- a/Clocker/ClockerUITests/NetworkDisconnectionTests.swift +++ b/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() { app.launchArguments.append("mockNetworkDown") precondition() diff --git a/Clocker/Panel/Data Layer/TimezoneData.swift b/Clocker/Panel/Data Layer/TimezoneData.swift index 3adcf5f..1a0338a 100644 --- a/Clocker/Panel/Data Layer/TimezoneData.swift +++ b/Clocker/Panel/Data Layer/TimezoneData.swift @@ -252,11 +252,11 @@ class TimezoneData: NSObject, NSCoding { newModels.append(newModel) } } - + if UserDefaults.standard.object(forKey: "shouldOverrideSecondsFormatBug") == nil { UserDefaults.standard.set("YES", forKey: "shouldOverrideSecondsFormatBug") } - + // Do the serialization let serializedModels = newModels.map { (place) -> Data in NSKeyedArchiver.archivedData(withRootObject: place) diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 4f2f5da..2713567 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -42,6 +42,7 @@ class PreferencesViewController: ParentViewController { return DataStore.shared().timezones() } + private var timezoneMetadataDictionary: [String: [String]] = [:] private lazy var startupManager = StartupManager() private var filteredArray: [Any] = [] private var timezoneArray: [TimezoneMetadata] = [] @@ -548,10 +549,11 @@ extension PreferencesViewController { self.placeholderLabel.isHidden = false - if NetworkManager.isConnected() == false { - self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError - return - } + /* + if NetworkManager.isConnected() == false { + self.placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError + return + }*/ self.isActivityInProgress = true @@ -564,7 +566,12 @@ extension PreferencesViewController { OperationQueue.main.addOperation { if let errorPresent = error { - self.presentError(errorPresent.localizedDescription) + self.findLocalSearchResultsForTimezones() + if self.timezoneFilteredArray.isEmpty { + self.presentError(errorPresent.localizedDescription) + return + } + self.prepareUIForPresentingResults() return } @@ -698,10 +705,10 @@ extension PreferencesViewController { placeholderLabel.isHidden = false } - if NetworkManager.isConnected() == false || ProcessInfo.processInfo.arguments.contains("mockTimezoneDown") { - resetStateAndShowDisconnectedMessage() - return - } +// if NetworkManager.isConnected() == false || ProcessInfo.processInfo.arguments.contains("mockTimezoneDown") { +// resetStateAndShowDisconnectedMessage() +// return +// } searchField.placeholderString = "Fetching data might take some time!" placeholderLabel.placeholderString = "Retrieving timezone data" @@ -813,6 +820,12 @@ extension PreferencesViewController { searchField.placeholderString = "Enter a city, state or country name" availableTimezoneTableView.isHidden = 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() { @@ -826,20 +839,8 @@ extension PreferencesViewController { for (abbreviation, timezone) in TimeZone.abbreviationDictionary { var tags: Set = [abbreviation.lowercased(), timezone.lowercased()] var extraTags: [String] = [] - if abbreviation == "IST" { - extraTags = ["india", "indian", "kolkata", "calcutta", "mumbai", "delhi", "hyderabad", "noida"] - } - - 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"] + if let tagsPresent = timezoneMetadataDictionary[abbreviation] { + extraTags = tagsPresent } extraTags.forEach { tag in